有人能帮我处理这个喷口文档吗,
use BoxSpoutReaderCommonCreatorReaderEntityFactory;
$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();
我没有得到的是:
- 我应该如何处理('/path/to/file.ext'(
- $filePath从哪里来?我们是否需要创建一个名为$filePath的变量,该变量将指向临时上传的文件
我已经阅读了文档,但我仍然不明白我还尝试用代码点火器来实现它,这是我的代码:
require_one APPPATH。'第三方\喷口\ src\spout\Autoloader\autoload.php';使用Box\Spout\Reader\Common\Creator\ReaderEntityFactory;
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_partyspoutsrctemptest.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: BoxSpoutCommonExceptionUnsupportedTypeException
Message: No readers supporting the given type: ext
Filename: D:ONNEOTHERS_CODING_PROGRAMMINGXAMPPhtdocsbulus-ciapplicationthird_partyspoutsrcSpoutReaderCommonCreatorReaderFactory.php
Line Number: 59
Backtrace:
File: D:ONNEOTHERS_CODING_PROGRAMMINGXAMPPhtdocsbulus-ciapplicationthird_partyspoutsrcSpoutReaderCommonCreatorReaderFactory.php
Line: 42
Function: createFromType
File: D:ONNEOTHERS_CODING_PROGRAMMINGXAMPPhtdocsbulus-ciapplicationthird_partyspoutsrcSpoutReaderCommonCreatorReaderEntityFactory.php
Line: 24
Function: createFromFile
File: D:ONNEOTHERS_CODING_PROGRAMMINGXAMPPhtdocsbulus-ciapplicationcontrollersExcel.php
Line: 20
Function: createReaderFromFile
File: D:ONNEOTHERS_CODING_PROGRAMMINGXAMPPhtdocsbulus-ciindex.php
Line: 315
Function: require_once
文件路径是一个字符串,指向要读取的电子表格。你需要定义它并通过这种方式将其传递给Spout:
use BoxSpoutReaderCommonCreatorReaderEntityFactory;
$filePath = APPPATH.'third_partyspoutsrctemptest.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();
你能试试吗?