Codeigniter (需要说明)喷口阅读器文档
有人能帮我弄一下这个喷口文档吗Codeigniter (需要说明)喷口阅读器文档,codeigniter,spout,Codeigniter,Spout,有人能帮我弄一下这个喷口文档吗 use Box\Spout\Reader\Common\Creator\ReaderEntityFactory; $reader = ReaderEntityFactory::createReaderFromFile('/path/to/file.ext'); $reader->open($filePath); foreach ($reader->getSheetIterator() as $sheet) { foreach ($shee
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();
我不明白的是:
//==========================================================
// 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();
你能试一试吗?是的,非常感谢。但是还有一个问题,当我尝试vardump$cells时,结果是一个令人困惑的对象,我不知道如何使用它
$cell[0]->getValue()
返回行的第一个单元格中的值。你可以用一个简单的foreach遍历单元格($cells作为$cell){…}
。