Read one worksheet at a time

Topics: Developer Forum, User Forum
May 12, 2010 at 11:03 PM
I am trying to load an excel file containing several worksheets. However, I will not know the name of the sheets as the user may change them. So I will need to load each sheet in sequence without knowing its name. Is this possible? I know that I can use the following: $objReader->setLoadSheetsOnly() but I need to know the name of the sheet right? Can I use an index instead? Thank you for your help
May 12, 2010 at 11:18 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
May 12, 2010 at 11:33 PM
Hi Again.. I understand that such feature is not available at the moment... so is there a way to get a list of all the worksheets names in a given excel file without loading all the excel file in memory? I am using the following at the moment: $objReader = PHPExcel_IOFactory::createReader('Excel2007'); $objReader->setReadDataOnly(true); $objPHPExcel = $objReader->load("test3.xlsx"); But it is having a big performance issues as the file is quite large. So what I need is to get the names of each worksheet and then load one worksheet at a time by loading it by name, without loading all the file in the first place. Is it possible? Or I am asking the impossible :) Thank you very much for your help once again and for a wonderful piece of software!
May 12, 2010 at 11:54 PM
Edited May 12, 2010 at 11:57 PM

Unfortunately, the answer to that question is "no", and providing a loader function like loadWorksheetNamesOnly() would be very inefficient.

I'd suggest using a PHPExcel_Reader_IReadFilter, but even that uses the worksheet name rather than index number

May 13, 2010 at 12:00 AM
OK Thanks very much for your answer.
Jan 21, 2011 at 11:14 PM
Edited Jan 21, 2011 at 11:17 PM

This functionality now exists in the SVN code:

$inputFileType = 'Excel5';
$inputFileName = './sampleData/example1.xls';
$objReader = PHPExcel_IOFactory::createReader($inputFileType);

returns an array of worksheet names

This method only exists for readers that support multiple-worksheets (Excel5, Excel2007, Gnumeric, OOCalc and Excel2003XML); not to CSV or SYLK.

Feb 21, 2011 at 6:44 PM

I needed this for validation. Thanks. :)