PHP 利用 PHPexcel 匯入資料庫

2021-09-06 08:55:21 字數 1714 閱讀 2160

<?php

error_reporting(e_all); //開啟錯誤

set_time_limit(0); //指令碼不超時

date_default_timezone_set('europe/london'); //設定時間

/** include path **/

set_include_path(get_include_path() . path_separator . '');//設定環境變數

/** phpexcel_iofactory */

include 'phpexcel/iofactory.php';

//$inputfiletype = 'excel5'; //這個是讀 xls的

$inputfiletype = 'excel2007';//這個是計xlsx的

//$inputfilename = './sampledata/example2.xls';

$inputfilename = './sampledata/book.xlsx';

echo 'loading file ',pathinfo($inputfilename,pathinfo_basename),' using iofactory with a defined reader type of ',$inputfiletype,'

'; $objreader = phpexcel_iofactory::createreader($inputfiletype);

$objphpexcel = $objreader->load($inputfilename);

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

$highestrow = $sheet->gethighestrow(); //取得總行數

$highestcolumn = $sheet->gethighestcolumn(); //取得總列

*/

$objworksheet = $objphpexcel->getactivesheet();//取得總行數

$highestrow = $objworksheet->gethighestrow();//取得總列數

echo 'highestrow='.$highestrow;

echo "

"; $highestcolumn = $objworksheet->gethighestcolumn();

$highestcolumnindex = phpexcel_cell::columnindexfromstring($highestcolumn);//總列數

echo 'highestcolumnindex='.$highestcolumnindex;

echo "

"; $headtitle=array();

for ($row = 1;$row <= $highestrow;$row++)

$info = array(

'word1'=>"$strs[0]",

'word2'=>"$strs[1]",

'word3'=>"$strs[2]",

'word4'=>"$strs[3]",

);//在這兒,你可以連線,你的資料庫,寫入資料庫了

print_r($info);

echo '

'; }

?>

PHP 利用 PHPexcel 匯入資料庫

error reporting e all 開啟錯誤 set time limit 0 指令碼不超時 date default timezone set europe london 設定時間 include path set include path get include path path se...

phpexcel 匯入匯出

匯出excel 以下是使用示例,對於以 開頭的行是不同的可選方式,請根據實際需要 開啟對應行的注釋。如果使用 excel5 輸出的內容應該是gbk編碼。require once phpexcel.php uncomment require once phpexcel writer excel5.ph...

phpExcel匯入資料

public function import table 限制上傳 型別 file type files file type var dump file type exit echo 上傳失敗,只能上傳excel的xls xlsx格式 exit 判斷 是否上傳成功 if is uploaded fi...