1

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

Itai Bar-Haim
  • 1,686
  • 16
  • 40
BourneShady
  • 955
  • 2
  • 17
  • 36

2 Answers2

2

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');
Itai Bar-Haim
  • 1,686
  • 16
  • 40
  • hi! for example i have 2 sheets what it did was loaded the 1st sheet twice. any ideas? – BourneShady May 23 '16 at 06:29
  • Try saving to a different format, see if it exports the sheets correctly. If so, then there's a bug in the save HTML implementation (they do say in the documentation it has its limitations). If it does work, and there is a bug in saving HTML, perhaps you can roll your own, by saving each and every sheet to HTML separately in a loop. – Itai Bar-Haim May 23 '16 at 06:31
2

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');
Mark Baker
  • 209,507
  • 32
  • 346
  • 385