一、 概述
php教程-excelreader 是一個讀取 excel xsl 檔案內容的一個 php 類。
它的下載網址: http://sourceforge.net/projects/phpexcelreader/
本部落格下載地址:phpexcelreader.zip
測試用excel檔案:測試.xls
檔案名稱: phpexcelreader.zip
包含兩個必需檔案: oleread.inc 、 reader.php 。其它檔案是一個應用例子 , 讀我檔案等
二、 檔案使用
首先 , 包含 reader 類檔案: require_once " reader.php";
建立一個執行個體: $xl_reader= new spreadsheet_excel_reader ( );
設定編碼資訊: $xl_reader ->setoutputencoding('utf-8');//不設定可能會是亂碼 要和網頁顯示編碼一致
讀取 excel 檔案資訊: $xl_reader->read("filename.xls");
它將匯出 excel 檔案中所有可以識別的資料存放區在一個對象中。資料存放區在 2 個數組中,目前沒有提供方法 / 函數訪問這些資料 . 可以像下面這樣簡單的使用數組名。
sheets 數組包含了讀取入對象的大量資料。它將匯出 excel 檔案中所有可以識別的資料存放區在一個 2 維數組中 $xl_reader->sheets[x][y] 。 x 為文檔中的表序號, y 是以下的某個參數 :
① numrows -- int -- 表的行數
例如: $rows = $xl_reader->sheets[0]['numrows']
② numcols -- int -- 表的列數
例如: $cols = $xl_reader->sheets[0]['numcols']
③ cells -- array -- 表的實際內容。是一個 [row][column] 格式的 2 維數組
例如: $cell_2_4 = $xl_reader->sheets[0]['cells'][2][4] // 行 2, 列 4 中的資料
④ cellsinfo -- array -- 表格中不同資料類型的資訊。每個都包含了表格的未經處理資料和類型。這個數組包含 2 部分: raw -- 表格未經處理資料; type -- 資料類型。
註:只顯示非文本資料資訊。
例如: $cell_info = $xl_reader[0]['cellsinfo'][2][4]
$cell_info['raw'] is the raw data from the cell
$cell_info['type'] is the data type
$xl_reader->sheets