Rewriting an Excel Document

Topics: Developer Forum, User Forum
Mar 3, 2009 at 12:57 AM
Edited Mar 3, 2009 at 12:57 AM
Hello,

I just downloaded the latest PHPExcel and it's very impressive.  My problem is that I would like to write to an existing Excel document that has data already in it.  I want to place content into one (or more) cells in an existing Excel document without overwriting the file and losing the existing data.  I'm sure this can be done when the file is written but not sure how.  Can someone help?  Thanks a bunch!


Developer
Mar 3, 2009 at 3:07 AM
It should be possible to read, modify, write. Example:

$reader = PHPExcel_IOFactory::createReader('Excel2007');
$excel = $reader->load('template.xlsx');

$sheet = $excel->getSheet(0);
$sheet->getCell('A1')->setValue('hello');

$writer = PHPExcel_IOFactory::createWriter($excel, 'Excel2007');
$writer->save('write.xlsx');

Mar 3, 2009 at 1:47 PM
Thanks!  This worked great!