// In CodeIgniter Version - 3.1.11
public function upload(){
ini_set('MAX_EXECUTION_TIME', -1);
ini_set('memory_limit', '-1');
if(isset($_FILES["file_upload"]["name"]))
{
require 'vendor/autoload.php';
$path = $_FILES["file_upload"]["tmp_name"];
$object = PHPExcel_IOFactory::load($path);
$db_flag = true;
foreach($object->getWorksheetIterator() as $worksheet)
{
$highestRow = $worksheet->getHighestRow();
$highestColumn = $worksheet->getHighestColumn();
$sheetname = $worksheet->getTitle();
$sheetname = trim($sheetname);
if ($sheetname == "Asset Wise & Location Wise")
{
$db_flag = false;
$db_count = 0;
$this->db->truncate("fi_asset_wise");
$this->load->helper('dt_helper');
$this->db->trans_start();
// get data from excel
for($row=5; $row<=$highestRow; $row++)
{
$asst_categ = trim($worksheet->getCellByColumnAndRow(0, $row)->getCalculatedValue());
if(empty($asst_categ) || strpos(strtoupper($asst_categ), "TOTAL") !== FALSE )
{
continue;
}
$descrip = trim($worksheet->getCellByColumnAndRow(1, $row)->getCalculatedValue());
$rate = trim($worksheet->getCellByColumnAndRow(2, $row)->getCalculatedValue());
$main_head = trim($worksheet->getCellByColumnAndRow(3, $row)->getCalculatedValue());
$sub_head = trim($worksheet->getCellByColumnAndRow(4, $row)->getCalculatedValue());
$gl_code = trim($worksheet->getCellByColumnAndRow(5, $row)->getCalculatedValue());
$asset_code = trim($worksheet->getCellByColumnAndRow(6, $row)->getCalculatedValue());
if(empty($dt_of_sale)) {
$dt_of_sale = null;
}else{
$db_udt = ($dt_of_sale- 25569) * 86400;
$date=date("d-m-Y", $db_udt);
$dt_of_sale = check_format_method($date);
}
$no_of_days = trim($worksheet->getCellByColumnAndRow(26, $row)->getCalculatedValue());
$insert_arr = array(
'asst_categ' => $asst_categ,
'descrip' => $descrip,
'rate' => $rate,
'main_head' => $main_head,
'sub_head' => $sub_head,
'gl_code' => $gl_code,
'asset_code' => $asset_code,
'dt_of_sale' => $dt_of_sale,
'no_of_days' => ($no_of_days >= 0.00 )?$no_of_days:0.00,
'status' => 1,
'created_at' => date('Y-m-d H:i:s'),
'updated_at' => date('Y-m-d H:i:s')
);
if(!empty($insert_arr))
{
$this->ass_model->insertData($insert_arr);
++$db_count;
}
}
$this->db->trans_complete();
// Running Transactions Manually
if ($this->db->trans_status() === FALSE){
$this->db->trans_rollback();
} else {
$this->db->trans_commit();
}
}
}
if($db_flag === true)
{
$this->session->set_flashdata('db_error', 'Error !! Invalid Sheet Name. Please enter correct sheetname.');
redirect(site_url('fixed-asset/fixed-asset-register'));
}
if($db_count > 0)
{
$this->session->set_flashdata('db_success', 'Success - Data Inserted Successfully');
redirect(site_url('fixed-asset/fixed-asset-register'));
}
}
}
getActiveSheet()
方法。 - Dennis BragagetHighestRow()
应该替换为getHighestDataRow()
;列函数同理。 - Raptor