PHP Excel匯入資料到MySQL資料庫

2022-08-18 19:54:12 字數 1451 閱讀 7264

我的模板內的資料如下圖:

後端介面**如下:

public

function uplexcel(request $request

)

//取陣列最後乙個元素,得到檔案型別

$uploaddir = "../uploads2/" . date("y-m-d") . '/';//

設定檔案儲存目錄 注意包含

if (!file_exists($uploaddir

))

$path = $uploaddir . md5(uniqid(rand())) . '.' . $type; //

產生隨機檔名

//$path = "images/".$filename; //客戶端上傳的檔名;

//下面必須是tmp_name 因為是從臨時資料夾中移動

move_uploaded_file($_files['excel']['tmp_name'], $path); //

從伺服器臨時檔案拷貝到相應的資料夾下

$file_path = $path

;

if (!file_exists($path

))

//檔案的副檔名

$ext = strtolower(pathinfo($path,pathinfo_extension));

if ($ext == 'xlsx')

elseif ($ext == 'xls')

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

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

取得總行數

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

取得總列數

$ar = array

();

$i = 0;

$importrows = 0;

for ($j = 2; $j

<= $highestrow; $j++)

}if ($i > 0)

$ret['res'] = "1";

$ret['allnum'] = $importrows

;

$ret['errnum'] = 0;

$ret['sucnum'] = $importrows

;

$ret['mdata'] = "匯入成功!";

return json_encode($ret

); }

else

}

phpExcel匯入資料

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

PHPExcel匯入到資料庫

使用phpexcel 讀取excel 資料到資料庫 建立乙個讀取excel資料,可用於入庫 function readexcel file return datas excel 資料 批量匯入資料庫 param string table 表名 param array excel result exc...

使用kettle匯入excel資料到mysql

kettle跑起來,要求有jre環境。另外,如果連線mysql資料庫的話,kettle本身是不包含mysql連線的jar,需要你手動放到安裝目錄的lib目錄下。如果是kettle啟動後放入的,需要重啟一下kettle。資料庫表設計圖 其中 id是主鍵 role code是角色 匯入時,根據excel...