Pass variable via Form

Topics: User Forum
Sep 19, 2012 at 12:28 PM

Hello,

Can anybody tell me if this is possible with PHPexcel?
I want to load an xls file, and change certain cell values (provided via an PHP form) so the output is calculated via PHP Excel.

Something like this:

require_once 'PHPExcel/Classes/PHPExcel/IOFactory.php';
$file="testfile.xlsx";

$Reader = PHPExcel_IOFactory::createReaderForFile($file);
$objXLS = $Reader->load($file);

/* overwrite a cell value */
$objXLS->getSheet(0)->getCell('C15')->setValue(46);

/* a formula including c15 */ echo $objXLS->getSheet(0)->getCell('C32')->getCalculatedValue();
By doing this, i still get the original calculated value. Any way I can achieve this?
Coordinator
Sep 19, 2012 at 5:41 PM

You'd only get the original calculated value if you've already executed getCalculatedValue() for that cell prior to overriding cell values, because PHPExcel maintains a cell cache of previously calculated values for each cell and uses that if available. Either don't call getCalculatedValue() before populating your cells, or flush the cache using PHPExcel_Calculation::getInstance()->clearCalculationCache() before your subsequent call to getCalculatedValue();

Take a look at the Quadratic.php example in /Tests which does pretty much what you're asking