【问题标题】:How to read Excel(.xlsx) file in php(codeigniter)?如何在 php(codeigniter) 中读取 Excel(.xlsx) 文件?
【发布时间】:2017-06-23 11:27:02
【问题描述】:

我正在使用 CodeIgniter,我想读取 excel 文件以提取数据并将其保存到 PHPmyAdmin 数据库。

我试过一些第三方库,比如

1- SimpleXLSX.class.php
2- Excel_reader

但这些对我没有帮助。

谁能给我一个很好的例子,说明如何在 CodeIgniter 中有效地读取 excel 文件?

【问题讨论】:

标签: php excel codeigniter phpexcel excel-reader


【解决方案1】:

这是从 .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);

【讨论】:

  • fgetcsv()从原生 BIFF (xls) 或 OfficeOpenXML (xlsx) 格式文件中读取,仅从基本 CSV 文件中读取跨度>
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-09-03
相关资源
最近更新 更多