import data from excel sheet using codeigniter -


i want import sing column of excel sheet database table name admin_record , excel sheet consist of 1 column , name of column bar codes , rows can many.

i want save in database table name admin_record , consists of 2 fields

  1. id (which primary key)
  2. bar_code.

find code totally cant understand

public function read_file($table = 'admin_record', $filename = 'example.xls') {      $pathtofile = 'uploads/' . $filename;     $this->load->library('spreadsheet_excel_reader');     $data = new spreadsheet_excel_reader($pathtofile);     $sql = "insert $table (";     for($index = 1;$index <= $data->sheets[0]['numcols']; $index++){     $sql.= strtolower($data->sheets[0]['cells'][1][$index]) . ", ";     }      $sql = rtrim($sql, ", ")." ) values ( ";     ($i = 2; $i <= $data->sheets[0]['numrows']; $i++) {         $valuessql = '';     ($j = 1; $j <= $data->sheets[0]['numcols']; $j++) {         $valuessql .= "\"" . $data->sheets[0]['cells'][$i][$j] . "\", ";     }     echo $sql . rtrim($valuessql, ", ")." ) <br>";     } } 

your library file wrong please use following link download spreadsheet_excel_reader library

public function my_test($table = 'admin_record', $filename = 'resources/uploads/c.xls')     {             $pathtofile = $filename;            $valuessql="";             $this->load->library('spreadsheet_excel_reader');             $data = new spreadsheet_excel_reader($pathtofile);             $sql = "insert $table (";             for($index = 1;$index <= $data->sheets[0]['numcols']; $index++){             $sql.= strtolower($data->sheets[0]['cells'][1][$index]) . ", ";             }              $sql = rtrim($sql, ", ")." ) values ( ";             ($i = 2; $i <= $data->sheets[0]['numrows']; $i++) {             $valuessql = '';             ($j = 1; $j <= $data->sheets[0]['numcols']; $j++) {             $valuessql .= "\"" . $data->sheets[0]['cells'][$i][$j] . "\", ";             }             echo $sql . rtrim($valuessql, ", ")." ) <br>";             }                                           // add line       } 

Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -