CSV,pdf, and html pre calculated formulas always 0?

Topics: Developer Forum, User Forum
May 23, 2008 at 6:02 PM
I have formulas and by default the doc says that it will pre-calculate the formula... only problem is it always returns a 0.

I tried adding: 
  $objWriter = new PHPExcel_Writer_PDF($objPHPExcel);
  $objWriter->setPreCalculateFormulas(true);
     $objWriter->save('php://output');

to see if maybe it was false by defualt,  but no luck I still get 0 ??  it works perfect in Excel2007 and Excel_5 just not the other 3...

Chris
Coordinator
May 26, 2008 at 7:22 AM
Does example 21pdf.php write formulas out?
Jun 3, 2008 at 6:38 PM
Hey,

I'm running into this same problem. I tested 21pdf.php and it output everything correctly. The only differences i could see in the example file were the createTextRun and getText attributes.

Any help would be awesome. Thanks in advance,
Thom
Coordinator
Jun 4, 2008 at 2:18 PM
Can you guys post a sample snippet here + info on PHP version and PHPExcel version?
Jun 4, 2008 at 3:13 PM
PHPExcel - 1.6.1
PHP - PHP Version 5.2.0-8

Alright, keep in mind these all function perfectly in any Excel output.
 So there are roughly 6 Cells like this with SUMs that total to 0 in the PDF
    $objPHPExcel->getActiveSheet()->getStyle('C'.(2+$Increment))->getFont()->setName('Arial');
    $objPHPExcel->getActiveSheet()->getStyle('C'.(2+$Increment))->getFont()->setSize(12);
    $objPHPExcel->getActiveSheet()->getStyle('C'.(2+$Increment))->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
    $objPHPExcel->getActiveSheet()->setCellValue('C'.(2+$Increment), '=SUM(C1:C'.(1+$Increment).')');
Totaling the $Increment cells above it

In the row below there is a static value applied for a multiplication cell beneath:
    $objPHPExcel->getActiveSheet()->getStyle('C'.(3+$Increment))->getFont()->setName('Arial');
    $objPHPExcel->getActiveSheet()->getStyle('C'.(3+$Increment))->getFont()->setSize(12);
    $objPHPExcel->getActiveSheet()->getStyle('C'.(3+$Increment))->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
    $objPHPExcel->getActiveSheet()->setCellValue('C'.3+$Increment), '0.55');


And here's the multiplication formula which totals to 0:
    $objPHPExcel->getActiveSheet()->getStyle('C'.(4+$Increment))->getFont()->setName('Arial');
    $objPHPExcel->getActiveSheet()->getStyle('C'.(4+$Increment))->getFont()->setSize(12);
    $objPHPExcel->getActiveSheet()->getStyle('C'.(4+$Increment))->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
    $objPHPExcel->getActiveSheet()->setCellValue('C'.(4+$Increment), '=C'.(2+$Increment).'*C'.(3+$Increment));

And the writer object
        $objWriter = new PHPExcel_Writer_PDF($objPHPExcel);
        $objWriter->setSheetIndex(0);
        $objWriter->setPreCalculateFormulas(true);
        $objWriter->save("reports/PHPExcelPDF.pdf");

anything stand out?
Coordinator
Jun 5, 2008 at 8:13 PM
There is a slight chance this is the PHP version... Would it be possible to test this on 5.2.5, for example?
Jun 5, 2008 at 10:29 PM
I'll give it a shot soon, but .. why would the test PDF render properly?
I'll let you know the results.