0

I'm using CodeIgniter and I want to read excel file to extract data and save it to PHPmyAdmin database.

I've tried some third party libraries like

1- SimpleXLSX.class.php
2- Excel_reader

but these are not helping me.

Can anybody please give me a good example of how to read excel files in CodeIgniter efficiently?

Josua Marcel C
  • 3,122
  • 6
  • 45
  • 87
Farhan92
  • 35
  • 3
  • 9

1 Answers1

-2

Here is the code to read from .xlsx file in to mysql database.

  $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);
Ketan Solanki
  • 697
  • 5
  • 13
  • 3
    `fgetcsv()` will ___not___ read from a native BIFF (xls) or OfficeOpenXML (xlsx) format file, only from basic CSV files – Mark Baker Jun 23 '17 at 11:50