1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
private function excel_handler($file){ //Start to read require(APPPATH.'libraries/PHPExcel.php'); include APPPATH.'libraries/PHPExcel/IOFactory.php'; $fields = $this->config->item('order_upload_fields'); //log_g($fields); // Read your Excel workbook try { $inputFileType = PHPExcel_IOFactory::identify($file); $objReader = PHPExcel_IOFactory::createReader($inputFileType); $objPHPExcel = $objReader->load($file); //log_g($objPHPExcel); } catch(Exception $e) { die('Error loading file "'.pathinfo($file,PATHINFO_BASENAME).'": '.$e->getMessage()); } // Get worksheet dimensions $sheet = $objPHPExcel->getSheet(0); $highestRow = $sheet->getHighestRow(); $highestColumn = $sheet->getHighestColumn(); $fields = $this->config->item('order_fields'); $upload_fields = $this->config->item('order_upload_fields'); //log_g($fields); for ($row = 2; $row <= $highestRow; $row++){ // Read a row of data into an array // The fourth param will convert datetime value automatically $rowData = $sheet->rangeToArray('A' . $row . ':' . $highestColumn . $row, NULL, TRUE, true); // Insert row data array into your database of choice here $data = $this->fill_fields($fields, $upload_fields, $rowData[0]); log_g($data); } log_g($highestColumn); } |
Reference: