測試用excel文件:測試.xls,文件名:phpexcelreader.zip
包含兩個必需文件:oleread.inc,reader.php,其它文件是一個應(yīng)用例子,自述文件等.
二、文件使用
首先,包含 reader 類文件:require_once " reader.php";
新建一個實(shí)例:$xl_reader= new spreadsheet_excel_reader ( );
設(shè)定編碼信息:$xl_reader ->setoutputencoding('utf-8');//不設(shè)定可能會是亂碼,要和網(wǎng)頁顯示編碼一致.
讀取 excel 文件信息:$xl_reader->read("filename.xls");
它將導(dǎo)出 excel 文件中所有可以識別的數(shù)據(jù)存儲在一個對象中,數(shù)據(jù)存儲在 2 個數(shù)組中,目前沒有提供方法函數(shù)訪問這些數(shù)據(jù),可以像下面這樣簡單的使用數(shù)組名.
sheets 數(shù)組包含了讀取入對象的大量數(shù)據(jù),它將導(dǎo)出 excel 文件中所有可以識別的數(shù)據(jù)存儲在一個 2 維數(shù)組中 $xl_reader->sheets[x][y],x 為文檔中的表序號,y 是以下的某個參數(shù):
① numrows -- int -- 表的行數(shù)
例如:$rows = $xl_reader->sheets[0]['numrows']
② numcols -- int -- 表的列數(shù)
例如:$cols = $xl_reader->sheets[0]['numcols']
③ cells -- array -- 表的實(shí)際內(nèi)容,是一個 [row][column] 格式的 2 維數(shù)組
例如: $cell_2_4 = $xl_reader->sheets[0]['cells'][2][4] // 行 2, 列 4 中的數(shù)據(jù)
④ cellsinfo -- array -- 表格中不同數(shù)據(jù)類型的信息,每個都包含了表格的原始數(shù)據(jù)和類型,這個數(shù)組包含 2 部分:raw -- 表格原始數(shù)據(jù),type -- 數(shù)據(jù)類型.
注:只顯示非文本數(shù)據(jù)信息.
例如:$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
新聞熱點(diǎn)
疑難解答