Writing Data on Existing Workbook without disturbing a specific spreadsheet

Topics: Developer Forum
Sep 16, 2010 at 2:12 PM

Hi All,

I need to make a copy of an existing xls template [template.xlsx - with 4 spreadsheets, three sheets are not having data, and the fourth sheet has some charts which will be generated dynamically when those three sheets are getting data].

On that new copy of the template [new.xlsx], I m trying to write data on the first three spreadsheets.

I could write data on the three spreadsheets, it works fine,  

but the charts and data on the fourth sheet is not retaining!!!

Help ME!

Thanks in advance.

And my code is,


require_once '1.7.4/Classes/PHPExcel/IOFactory.php';

$objPHPexcel = PHPExcel_IOFactory::load('template.xlsx');

$objWorksheet = $objPHPexcel->setActiveSheetIndex(0);


$objWorksheet = $objPHPexcel->setActiveSheetIndex(1);


$objWorksheet = $objPHPexcel->setActiveSheetIndex(2);


$objWriter = PHPExcel_IOFactory::createWriter($objPHPexcel, 'Excel2007');








Sep 16, 2010 at 9:23 PM
Edited Sep 16, 2010 at 9:25 PM

This is not possible at present, although the data on your 4th worksheet should be retained... I can't explain why this is being lost. However, charts are not yet supported (we're planning on implemented them later this Autumn)... and PHPExcel will discard anything that it doesn't yet support when reading from an existing workbook, hence the loss of your charts.


$objWriter = PHPExcel_IOFactory::createWriter($objPHPexcel, 'Excel2007');

You should be using the Excel5 Writer to generate an xls file, or change the new filename to an xlsx extension.


Sep 20, 2010 at 11:35 AM


Thanks MARK!!

But could you tell how to write on sheets of an existing workbook ??





Sep 21, 2010 at 12:30 PM
Premalatha wrote:

But could you tell how to write on sheets of an existing workbook ??

 The method that you outlined in your original post should work perfectly well, with the proviso that I made before that any elements of Excel that aren't yet supported by PHPExcel will be lost.

If you need a solution to edit Excel workbooks that loses nothing, then the only suggestion that I can make is .COM