PHPExcel overrides xlsx content with previous opened file.

Topics: Developer Forum
Dec 6, 2012 at 6:09 AM

Hi Guys, Good day!,

I'm having problem implementing PHPExcel, I was able to read/parse the xlsx format but whenever my script is done running the content of the file is modified by the old opened/processed file. I tried restarting apache even my workstation to purge cached data but to no avail, I simply don't know what could be the problem. Please help :D 

 

System Info

PHPEngine : 5.3.5

O.S. : Windows 7 Ultimate

PHPExcel : 1.7.8, 2012-10-12

 

Actual Script

$objReader = PHPExcel_IOFactory::createReader('Excel2007');

$objReader->setReadDataOnly(true);

 $objPHPExcel = $objReader->load('../update_XLSX/ZMR5420121117.xlsx');

$objWorksheet = $objPHPExcel->getActiveSheet()->toArray(null, true, true, true);

Coordinator
Dec 6, 2012 at 7:29 AM

I'm not really sure I understand..... Your script is loading a file and reading the worksheet data into an array, but not much more. You're not changing any data or saving anything.

Dec 6, 2012 at 9:07 AM
Edited Dec 6, 2012 at 9:07 AM

Yes Sir you're right, what I wanted to do is just read the data inside that xlsx then save it to database, further processing will be done without using PHPExcel. The problem I'm facing is that whenever I open a new file using this code the data/cell/colum of this file will be overwritten with the data of my previous opened file (last subject file). It's like there's a cloning happening when the $object->load() is executed. Could this be a cache? Thanks for your speedy reply very much appreciated.

Coordinator
Dec 6, 2012 at 3:59 PM

If you're trying to load several workbook files in a big loop, then you need to clear down each PHPExcel object once you've finished using it, and before you load the next workbook: see section 4.3 of the developer documentation for clearing a workbook from memory.

You'll also need to clear the calculation cache