PHPExcel - cell formating - phpexcel

if I fill a cell with the value "0.07" and then define it as a percentage, excel turns this value into "7,00". Can someone tell me how to work correctly? thanks
$objPHPExcel->getActiveSheet()->setCellValue($col.$rowCount,'0.07');
$objPHPExcel->getActiveSheet()->getStyle($col.$rowCount)->getNumberFormat()->applyFromArray(array('code' => PHPExcel_Style_NumberFormat::FORMAT_PERCENTAGE_00));
if i change and set the value to "0,07" - excel means that the value is formatted as text.

ok, i found a simple solution:
$objPHPExcel->getActiveSheet()->setCellValue($col.$rowCount, 0.07/100);
$objPHPExcel->getActiveSheet()->getStyle($col.$rowCount)->getNumberFormat()->setFormatCode('0.00%');
i am happy if it helps others.

Related

Display cumulative value of each column in balloon text

I built a cumulative line graph using context.cumulativeCol() in the Value field and I am interested in displaying the cumulated value of the current column in the ballon text.
This is what I have, which only shows the value of the column:
I tried to change the default value [[Row]], [[Column]]: [[Value]] from the Ballon Text field and tried to use something like context.cumulativeCol() but I could not achieve my goal.
If it is possible, how am I supposed to do it?
I've just tried to put:
return "Cumulative: " + context.cumulativeCol();
to the balloon function and it worked fine in the latest version. Perhaps you are trying to return a number instead of a string from the balloon function?

PHPExcel format dates occuring this week

PHPExcel conditional formatting has some helpful conditions and operators...
I applied a condition like so:
$aCondition = new PHPExcel_Style_Conditional();
$aCondition->setConditionType(PHPExcel_Style_Conditional::CONDITION_EXPRESSION)
->setOperatorType(PHPExcel_Style_Conditional::OPERATOR_EQUAL)
->addCondition('AND(($B2<>$B3),$B2<>"")');
$aCondition->getStyle()->getBorders()->getBottom()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
$aCondition->getStyle()->getNumberFormat()->setFormatCode($dateFormat);
$conditionalStyles = $sheet->getStyle('B2')->getConditionalStyles();
array_push($conditionalStyles, $aCondition);
$sheet->getStyle('$'.$letter.'2:$'.$letter.'10000')->setConditionalStyles($conditionalStyles);
However, when I get to the excel document... it marks the cell yellow even though it should not be... but if I then go to the cell and press enter... the cell then loses its yellow... and then the conditional formatting works correctly...
I apply formatting for that cell's rows like so:
$sheet->getStyle('M2:M9999')
->getNumberFormat()
->setFormatCode("dd/mm/yyyy");
I found this little doozy:
PHPExcel_Shared_Date::PHPToExcel( strtotime( "03/25/2014" ) )
As soon as you apply this, the issue goes away.. This is because the formatcode is just a mask... the underlying data has to be of a special Excel date type.

Change number_format datatype

How do I convert to double the returned value of the php function, number_format();
Here's my code:
$objPHPExcel->getActiveSheet()->setCellValue($colmun_alpha[$col_count+1].$row,number_format($items[0][1],2));
I need number_format($items[0][1],2) for the purpose of displaying it nicely in Excel. But
I the sum function of excel doesn't work because $items[0][1] is formatted to string.
I need somehow to format it just like the number_format do but with a datatype of double / float.
Thanks for your help.
$items[0][1] = 12345.678;
$objPHPExcel->getActiveSheet()
->setCellValue($colmun_alpha[$col_count+1].$row, $items[0][1]);
$objPHPExcel->getActiveSheet()
->getStyle($colmun_alpha[$col_count+1].$row)
->getNumberFormat()
->setFormatCode('#,##0.00');
you can use typecasting to ensure that the variable has a float type.
number_format( (float) $items[0][1],2)
if this doesnt work then maybe something else is not working properly in your code

PHPExcel Accounting Formats

I'm working with PHPExcel and I'm trying to format a cell using Excel's built-in "Accounting" format. I'm aware of the Format Code:
PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_USD_SIMPLE
But this simply formats to two decimal places and adds a $ in front of the number. The result I'm looking for is the right aligned cell with the $ on the left. $0 values should be listed as "-" and negative values should be $ (1.11)
As far as I can tell there are no other currency formats in the documentation (though I may have missed it, this documentation is horrendous). Am I looking in the wrong place? Can this be achieved with regular cell formatting or is Excel doing something unique for Accounting?
I reverse engineered the format code from an existing spreadsheet using PHPExcel and got this:
_("$"* #,##0.00_);_("$"* \(#,##0.00\);_("$"* "-"??_);_(#_)
This is the code Excel places on the cell when you select the "Accounting" format... or click that "$" toolbar button in Excel 2007.
If you didn't need currency symbol :
->setFormatCode("_(* #,##0.00_);_(* \(#,##0.00\);_(* \"-\"??_);_(#_)");
$objPHPExcel->getActiveSheet()->getStyle('C1')->getNumberFormat()->setFormatCode("#,##0.00");
or use
$objPHPExcel->getActiveSheet()->getStyle('C1')->getNumberFormat()->setFormatCode("#.##0,00");
Set in getStyle CELL.
There are no other pre-defined formats beyond those listed in PHPExcel_Style_NumberFormat, but you should be able to set the format code to any string that you could use when setting an MS Excel custom format...
e.g.
[green]$#,##0.00;[red]$(-#,##0.00)
As regards cell alignment, set this to right yourself, or don't set it at all.

Finding First Row in a RDLC Table

I have a table in a RDLC report which is utilized as a subreport, and the first column of this table is a static string. Does anyone know how I can determine if a row is the first in the table. I tried using "=First("My String")" but it didn't work.
Looking at the link supplied by ThatBloke in his answer, I found the RowNumber command.
Which means that this worked:
=IIf(RowNumber(Nothing)=1,"myString", "")
Aggregate functions work with "Scope', referring to the paragraph scope in this MSDN article, might help...
http://msdn.microsoft.com/fr-fr/library/ms252112(VS.80).aspx"
From what I understand you may have to define a scope or try =First("MyString", Nothing).
=IIF((RowNumber(Nothing) Mod <>)=0)
<> Indicate No of Rows Which you want To Display

Resources