php - 如何查看Excel文件第二张表?
问题描述
基本上,我已经创建了一个页面来在浏览器上查看 xlxs 文件。它工作正常,但问题是这个 php 代码只能显示一张纸。
我想要达到的目标:
- 使用 PHP Excel Reader 在浏览器上以表格格式显示 Excel 电子表格
- 检查 .xls 文档中有多少工作表,获取工作表名称并相应地显示按钮数量
- 按钮必须能够允许用户在一个文档的不同页面之间遍历
代码:
<?php
if($the1['file_type']=='excel'){
require_once "Classes/PHPExcel.php";
$reader= PHPExcel_IOFactory::createReaderForFile($the1['path'].'/'.$the1['file_name']);
$excel_Obj = $reader->load($the1['path'].'/'.$the1['file_name']);
$worksheet=$excel_Obj->getSheet('0');
$lastRow = $worksheet->getHighestRow();
$columncount = $worksheet->getHighestDataColumn();
$columncount_number=PHPExcel_Cell::columnIndexFromString($columncount);
echo "<table border='1'>";
for($row=0;$row<=$lastRow;$row++){
echo "<tr>";
for($col=0;$col<=$columncount_number;$col++){
echo "<td>";
echo $worksheet->getCell(PHPExcel_Cell::stringFromColumnIndex($col).$row)->getValue();
echo "</td>";
}
echo "</tr>";
}
echo "</table>";
mysqli_query($con,"update file1 set status='read' where file_name='$id'");
}
?>
解决方案
使用 setActiveSheetIndex(sheet number) 指定工作表 0(第一个工作表)、1(第二个工作表)、2(第三个工作表)等等。例如
$sheetindex=1; // use the 2nd sheet
$worksheet = $excel_Obj->setActiveSheetIndex($sheetindex);
推荐阅读
- c - 双精度、整数、长双精度
- ruby - 如何在 Windows 10 中安装 ruby 2.4.0
- ionic-framework - 如何在 Ionic 2/3 应用程序中使用 branch.io 创建 Android 应用程序链接?
- amazon-web-services - 为跨 AWS 账户创建的任何新存储桶创建 SNS 通知
- c++ - 删除符号和生成排列的算法
- c - 如何将文件添加到 mpd(音乐播放器守护程序)的播放列表?
- sorting - Elasticsearch 排序问题
- laravel - 为什么我在状态码 204 时收到“无效 JSON”?
- javascript - 重置对数组的更改
- algorithm - 如何获得 N 个项目的所有可能组合,分为 M 个项目的集合,并且同一集合中两个项目的出现值对于每个项目都相同?