Home  >  Article  >  Backend Development  >  PHP读取Excel 之 Spreadsheet_Excel_Reader

PHP读取Excel 之 Spreadsheet_Excel_Reader

WBOY
WBOYOriginal
2016-06-23 14:32:071154browse

和Spreadsheet_Excel_Writer类似,Spreadsheet_Excel_Reader是用来读取Excel内容的工具。
可以方便的将Excel数据导入到数据或者其他用途。

如下代码:

<?php//调用Readerrequire_once 'Spreadsheet/Excel/Reader/reader.php';//创建 Reader$data = new Spreadsheet_Excel_Reader();//设置文本输出编码$data->setOutputEncoding('GB2312');//读取Excel文件$data->read("c:\test.xls");//$data->sheets[0]['numRows']为Excel行数for ($i = 1; $i <= $data->sheets[0]['numRows']; $i++) {  //$data->sheets[0]['numCols']为Excel列数  for ($j = 1; $j <= $data->sheets[0]['numCols']; $j++) {   //显示每个单元格内容   echo $data->sheets[0]['cells'][$i][$j];  }}?>


另,由于日期型的特殊性,在取值时可能会产生错误,可将Excel单元格类型设为Text,
将日期以文本形式读取,如需日期型字符再通过PHP对其进行处理即可(strtotime()结合date())。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:PHP之PDO介绍Next article:PHP正则详解