如何在php(codeigniter)中读取Excel(.xlsx)文件?
我正在使用CodeIgniter,我想读取excel文件以提取数据并将其保存到PHPmyAdmin数据库如何在php(codeigniter)中读取Excel(.xlsx)文件?,php,excel,codeigniter,phpexcel,excel-reader,Php,Excel,Codeigniter,Phpexcel,Excel Reader,我正在使用CodeIgniter,我想读取excel文件以提取数据并将其保存到PHPmyAdmin数据库 $csvFile = fopen("path/to/your/file"); //skip first line fgetcsv($csvFile); //read data from csv file line by line while(($line = fgetcsv($csvFile)) !== FALSE){ //You can hav
$csvFile = fopen("path/to/your/file");
//skip first line
fgetcsv($csvFile);
//read data from csv file line by line
while(($line = fgetcsv($csvFile)) !== FALSE){
//You can have your active record's query to insert it into Db
$db->query("INSERT INTO tableName (Column1) VALUES ('".$line[0]."')");
}
//close opened csv file
fclose($csvFile);
我试过一些第三方库,比如
1- SimpleXLSX.class.php
2- Excel_reader
但这些对我没有帮助
有谁能给我举个好例子,说明如何高效地读取CodeIgniter中的excel文件吗?以下是从.xlsx文件读取到mysql数据库的代码
$csvFile = fopen("path/to/your/file");
//skip first line
fgetcsv($csvFile);
//read data from csv file line by line
while(($line = fgetcsv($csvFile)) !== FALSE){
//You can have your active record's query to insert it into Db
$db->query("INSERT INTO tableName (Column1) VALUES ('".$line[0]."')");
}
//close opened csv file
fclose($csvFile);
请检查我使用的PHPExcel库,它非常适合从
.xls
或.xslx
文件导入数据。检查此问题我看到了相同的问题,请检查它,希望它也适用于您。可能重复的fgetcsv()
不会从本机BIFF(xls)或OfficeOpenXML(xlsx)格式文件中读取,只能从基本CSV文件中读取