1、 概述 php
PHP-ExcelReader 是一个读取 Excel xsl 文件内容的一个 PHP 类。 数组
它的下载网址: http://sourceforge.net/projects/phpexcelreader/ 函数
文件名: phpExcelReader.zip ui
包含两个必需文件: oleread.inc 、 reader.php 。其它文件是一个应用例子 , 自述文件等 .net
2、 文件使用 excel
首先 , 包含 reader 类文件: require_once " reader.php"; code
新建一个实例: $xl_reader= new Spreadsheet_Excel_Reader ( ); 对象
读取 Excel 文件信息: $xl_reader->read("filename.xls"); blog
它将导出 Excel 文件中全部能够识别的数据存储在一个对象中。数据存储在 2 个数组中,目前没有提供方法 / 函数访问这些数据. 能够像下面这样简单的使用数组名。 索引
sheets 数组包含了读取入对象的大量数据。它将导出 Excel 文件中全部能够识别的数据存储在一个 2 维数组中 $xl_reader->sheets[x][y] 。 x 为文档中的表序号, y 是如下的某个参数 :
l numRows -- int -- 表的行数
例如: $rows = $xl_reader->sheets[0]['numRows']
l numCols -- int -- 表的列数
例如: $cols = $xl_reader->sheets[0]['numCols']
l cells -- array -- 表的实际内容。是一个 [row][column] 格式的 2 维数组
例如: $cell_2_4 = $xl_reader->sheets[0]['cells'][2][4] // 行 2, 列 4 中的数据
l 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 数组示例:
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] => 3054
)
)
PHP-ExcelReader 只能支持 BIFF7 ,BIFF8 格式的文件。包括 Excel95 到 Excel2003. 可是不包含 Excel5.0 及以前的版本. 实际上 Excel XP 和 Excel 2003 使用的 BIFF8X 是 BIFF8 格式的一个扩展 . 全部添加的特性可能不被 PHP-ExcelReader. 锁支持。不然它只能以 Excel XP/2003 文件运行。
若是出现: 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目录下发 现了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 ');