Output with recalculated values

Topics: User Forum
Nov 12, 2009 at 7:52 PM

I am using PHPExcel version 1.7.1 & PHP version 5.2.5.

I am trying to open an existing excel file, change the value of one cell and output the updated file to the user's browser so they can immediately open it. The sheet contains many calculated values, all of which are based on the value of the one cell which is changed.

The output works fine if the user has the full version of Microsoft Excel. But most of our users only have the "Excel Viewer 2003". When they open the changed file, none of the values are recalculated.

I've tried outputting the file to PDF. The values are calculated correctly, But the cell borders do not display. My research has told me that this is a known bug in the PDF export.

Here's what I have so far:

/** Error reporting */
ini_set('zend.ze1_compatibility_mode', '0');

/** PHPExcel_IOFactory */
//require_once '../Classes/PHPExcel/IOFactory.php';
require_once '../Classes/PHPExcel/Writer/Excel5.php';

if (!file_exists("CPR_Cards\CPRCardAdolescent12yearsolderprotected.xls")) {
	exit("CPRCardAdolescent12yearsolderprotected.xls FILE NOT FOUND!\n");

$objPHPExcel = PHPExcel_IOFactory::load("CPR_Cards\CPRCardAdolescent12yearsolderprotected.xls");

$objPHPExcel->getActiveSheet()->setCellValue('C3', $_GET['number']);

// Set active sheet index to the first sheet, so Excel opens this as the first sheet

// Redirect output to a client’s web browser (Excel5)
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="test.xls"');
header('Cache-Control: max-age=0');

//$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter = new PHPExcel_Writer_Excel5($objPHPExcel);


Since it appears that the Excel Viewer doesn't calculate the formulas, do you have any idea what I can do to get them recalculated before the output?



Nov 12, 2009 at 11:34 PM

You are correct that PHPExcel_Writer_Excel5 does not store calculated values. Your example shows that this can be a problem. Historically, the reason why PHPExcel_Writer_Excel5 does not store calculated values is because it is based on PEAR::Spreadsheet_Excel_Writer which did not feature a calculation engine, thus such feature was not possible to implement. Today situation is different.

I have created a work item for this. Will try put it on the to-do list for next week.



Nov 14, 2009 at 5:07 AM

Try with latest source code tomorrow:


Nov 16, 2009 at 2:07 PM

Thanks a bunch, koyama! That seems to have fixed my problem.

Bravo, on the quick response!!