PHP-ExcelReader
生活随笔
收集整理的這篇文章主要介紹了
PHP-ExcelReader
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
一、概述
PHP-ExcelReader是一個讀取Excel xsl文件內(nèi)容的一個PHP類。
它的下載網(wǎng)址:http://sourceforge.net/projects/phpexcelreader/
文件名:phpExcelReader.zip
包含兩個必需文件:oleread.inc、reader.php。其它文件是一個應(yīng)用例子,自述文件等
?
二、文件使用
首先,包含reader類文件:require_once " reader.php";
新建一個實例:$xl_reader= new Spreadsheet_Excel_Reader ( );
讀取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ù) :
l?????? numRows -- int -- 表的行數(shù)
例如:$rows = $xl_reader->sheets[0]['numRows']
l?????? numCols -- int -- 表的列數(shù)
例如:$cols = $xl_reader->sheets[0]['numCols']
l?????? cells -- array -- 表的實際內(nèi)容。是一個 [row][column]格式的2維數(shù)組
?例如:$cell_2_4 = $xl_reader->sheets[0]['cells'][2][4] //行2,列4中的數(shù)據(jù)
l?????? 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數(shù)組示例:
Array
(
??? [0] => Array
??????? (
??????????? [maxrow] => 0
??????????? [maxcol] => 0
??????????? [numRows] => 30
??????????? [numCols] => 12
??????????? [cells] => Array
??????????????? (
??????????????????? [1] => Array
??????????????????????? (
??????????????????????????? [1] => 日期
??????????????????????????? [2] => 捐款人姓名/職稱
??????????????????????????? [3] => 金額
??????????????????????????? [4] => 原捐款金額
??????????????????????????? [5] => 收據(jù)號
??????????????????????????? [6] => 收據(jù)抬頭
??????????????????????????? [7] => 性別
??????????????????????????? [8] => 用途
??????????????????????????? [9] => 地址
??????????????????????????? [10] => 聯(lián)系人/電話
??????????????????????????? [11] => 執(zhí)行情形
??????????????????????????? [12] => 備注
??????????????????????? )
?
??????????????????? [2] => Array
??????????????????????? (
??????????????????????????? [1] => 2007/06/02
??????????????????????????? [2] => 秦榮華 魏清蓮 /集團(tuán)
??????????????????????????? [3] => 300000
??????????????????????????? [4] => 45
??????????????????????????? [5] => 502
??????????????????????????? [6] => 寧波國雅機械有限公司
??????????????????????????? [7] => 夫婦
??????????????????????????? [8] => 測試
??????????????????????????? [10] => 胡愛華秘書/135 6651 8117
??????????????????????????? [11] => 2008-9愛心小學(xué)1所25萬? 2008-12愛心小學(xué)1所25萬 2009-9 珍珠班2班 750000元? 餘額 25萬
??????????????????????????? [12] => 備注
??????????????????????? )
?
??????????????? )
?
??????????? [cellsInfo] => Array
??????????????? (
??????????????????? [2] => Array
??????????????????????? (
??????????????????????????? [1] => Array
??????????????????????????????? (
??????????????????????????????????? [raw] => 1180742400
??????????????????????????????????? [type] => date
??????????????????????????????? )
?
??????????????????????????? [3] => Array
??????????????????????????????? (
??????????????????????????????????? [raw] => 300000
??????????????????????????????????? [type] => number
??????????????????????????????? )
?
??????????????????????????? [4] => Array
??????????????????????????????? (
??????????????????????????????????? [raw] => 45
??????????????????????????????????? [type] => unknown
??????????????????????????????? )
?
??????????????????????????? [5] => Array
??????????????????????????????? (
??????????????????????????????????? [raw] => 502
??????????????????????????????????? [type] => unknown
??????????????????????????????? )
???????????????????????? )
???????????????? )
???????? )
???? [1] => Array
??????? (
??????????? [maxrow] => 0
??????????? [maxcol] => 0
??????????? [numRows] => 0
??????????? [numCols] => 0
??????? )
?
??? [2] => Array
??????? (
??????????? [maxrow] => 0
??????????? [maxcol] => 0
??????????? [numRows] => 0
??????????? [numCols] => 0
??????? )
?)
?
boundsheets 數(shù)組包含了對象的其它信息,數(shù)組按workbook索引。 第二個索引為名稱:$xl_reader->boundsheets[i]['name'] 返回第i個表的表名
例如:$sheetname = $xl_reader->boundsheets[0]['name']; // name of the first sheet
?
$xl_reader-> boundsheets數(shù)組示例:
Array
(
??? [0] => Array
??????? (
??????????? [name] => Sheet1
??????????? [offset] => 3054
??????? )
?
??? [1] => Array
??????? (
??????????? [name] => Sheet2
??????????? [offset] => 6147
??????? )
?
??? [2] => Array
??????? (
??????????? [name] => Sheet3
??????????? [offset] => 6410
??????? )
?)
?
PHP-ExcelReader只能支持 BIFF7 ,BIFF8格式的文件。包括Excel95到Excel2003.但是不包含Excel5.0及之前的版本.實際上 Excel XP 和Excel 2003 使用的BIFF8X是BIFF8格式的一個擴展.所有添加的特性可能不被PHP-ExcelReader.鎖支持。否則它只能以Excel XP/2003文件運行。
如果出現(xiàn):Fatal error: require_once() [function.require]: Failed opening required 'Spreadsheet/Excel/Reader/OLERead.php' (include_path='.;\xampp\php\PEAR') in XXXX
意思是缺少Spreadsheet/Excel/Reader/OLERead.php這個文件。但是確實是沒有這個文件呀!找了找,在excel目錄下發(fā)現(xiàn)了oleread.inc文件,于是將Spreadsheet/Excel/Reader/OLERead.php換成oleread.inc就OK了!
也就是將
??? require_once 'Spreadsheet/Excel/Reader/OLERead.php';
修改為
??? require_once 'oleread.inc';
即可。
另外,在example.php 中,需要修改
??? $data->setOutputEncoding('CP1251');
為
??? $data->setOutputEncoding('CP936');
不然的話中文將會有問題。
如果是使用繁體的話可以修改為CP950、日文是CP932,具體可參考codepage說明。
還有,其自帶的 jxlrwtest.xls 可能有問題,需要修改example.php中的:
??? $data->read('jxlrwtest.xls');
附件: phpexcelreader.zip (21.02 K, 下載次數(shù):37)
Tags: excel
PHP-ExcelReader是一個讀取Excel xsl文件內(nèi)容的一個PHP類。
它的下載網(wǎng)址:http://sourceforge.net/projects/phpexcelreader/
文件名:phpExcelReader.zip
包含兩個必需文件:oleread.inc、reader.php。其它文件是一個應(yīng)用例子,自述文件等
?
二、文件使用
首先,包含reader類文件:require_once " reader.php";
新建一個實例:$xl_reader= new Spreadsheet_Excel_Reader ( );
讀取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ù) :
l?????? numRows -- int -- 表的行數(shù)
例如:$rows = $xl_reader->sheets[0]['numRows']
l?????? numCols -- int -- 表的列數(shù)
例如:$cols = $xl_reader->sheets[0]['numCols']
l?????? cells -- array -- 表的實際內(nèi)容。是一個 [row][column]格式的2維數(shù)組
?例如:$cell_2_4 = $xl_reader->sheets[0]['cells'][2][4] //行2,列4中的數(shù)據(jù)
l?????? 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數(shù)組示例:
Array
(
??? [0] => Array
??????? (
??????????? [maxrow] => 0
??????????? [maxcol] => 0
??????????? [numRows] => 30
??????????? [numCols] => 12
??????????? [cells] => Array
??????????????? (
??????????????????? [1] => Array
??????????????????????? (
??????????????????????????? [1] => 日期
??????????????????????????? [2] => 捐款人姓名/職稱
??????????????????????????? [3] => 金額
??????????????????????????? [4] => 原捐款金額
??????????????????????????? [5] => 收據(jù)號
??????????????????????????? [6] => 收據(jù)抬頭
??????????????????????????? [7] => 性別
??????????????????????????? [8] => 用途
??????????????????????????? [9] => 地址
??????????????????????????? [10] => 聯(lián)系人/電話
??????????????????????????? [11] => 執(zhí)行情形
??????????????????????????? [12] => 備注
??????????????????????? )
?
??????????????????? [2] => Array
??????????????????????? (
??????????????????????????? [1] => 2007/06/02
??????????????????????????? [2] => 秦榮華 魏清蓮 /集團(tuán)
??????????????????????????? [3] => 300000
??????????????????????????? [4] => 45
??????????????????????????? [5] => 502
??????????????????????????? [6] => 寧波國雅機械有限公司
??????????????????????????? [7] => 夫婦
??????????????????????????? [8] => 測試
??????????????????????????? [10] => 胡愛華秘書/135 6651 8117
??????????????????????????? [11] => 2008-9愛心小學(xué)1所25萬? 2008-12愛心小學(xué)1所25萬 2009-9 珍珠班2班 750000元? 餘額 25萬
??????????????????????????? [12] => 備注
??????????????????????? )
?
??????????????? )
?
??????????? [cellsInfo] => Array
??????????????? (
??????????????????? [2] => Array
??????????????????????? (
??????????????????????????? [1] => Array
??????????????????????????????? (
??????????????????????????????????? [raw] => 1180742400
??????????????????????????????????? [type] => date
??????????????????????????????? )
?
??????????????????????????? [3] => Array
??????????????????????????????? (
??????????????????????????????????? [raw] => 300000
??????????????????????????????????? [type] => number
??????????????????????????????? )
?
??????????????????????????? [4] => Array
??????????????????????????????? (
??????????????????????????????????? [raw] => 45
??????????????????????????????????? [type] => unknown
??????????????????????????????? )
?
??????????????????????????? [5] => Array
??????????????????????????????? (
??????????????????????????????????? [raw] => 502
??????????????????????????????????? [type] => unknown
??????????????????????????????? )
???????????????????????? )
???????????????? )
???????? )
???? [1] => Array
??????? (
??????????? [maxrow] => 0
??????????? [maxcol] => 0
??????????? [numRows] => 0
??????????? [numCols] => 0
??????? )
?
??? [2] => Array
??????? (
??????????? [maxrow] => 0
??????????? [maxcol] => 0
??????????? [numRows] => 0
??????????? [numCols] => 0
??????? )
?)
?
boundsheets 數(shù)組包含了對象的其它信息,數(shù)組按workbook索引。 第二個索引為名稱:$xl_reader->boundsheets[i]['name'] 返回第i個表的表名
例如:$sheetname = $xl_reader->boundsheets[0]['name']; // name of the first sheet
?
$xl_reader-> boundsheets數(shù)組示例:
Array
(
??? [0] => Array
??????? (
??????????? [name] => Sheet1
??????????? [offset] => 3054
??????? )
?
??? [1] => Array
??????? (
??????????? [name] => Sheet2
??????????? [offset] => 6147
??????? )
?
??? [2] => Array
??????? (
??????????? [name] => Sheet3
??????????? [offset] => 6410
??????? )
?)
?
PHP-ExcelReader只能支持 BIFF7 ,BIFF8格式的文件。包括Excel95到Excel2003.但是不包含Excel5.0及之前的版本.實際上 Excel XP 和Excel 2003 使用的BIFF8X是BIFF8格式的一個擴展.所有添加的特性可能不被PHP-ExcelReader.鎖支持。否則它只能以Excel XP/2003文件運行。
如果出現(xiàn):Fatal error: require_once() [function.require]: Failed opening required 'Spreadsheet/Excel/Reader/OLERead.php' (include_path='.;\xampp\php\PEAR') in XXXX
意思是缺少Spreadsheet/Excel/Reader/OLERead.php這個文件。但是確實是沒有這個文件呀!找了找,在excel目錄下發(fā)現(xiàn)了oleread.inc文件,于是將Spreadsheet/Excel/Reader/OLERead.php換成oleread.inc就OK了!
也就是將
??? require_once 'Spreadsheet/Excel/Reader/OLERead.php';
修改為
??? require_once 'oleread.inc';
即可。
另外,在example.php 中,需要修改
??? $data->setOutputEncoding('CP1251');
為
??? $data->setOutputEncoding('CP936');
不然的話中文將會有問題。
如果是使用繁體的話可以修改為CP950、日文是CP932,具體可參考codepage說明。
還有,其自帶的 jxlrwtest.xls 可能有問題,需要修改example.php中的:
??? $data->read('jxlrwtest.xls');
附件: phpexcelreader.zip (21.02 K, 下載次數(shù):37)
Tags: excel
總結(jié)
以上是生活随笔為你收集整理的PHP-ExcelReader的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: tbody添加垂直滚动条
- 下一篇: PHP 与 Perl 对照表