PhpSpreadsheet conditional formatting cell (fill) - php

I have set theese conditions:
$objConditionalRed->setConditionType(conditional::CONDITION_CELLIS);
$objConditionalRed->setOperatorType(conditional::OPERATOR_LESSTHAN);
$objConditionalRed->addCondition('50');
$objConditionalRed->getStyle()->getFill()->setFillType(fill::FILL_SOLID);
$objConditionalRed->getStyle()->getFill()->getStartColor()->setARGB('FFFF0000');
$objConditionalRed->getStyle()->getFont()->setBold(true);
Font formating works well (even if I change getFill to getFont and color font, it works), however, cell would not fill if condition is met, what might be wrong?

Looks like the problem was, that I needed to use getEndColor() instead of getStartColor(),
if someone knows, why this one should be used, will be pleased to hear.
T.Y.

Related

How to set conditional format to color each second row with phpspreadsheet

Does somebody know how set conditional format with phpspreadsheet that each second row is shadowed like in the picture below?
sorry, I had to delete all the data, but I think its clear what I've meant
As it looks like there is no "function" inside phpspreadsheet to color the background of each 2nd row(?). If somebody knows such an easy way I'm still interested. In the meantime see my own amateurish way:
As long as you have the variables $col and $rowNumber available somewhere inside your script you can loop thrue all lines and set a background color for all lines with an odd number. Even lines you could address with the "else part".
if ($rowNumber%2) {
$spreadsheet->getActiveSheet()->getStyle($col.$rowNumber)->getFill()->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)->getStartColor()->setARGB('e2efda'); //e2efda
};

How to check if a cell has a bottom border with Phpexcel

How to check if a cell has a bottom border using PHPexcel? I am working on a very funky template the sales force of my company have assembled.
The lines could go on and on inside the "Why?" block so that is why I need to check for that last bottom border to move on in my loop.
Example:
This will check the entire G column until it is empty
NumCells = Range("G" & Rows.Count).End(xlUp).Row +1
If Range("G" & NumCells).Borders(xlEdgeBottom).LineStyle = xlContinuous Then
*Continue with code
I ended up using something like this (didn't really find the bottom border a reliable solution). This will just simply grab the data inside of the following cell ranges (B25:B29):
$objPHPExcel->setActiveSheetIndex($sheetIndex)->rangeToArray('B25:B29');

Netbeans autocomplete not following style guide

I like to have a space after function names, arrays, that sort of thing, so a function declaration would look like:
function myfunction ($param)
{
$a = array ('a', 'b');
callfunction ($a);
}
And although I have set the style guide in Netbeans to correspond to this whenever it does autocomplete/suggestions it always misses out the space and gives me something like callfunction($a) even though when I go source->format (alt+shift+f) it then formats the code properly.
Any way to get autocomplete to add the space?
UPDATE:
Just to make things clear, I have set up Netbeans to correspond to my coding preferences, as indicated by the ability to use auto format. The problem is auto complete (or whatever the hint thing is called) does not respect these settings, leading to the missing space.
Go in Tools->Options.
In pane Editor -> choose pane Formatting.
In language choose PHP and in Category choose Spaces.
Check all in Before Keywords, Before Parenthesis, Before left braces, and you can choose other properties if you want.
Then when you will use auto-complete or Alt+Shift+F to reformat it will put the spaces correctly.
EDIT :
In the OP case it seems an other configuration prevents the auto-complete to works.
This is my config :
Do this:
Goto Options > Formatting
Scroll down to "Spaces Before Parenthesis"
Check the option called "Function Declaration"

how to print a cell inside a cell using fpdf

I'm making some pdf document from php code using fpdf library. In that document i have created two cell like this
$pdf->Cell(100,100,"Text inside first column",1,0,'L');
$pdf->Cell(35,35,'Text inside second column ',1,0,'C');
above code works well, out put have two cells, first one has size of 100x100 and second has 35x35 , and second cell was just right to the first cell.
but i need to print that second sell inside the first cell
is there any way in fpdf ?
can anyone help me?
I'm not sure what you want exactly achive, but maybe this AddOn could help you to do this:
http://www.interpid.eu/fpdf-table
Other way would be moving the pointer, something like this:
$pdf->Cell(100,100,"Text inside first column",1,0,'L');
$pdf->SetX($pdf->GetX() - 35);
$pdf->Cell(35,35,'Text inside second column ',1,0,'C');
In Nested cell X-axis and Y-axis, I have achieved like this
`$pdf->Cell(190,20,"",1,0,'L');
$pdf->SetX($pdf->GetX() - 189);
$pdf->Cell(100,10,'First ',2,0,'L');
$pdf->Cell(90,10,'March/2020 ',2,0,'R');
$pdf->SetY($pdf->GetY() +5);
$pdf->Cell(100,10,'MCB,UBl Omni, HBL Konnect, Alfalah , Mobi Cash ',2,0,'L');
$pdf->SetY($pdf->GetY() +5);`enter code here`
$pdf->Cell(139,10,'third text he`enter code here`re ',2,0,'L');
$pdf->Cell(50,10,'Lahore',2,0,'R');`

Is there a period in the string?

So i am using this wordpress function to get the users image
the_author_meta('author_image', the_author_ID()
and it will either return something.jpg or something.png or something.gif if it finds an image otherwise it will return an integer like 2330. How would i do a preg_match or some conditional to let me know if an image is present. I was thinking of doing a preg_match to see if there is a period in the name but if someone has a better idea that would be great..
Simpler:
if (is_numeric($author_image)){
// this is presumably not a file
}
If all you want to do is check the extension of the file to see if it ends with something (ex. '.jpg', '.png', etc.) you can use the solution presented here:
startsWith() and endsWith() functions in PHP
I do not have familiarity with the library that you are using, but there really should be a better way to detect if the file is actually an image (some sort of meta data). Maybe reading the documentation will help?
EDIT: I misread the part about the function returning integers if an image is not found. The is_numeric() solution is probably enough, but I'll leave my answer up to give you options (for example, if you want to distinguish between image types).

Categories