最近,在我的一个基于 CodeIgniter 的项目中,我需要从 Excel 文件( .xlsx 和 .xls )读取数据并将这些数据插入 MySQL。不幸的是,我没有使用PHP电子表格之前(因为我不需要使用 Excel :( )。
到目前为止我所做的是下载PHP电子表格从Github下载并解压到我的根目录代码点火器项目。
PHPSpreadsheet in CodeIgniter root directory.
File Structure of PHPSpreadsheet.
到目前为止,我已经尝试将官方文档示例导入到我的 CI 应用程序中:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
use PhpOffice\PhpSpreadsheet\IOFactory;
class Welcome extends CI_Controller {
function __construct() {
parent::__construct();
}
public function index()
{
$inputFileType = 'Xlsx';
$inputFileName = 'test.xlsx';
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
/** Load $inputFileName to a Spreadsheet Object **/
$spreadsheet = $reader->load($inputFileName);
print_r( $spreadsheet );
}
}
But it shows the following error!!
谁能告诉我如何使用PHP电子表格 in 代码点火器从Excel文件中读取数据并将其存储到MySQL数据库中?
包含 PhpSpreadsheet 的最简单方法是使用 Composer - 文档位于https://phpspreadsheet.readthedocs.io/en/latest/ https://phpspreadsheet.readthedocs.io/en/develop/解释了如何执行此操作。
否则,您将需要 PSR4 自动加载器来加载 use 语句指定的类或自己包含文件。如果您自己包含文件,要读取 Excel 文件,您需要包含 PhpSpreadsheet/src/PhpSpreadsheet/IOFactory.php
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)