Skip to content

Instantly share code, notes, and snippets.

@amin3d
Created June 22, 2016 11:41
Show Gist options
  • Save amin3d/98f476129438e2d242aae4c1aa4cb345 to your computer and use it in GitHub Desktop.
Save amin3d/98f476129438e2d242aae4c1aa4cb345 to your computer and use it in GitHub Desktop.
add to database PHPEXCEL AND CODEIGNITER
public function index()
{
$this->load->library('excel');
$objReader = PHPExcel_IOFactory::createReader('Excel2007');
$objReader->setReadDataOnly(true);
$objPHPExcel = $objReader->load("uploads/foghetakhasos.xlsx");
$objWorksheet = $objPHPExcel->getActiveSheet();
$highestRow = $objWorksheet->getHighestRow();
$highestColumn = $objWorksheet->getHighestColumn();
$this->load->database();
$highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);
for ($row = 1; $row <= $highestRow; ++$row) {
if($objWorksheet->getCellByColumnAndRow(0, $row)->getValue()!='')
{
$value = trim($objWorksheet->getCellByColumnAndRow(0, $row)->getValue(),chr(0xC2).chr(0xA0));
$data = array(
'title' => $value,
'type' => 'foghtakhasos',
);
$this->db->insert('expertslist', $data);
echo 'inserted';
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment