[英]PhpSpreadsheet foreach loop through multiple sheets
I'm new to PhpSpreadsheet, I have a file with multiple sheets (all the same), I checked all the examples in the Reader section of the documentation, but each example ends with a code like 我是PhpSpreadsheet的新手,我有一个包含多个工作表的文件(都一样),我检查了文档“ 读者”部分中的所有示例,但每个示例都以类似以下代码的结尾
$sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true);
so seems that I can get my data only from the active sheet. 看来我只能从活动工作表中获取数据。 I would like to loop through each sheet to get data from each one, something like: 我想遍历每张工作表以从每张工作表中获取数据,例如:
foreach ($sheetData as $sheet) {
echo "...my data ...";
}
Any idea? 任何想法? Am I missing something? 我想念什么吗? Thanks 谢谢
You'd want to use the getSheetCount()
method to determine how many sheets there are, and then use a standard for
loop with getSheet()
: 您想要使用getSheetCount()
方法来确定有多少张纸,然后for
getSheet()
使用标准的for
循环:
$sheetCount = $spreadsheet->getSheetCount();
for ($i = 0; $i < $sheetCount; $i++) {
$sheet = $spreadsheet->getSheet($i);
$sheetData = $sheet->toArray(null, true, true, true);
}
See the Worksheet documentation . 请参阅工作表文档 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.