extract sheet1 from multisheet xls

Topics: User Forum
Jul 15, 2009 at 5:55 PM

Is it possible to open a large xlsx and just extract the first sheet from it and save it as a xls ?  The large xlsx will have formulas and alot of references back and forth between the sheets but I just want to be able to grab the values from the 1st sheet and export it.

 

I am new to this framework so any help is appreciated.

 

Developer
Jul 15, 2009 at 6:05 PM
Edited Jul 15, 2009 at 6:14 PM

For a start, try something like this:

 

$reader = PHPExcel_IOFactory::createReader('Excel2007');
$reader->setLoadSheetsOnly('Sheet1');

$excel = $reader->load('test.xlsx');

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

 

Jul 15, 2009 at 7:33 PM

thanks for your reply.

 

I believe that your code will load the old sheet and write it as a Excel5 format as the output.

 

I am wanting to only write the first sheet out as the output.

 

Thanks

 

Developer
Jul 15, 2009 at 7:41 PM

>> I believe that your code will load the old sheet and write it as a Excel5 format as the output.

>>I am wanting to only write the first sheet out as the output.

These sound pretty much like the same things? Can you try the code and see what happens? In the above, replace Sheet1 with the name of the first sheet.