php读取excel文件-reader.php excel操作类使用
?一、?概述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?数组示例:
array( [0] => array ( [maxrow] => 0 [maxcol] => 0 [numrows] => 5 [numcols] => 3 [cells] => array ( [1] => array ( [1] => 网站名称 [2] => 网址 [3] => 类型 ) [2] => array ( [1] => 百度 [2] => http://www.baidu.com [3] => 搜索引擎 ) [3] => array ( [1] => 谷歌 [2] => http://www.google.com.hk [3] => 搜索引擎 ) [4] => array ( [1] => 400电话 [2] => http://www.my400800.cn [3] => 企业网站 ) [5] => array ( [1] => 新浪 [2] => http://www.sina.com.cn [3] => 门户网站 ) ) ) [1] => array ( [maxrow] => 0 [maxcol] => 0 [numrows] => 0 [numcols] => 0 ) [2] => array ( [maxrow] => 0 [maxcol] => 0 [numrows] => 0 [numcols] => 0 ))
?
boundsheets?数组包含了对象的其它信息,数组按?workbook?索引。?第二个索引为名称:?$xl_reader->boundsheets[i]['name']?返回第?i?个表的表名
例如:?$sheetname = $xl_reader->boundsheets[0]['name']; // name of the first sheet
?
$xl_reader-> boundsheets?数组示例:
array( [0] => array ( [name] => sheet1 [offset] => 2148 ) [1] => array ( [name] => sheet2 [offset] => 3484 ) [2] => array ( [name] => sheet3 [offset] => 3760 ))
?
php-excelreader?只能支持?biff7 ,biff8?格式的文件。包括?excel95?到?excel2003.?但是不包含?excel5.0?及之前的版本?.?实际上?excel xp?和?excel 2003?使用的?biff8x?是?biff8?格式的一个扩展?.?所有添加的特性可能不被?php-excelreader.?锁支持。否则它只能以?excel xp/2003?文件运行。