* 將excel轉換為陣列 by aibhsc
* */
require(root_path .
'includes/phpexcel.php
');//
引入php excel類
function format_excel2array($filepath='',$sheet=0
) $phpreader = new phpexcel_reader_excel2007(); //
建立reader物件
if(!$phpreader->canread($filepath))
}$phpexcel = $phpreader->load($filepath); //
建立excel物件
$currentsheet = $phpexcel->getsheet($sheet); //
**讀取excel檔案中的指定工作表*/
$allcolumn = $currentsheet->gethighestcolumn(); //
**取得最大的列號*/
$allrow = $currentsheet->gethighestrow(); //
**取得一共有多少行*/
$data =array();
for($rowindex=1;$rowindex<=$allrow;$rowindex++)
$data[$rowindex][$colindex] =$cell;}}
return
$data;}
使用方法:
$filepath = root_path.'
data/diamondstock.xlsx
'; //
鑽石庫存盤案
$data =format_excel2array($filepath);
print_r($data);die;
輸出結果示例:
array
( [
1] =>array
([a] =>商品編號
[b] =>商品名稱
[c] =>總重量
[d] =>進貨**
[e] =>銷售**
[f] =>4c備註)[
2] =>array
([a] => 10001
[b] => gia-2156685995
[c] => 0.7
[d] => 1760
[e] => 1848
[f] => g色、0
.7ct、si1、fr)[
3] =>array
([a] => 10002
[b] => gia-2156685996
[c] => 0.7
[d] => 1760
[e] => 1848
[f] => g色、0
.7ct、si1、fr)[
4] =>array
([a] => 10003
[b] => gia-2156685997
[c] => 0.7
[d] => 1760
[e] => 1848
[f] => g色、0
.7ct、si1、fr)[
5] =>array
([a] => 10004
[b] => gia-2156685998
[c] => 0.7
[d] => 1760
[e] => 1848
[f] => g色、0
.7ct、si1、fr)[
6] =>array
([a] => 10005
[b] => gia-2156685999
[c] => 0.7
[d] => 1760
[e] => 1848
[f] => g色、0
.7ct、si1、fr)[
7] =>array
([a] => 10006
[b] => gia-2156686000
[c] => 0.7
[d] => 1760
[e] => 1848
[f] => g色、0
.7ct、si1、fr)[
8] =>array
([a] => 10007
[b] => gia-2156686001
[c] => 0.7
[d] => 1760
[e] => 1848
[f] => g色、0
.7ct、si1、fr)[
9] =>array
([a] => 10008
[b] => gia-2156686002
[c] => 0.7
[d] => 1760
[e] => 1848
[f] => g色、0
.7ct、si1、fr)[
10] =>array
([a] => 10009
[b] => gia-2156686003
[c] => 0.7
[d] => 1760
[e] => 1848
[f] => g色、0
.7ct、si1、fr)[
11] =>array
([a] => 10010
[b] => gia-2156686004
[c] => 0.7
[d] => 1760
[e] => 1848
[f] => g色、0
.7ct、si1、fr)[
12] =>array
([a] => 10011
[b] => gia-2156686005
[c] => 0.7
[d] => 1760
[e] => 1848
[f] => g色、0
.7ct、si1、fr)[
13] =>array
([a] => 10012
[b] => gia-2156686006
[c] => 0.7
[d] => 1760
[e] => 1848
[f] => g色、0
.7ct、si1、fr)[
14] =>array
([a] => 10013
[b] => gia-2156686007
[c] => 0.7
[d] => 1760
[e] => 1848
[f] => g色、0
.7ct、si1、fr
) )
PHPExcel 讀取Excel檔案
讀取excel檔案內容 dir str replace dirname file 當前檔案目錄 require once dir.phpexcel iofactory.php 引入excel類庫檔案 filename dir.browser.xls 操作的excel檔案 excelobj phpex...
PHPExcel讀取excel檔案
之前的博文已經對phpexcel匯出excel檔案做了簡單的總結,現對他讀取excel做以下總結。對資料量不會很大的建可以採用web直接用此方法讀取,如果資料量會很大的話,還是建議web只做上傳功能,讀取 處理還是放後台吧。phpexcel還是比較耗費時間 記憶體的。例項 php 首先匯入phpex...
PHPExcel讀取Excel檔案
用phpexcel讀取excel 2007 或者excel2003檔案 涉及知識點 php對excel檔案進行迴圈讀取 php對字元進行ascii編碼轉化,將字元轉為十進位制數 php對excel日期格式讀取,並進行顯示轉化 php對漢字亂碼進行編碼轉化 require once phpexcel....