• 读取文件已支持 windows 系统,版本号大于等于 1.3.4.1
  • 扩展版本大于等于 1.3.2
  • PECL 安装时将会提示是否开启读取功能,请键入 yes

函数原型

sheetList(): array

示例

  1. $excel = new \Vtiful\Kernel\Excel(['path' => './tests']);
  2. // 构建示例文件
  3. $filePath = $excel
  4. // 第一个工作表
  5. ->fileName('tutorial.xlsx', 'test1')
  6. ->header(['sheet'])
  7. ->data([['test1']])
  8. // 第二个工作表
  9. ->addSheet('test2')
  10. ->header(['sheet'])
  11. ->data([['test2']])
  12. ->output();
  13. // 打开示例文件
  14. $sheetList = $excel->openFile('tutorial.xlsx')
  15. ->sheetList();
  16. foreach ($sheetList as $sheetName) {
  17. echo 'Sheet Name:' . $sheetName . PHP_EOL;
  18. // 通过工作表名称获取工作表数据
  19. $sheetData = $excel
  20. ->openSheet($sheetName)
  21. ->getSheetData();
  22. var_dump($sheetData);
  23. }

示例输出

  1. Sheet Name:test1
  2. array(2) {
  3. [0]=>
  4. array(1) {
  5. [0]=>
  6. string(5) "sheet"
  7. }
  8. [1]=>
  9. array(1) {
  10. [0]=>
  11. string(5) "test1"
  12. }
  13. }
  14. Sheet Name:test2
  15. array(2) {
  16. [0]=>
  17. array(1) {
  18. [0]=>
  19. string(5) "sheet"
  20. }
  21. [1]=>
  22. array(1) {
  23. [0]=>
  24. string(5) "test2"
  25. }
  26. }