PHPSpreadsheet cannot set worksheet margin - excel

Hi I have a little problem with this plugin, this is the code that makes an error
Sheet::macro('setPageMargins', function (Sheet $sheet, float $top = 1, float $right = 0.75, float $bottom = 1, float $left = 0.75) {
$sheet->getDelegate()->getPageMargins()->setTop($top);
$sheet->getDelegate()->getPageMargins()->setRight($right);
$sheet->getDelegate()->getPageMargins()->setLeft($left);
$sheet->getDelegate()->getPageMargins()->setBottom($bottom);
});
Here is the error
Argument 1 passed to
PhpOffice\PhpSpreadsheet\Worksheet\Worksheet::setPageMargins() must be
an instance of PhpOffice\PhpSpreadsheet\Worksheet\PageMargins, float
given
and I just following this documentation https://phpspreadsheet.readthedocs.io/en/develop/topics/recipes/#page-margins with using maatwebsite\Excel, by the way i'm using Laravel 5.7.
The question is how to set the margin? because I think the documentation is wrong, please help

I believe you should be doing:
// Create a page margins object.
$pageMargins = new \PhpOffice\PhpSpreadsheet\Worksheet\PageMargins();
$pageMargins->setTop(1);
$pageMargins->setRight(0.75);
$pageMargins->setBottom(1);
$pageMargins->setLeft(0.75);
Sheet::macro('setPageMargins', function($sheet, $pageMargins));
According to the code, it says public function setPageMargins(PageMargins $pValue).
(https://github.com/PHPOffice/PhpSpreadsheet/blob/0e8fde9be6d3918ffe030bed0ba0297bfe330c4d/src/PhpSpreadsheet/Worksheet/Worksheet.php#L966)
Your ::macro calls the setPageMargins function, although this pattern confuses me (it appears to be some Maatwebsite\Excel thing).

Related

Visio Shape Text positioning below the shape using Text Transform

I have a building a set of stencil shapes and I need the text to display below the shape. I am using custom formulas to generate the text, and as such the volume of text changes from use case to use case.
What I have come across is using the Text Transform set of properties, and I have tried the following with success for a single line of text:
TxtWidth = TEXTWIDTH(TheText)
TxtPinX = Width * 0.5
TxtLocPinX = TxtWidth * 0.5
TxtHeight = Height * 0
TxtPinY = Height * -0.2
TxtLocPinY = TxtHieght * 0.5
TxtAngle = 0 deg
The problem arises when there is more than a single line of text to display -> the text appears 'half above (inside) and half below' the bottom the shape.
I would like to place all the text, regardless of how many lines there are, underneath the shape.
What I have tried is to set the TxtPinY = some formula different from above eg/ Height * -(TxtHeight). This seems to always result in an 'error in formula'.
I am sure that this is something simple that I am missing, but I cannot figure it out.
Can anybody point me in the right direction?
Cheers and thanks for taking a look at this,
The Frog
You could try the TEXTHEIGHT function to get around this. Specify a reasonable maximum text widht as a second parameter for it:
TxtHeight = TEXTHEIGHT(TheText,100)
TxtPinY = 0
TxtLocPinY = TxtHeight
You can use the code provided with the stencil available in this post:
http://visguy.com/vgforum/index.php?topic=7461.msg31490#msg31490

Revit API changes wall parameters: from metadata it showed the correct result, not reflected in UI however

Using revit-python-wrapper to create Wall then adjust the Wall height and Wall offset to the ground.
Here is the code
from rpw import db
from rpw import DB
start_point = XYZ(0, 0, 0)
end_point = XYZ(45, 0, 0)
# Wrapper Line
line = Line.new(start_point, end_point)
levels = db.Collector(of_class='Level')
level_0 = levels.get_first()
wall = DB.Wall.Create(doc, line.unwrap(), level_0.Id, False)
w = db.Wall(wall)
w.parameters['Unconnected Height'].value = 2675
w.parameters['Base Offset'].value = 45
Wall created successfully in the empty Revit project.
Using snoop revit DB, only one wall is found. The ID is : 318835
Checked the parameters belonging to this Wall - 318835. The parameter 'Unconnected Height' has correct double value: 2675.0 and the parameter "Base Offset" has correct double value: 45.0.
So far, everthing is perfect and per my expectation.
But, from the UI interface, the only Wall created is shown in wrong position. In 3D view, it's above the Level 1 which height is 4000.
And from the proporty tab of the selected Wall, the two parameters are also in the wrong values.
'Unconnected Height' has correct double value: 815340.0 and the parameter "Base Offset" has correct double value: 13716.0.
When I digged into deeper, I found actually the value I changed is shown in AsDouble. However, the value I changed in the UI is shown AsValueString. Both of them are pointing to the same property. However they are different, my understanding they should be the same value but in different data format.
Am I wrong?
I figured it out now.
Internally, Revit use feet rather than mm.
So, make sure convert the mm to feet then pass it to value.
w.parameters['Unconnected Height'].value = mm_to_feet(2675)
w.parameters['Base Offset'].value = mm_to_feet(45)

How do I set custom colours on a pyqt QColorDialog?

I am bringing up a QcolorDialog like so:-
colour = QtGui.QColorDialog.getColor()
What I want to know is how to set the colours of the custom color swatches before I bring up the dialog. I have searched a lot and found the method setCustomColor() but I just can't get it to work. It repeatedly tells me
TypeError: argument 2 of QColorDialog.setCustomColor() has an invalid type
I have tried all manner of variations of how to create a QColor, but it never seems happy with it.This is what I am currently trying:-
mycolor = QtGui.QColor(0,0,0,0)
colour = QtGui.QColorDialog.setCustomColor(0,mycolor)
But it still gives me the same 'invalid type' error...
Any ideas?
All you need to do is:
colour_dia = QtGui.QColorDialog()
mycolour = QtGui.QColor(0, 0, 0, 0).rgba()
#This needs a integer value for colour
colour_dia.setCustomColor(0, mycolour)
selected_colour = colour_dia.getColor()

SKIA - Inaccurate value returned by measureText()

I have a problem measuring text using skia measureText() function.
The value returned is inaccurate.
SkPaint *skPaint = new SkPaint();
SkTypeface* myFont = SkTypeface::CreateFromName("Impact", SkTypeface::kNormal);
skPaint->setTypeface(myFont);
skPaint->setAntiAlias(true);
skPaint->setTextAlign(SkPaint::kLeft_Align);
skPaint->setTextEncoding(SkPaint::kUTF16_TextEncoding);
skPaint->setTextSize(SkIntToScalar(120));
skPaint->setColor(0xff000001);
canvas->drawText(text, length, SkIntToScalar(x) , SkIntToScalar(y) , *skPaint);
SkScalar width = skPaint->measureText(text, length);
The width returned by measureText() is 451.
I checked the generated bitmap text via a photo editor app, the actual width is only 438.
Any thoughts on getting the accurate width of text in SKIA?
Thank you!
I believe what you are trying to match will come from "bounds"
SkRect bounds;
SkScalar textWidth = paint.measureText("some", 4, &bounds);
which is a minimum rectangle to fit a given text, whereas textWidth is slightly larger than that.
I faced this issue too. Dont know why exactly it happens, maybe because of kerning differences, but i came to this:
SizeF RenderTextAndroid::GetStringSizeF() {
UpdateFont();
const base::string16& text = GetLayoutText();
std::vector<SkScalar> widths(text.length());
paint_.getTextWidths(text.c_str(), GetStrByteLen(text), &widths[0], NULL);
return SizeF(std::accumulate(widths.begin(), widths.end(), 0),
font_metrics_.fBottom - font_metrics_.fTop);
}
Where UpdateFont just sets new parameters to SkPaint

Display Text on MFC Based Application

I'm a little new to using MFC and VC++ as such, but I'm doing this as part of a Course and i Have to stick to VC++.
http://www.cprogramming.com/tutorial/game_programming/same_game_part1.html
This is the tutorial I have been following to make a simple samegame. However when i try to display score, the score is getting displayed Underneath or outside my application window, even though I've displayed score before calling updateWindow(). I've tried various methods but I am kinda lost here.
Here is the code I'm using to Display the score:
void CSameGameView::updateScore()
{
CSameGameDoc* pDoc = GetDocument();
CRect rcClient, rcWindow;
GetClientRect(&rcClient);
GetParentFrame()->GetWindowRect(&rcWindow);
int nHeightDiff = rcWindow.Height() - rcClient.Height();
rcScore.top=rcWindow.top + pDoc->GetHeight() * pDoc->GetRows() + nHeightDiff;
rcScore.left=rcWindow.left + 50;
rcScore.right=rcWindow.left + pDoc->GetWidth() - 50;
rcScore.bottom=rcScore.top + 20;
CString str;
double points = Score::getScore();
str.Format(_T("Score: %0.2f"), points);
HDC hDC=CreateDC(TEXT("DISPLAY"),NULL,NULL,NULL);
COLORREF clr = pDoc->GetBoardSpace(-1, -1); //this return background colour
pDC->FillSolidRect(&rcScore, clr);
DrawText(hDC, (LPCTSTR) str, -1, (LPRECT) &rcScore, DT_CENTER);
}
Thank you for any help and I'm sorry if the question doesn't make sense or in ambiguous.
There are several problems with your code:
1. The hDC you are creating is going to have coordinates relative to the desktop window. To paint text in your window, use CClientDC like this: CClientDC dc(this); (see http://msdn.microsoft.com/en-US/library/s8kx4w44%28v=vs.80%29.aspx)
2. The code you have will leak a DC every time the function is called. The method in #1 will fix that.
3. Your paint code should be done in the CView::OnDraw. There you get a DC passed to you and you don't have to worry about creating one with CClientDC. Set the variables you want to draw (e.g. your points or score), store them as class members and draw them in CView::OnDraw.
Don't do the drawing in your updateScore method.
Make sense? Hang in there!

Resources