简体   繁体   English

使用PHPExcel读取xls和xlsx文件中的所有工作表

[英]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 嗨我正在开发一个项目,使用PHP显示excel文件的内容到目前为止这里是我正在编写的代码

$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 非常感谢提前

By default, the HTML Writer only displays a single sheet (the current active worksheet). 默认情况下,HTML Writer仅显示单个工作表(当前活动工作表)。

You can change that by calling the Writer's writeAllSheets() method before saving. 您可以在保存之前通过调用Writer的writeAllSheets()方法来更改它。

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

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');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM