BourneShady
BourneShady

Reputation: 935

read all sheets in xls and xlsx file using PHPExcel

hi im working on a project that displays the content of an excel file using php so far here is the code im working on

$inputFileType = 'Excel5'; // Excel2007 for xlsx
$inputFileName = $opendoc;

$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objPHPExcel = $objReader->load($inputFileName);

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'HTML');
$objw = $objWriter;
$objw->save('php://output');

my problem is how to display the other sheets because only one sheet is being displayed any ideas? thanks so much in advance

Upvotes: 1

Views: 3429

Answers (2)

Mark Baker
Mark Baker

Reputation: 212522

By default, the HTML Writer only displays a single sheet (the current active worksheet).

You can change that by calling the Writer's writeAllSheets() method before saving.

$objw = PHPExcel_IOFactory::createWriter($objPHPExcel, 'HTML');
$objw->writeAllSheets();
$objw->save('php://output');

Upvotes: 2

Itai Bar-Haim
Itai Bar-Haim

Reputation: 1674

Try adding the following line after creating the reader and before loading the file:

$objReader->setLoadAllSheets();

so it becomes:

$inputFileType = 'Excel5'; // Excel2007 for xlsx
$inputFileName = $opendoc;

$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objReader->setLoadAllSheets();
$objPHPExcel = $objReader->load($inputFileName);

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'HTML');
$objw = $objWriter;
$objw->save('php://output');

Upvotes: 2

Related Questions