phpExcel匯入資料

2022-09-09 01:48:12 字數 3859 閱讀 2862

public

function

import_table()

//限制上傳**型別

$file_type = $_files['file']['type'];

//var_dump($file_type);

// exit;

echo "上傳失敗,只能上傳excel的xls、xlsx格式!";

exit

(); }

//判斷**是否上傳成功

if (is_uploaded_file($_files['file']['tmp_name']))

$objreader = \phpexcel_iofactory::createreader('excel2007');//

use excel2007 for 2007 format

//接收存在快取中的excel**

$filename = $_files['file']['tmp_name'];

$objphpexcel = $objreader->load($filename); //

$filename可以是上傳的**,或者是指定的**

$sheet = $objphpexcel->getsheet(0);

$highestrow = $sheet->gethighestrow(); //

取得總行數

$highestcolumn = $sheet->gethighestcolumn(); //

取得總列數

$end_index = \phpexcel_cell::columnindexfromstring($highestcolumn);//

由列名轉為列數('ab'->28)

$dataset=array

();

for($j=3;$j

<=$highestrow;$j++)

}foreach ($dataset

as$k=>$v

) db('village')->insert($f

);

break

;

case 'people':

$fields=array('peoplename','gender','nation','birthdate','origin','peopletype','credentialtype','credentialno','villagecode','domicile','streetcode','domicileroadcode','domicileaddress','residence','residencecode','residenceroadcode','residenceaddress','educationcode','maritalstatuscode','spousename','spousetype','spouseno','nationalitycode','entrytime','surnameeng','nameeng','phonenoone','phonenooneperson','phonenoonepersontype','phonenoonepersonid','phonenotwo','phonenotwoperson','phonenotwopersontype','phonenotwopersonid','phonenothree','phonenothreeperson','phonenothreepersontype','phonenothreepersonid','idcardpicurl','source','rowtime');

$f=;

foreach ($fields

as$kk=>$vv

) db('people')->insert($f

);

break

;

case 'build':

$fields=array('villagecode','buildingcode','buildingno','floortotal','housetotal','note','lon','lat','alt','gisarea','gistype','rowtime');

$f=;

foreach ($fields

as$kk=>$vv

) db('build')->insert($f

);

break

;

case 'house':

$fields=array('villagecode','buildingcode','floor','houseno','housecode','houselabel','housepurpose','housearea','peoplenumber','note','lon','lat','alt','gistype','rowtime');

$f=;

foreach ($fields

as$kk=>$vv

) db('house')->insert($f

);

break

;

case 'company':

$fields=array('companycode','villagecode','companyname','companytype','companyadress','companypic','lon','lat','alt','gistype');

$f=;

foreach ($fields

as$kk=>$vv

) db('company')->insert($f

);

break

;

case 'company_house':

$fields=array('companycode','buildingcode','houseno','rowtime');

$f=;

foreach ($fields

as$kk=>$vv

) db('company_house')->insert($f

);

break

;

case 'company_people':

$fields=array('villagecode','buildingno','houseno','companycode','credentialtype','credentialno','phone','entrydate','jobtitle','remark','idcardpicurl');

$f=;

foreach ($fields

as$kk=>$vv

) db('company_people')->insert($f

);

break

; }

}$this->success('匯入成功',url('index/index'));

exit

(); }

}

phpexcel匯入excel資料

public function importexcel file phpexcel phpreader load file 載入excel物件 sheet phpexcel getsheet 0 獲取指定的sheet表 rows sheet gethighestrow 行數 cols sheet g...

PHP Excel匯入資料到MySQL資料庫

我的模板內的資料如下圖 後端介面 如下 public function uplexcel request request 取陣列最後乙個元素,得到檔案型別 uploaddir uploads2 date y m d 設定檔案儲存目錄 注意包含 if file exists uploaddir pat...

PHPExcel將Excel資料匯入資料庫

1 phpexcel讀取匯入excel資料到資料庫 2003,2007通用 使用方法 3 先用excel2array 方法將excel表中的資料儲存到陣列,在從遍歷二維陣列將資料儲存進資料庫 4require once phpexcel.class.php 5require once phpexce...