Read one worksheet at a time

Topics: Developer Forum, User Forum
May 12, 2010 at 10: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
Coordinator
May 12, 2010 at 10: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 10: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!
Coordinator
May 12, 2010 at 10:54 PM
Edited May 12, 2010 at 10: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 12, 2010 at 11:00 PM
OK Thanks very much for your answer.
Coordinator
Jan 21, 2011 at 10:14 PM
Edited Jan 21, 2011 at 10:17 PM

This functionality now exists in the SVN code:

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

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 5:44 PM

I needed this for validation. Thanks. :)