(需要解释)spout reader 文档

(need explanation) spout reader documentation

有人可以帮我处理这个 spout 文档吗,

use Box\Spout\Reader\Common\Creator\ReaderEntityFactory;

$reader = ReaderEntityFactory::createReaderFromFile('/path/to/file.ext');

$reader->open($filePath);

foreach ($reader->getSheetIterator() as $sheet) {
    foreach ($sheet->getRowIterator() as $row) {
        // do stuff with the row
        $cells = $row->getCells();
        ...
    }
}

$reader->close();

我不明白的是:

  1. 我应该用 ('/path/to/file.ext')
  2. 做什么
  3. $filePath 从何而来?我们是否需要创建一个名为 $filePath 的变量来指向临时上传的文件?

我已经阅读了文档,但我还是不明白 我也尝试用代码点火器来实现它,这是我的代码:

require_once APPPATH.'third_party\spout\src\Spout\Autoloader\autoload.php'; 使用 Box\Spout\Reader\Common\Creator\ReaderEntityFactory;

class Excel 扩展 CI_Controller {

//==========================================================
// C O N S T R U C T O R
//==========================================================
    public function __construct()
    {
        parent::__construct();
        $this->load->model('Excel_model');
    }

    public function index()
    {
        $reader = ReaderEntityFactory::createReaderFromFile('/path/to/file.ext');
        $filePath = APPPATH.'third_party\spout\src\temp\test.xlsx';
        $reader->open($filePath);

        foreach ($reader->getSheetIterator() as $sheet) {
            foreach ($sheet->getRowIterator() as $row) {
                // do stuff with the row
                $cells = $row->getCells();
                echo $cells;
            }
        }

        $reader->close();   
    }   

}   

却收到此错误消息:

An uncaught Exception was encountered

Type: Box\Spout\Common\Exception\UnsupportedTypeException

Message: No readers supporting the given type: ext

Filename: D:\ONNE\OTHERS\_CODING_PROGRAMMING\XAMPP\htdocs\bulus-ci\application\third_party\spout\src\Spout\Reader\Common\Creator\ReaderFactory.php

Line Number: 59

Backtrace:

File: D:\ONNE\OTHERS\_CODING_PROGRAMMING\XAMPP\htdocs\bulus-ci\application\third_party\spout\src\Spout\Reader\Common\Creator\ReaderFactory.php
Line: 42
Function: createFromType

File: D:\ONNE\OTHERS\_CODING_PROGRAMMING\XAMPP\htdocs\bulus-ci\application\third_party\spout\src\Spout\Reader\Common\Creator\ReaderEntityFactory.php
Line: 24
Function: createFromFile

File: D:\ONNE\OTHERS\_CODING_PROGRAMMING\XAMPP\htdocs\bulus-ci\application\controllers\Excel.php
Line: 20
Function: createReaderFromFile

File: D:\ONNE\OTHERS\_CODING_PROGRAMMING\XAMPP\htdocs\bulus-ci\index.php
Line: 315
Function: require_once

文件路径是指向您尝试阅读的电子表格的字符串。您需要这样定义它并将其传递给 Spout:

use Box\Spout\Reader\Common\Creator\ReaderEntityFactory;

$filePath = APPPATH.'third_party\spout\src\temp\test.xlsx';
$reader = ReaderEntityFactory::createReaderFromFile($filePath);
$reader->open($filePath);

foreach ($reader->getSheetIterator() as $sheet) {
    foreach ($sheet->getRowIterator() as $row) {
        // do stuff with the row
        $cells = $row->getCells();
        ...
    }
}

$reader->close();

你能试试看吗?