1. _toString() 是PHP自带的魔术方法,把对象强制转换为string
<?php
$dir = dirname(__FILE__); //找出当前脚本所在路径
// 比如当前文件所在目录是: D:\1WWW\yui890\syh ,则 $dir = D:\1WWW\yui890\syh
//利用php读取excel数据
require $dir.'\PHPExcel-1.8\Classes\PHPExcel\IOFactory.php';
$filename = $dir.'\list.xls';
$objPHPExcelReader = PHPExcel_IOFactory::load($filename); //加载excel文件
foreach($objPHPExcelReader->getWorksheetIterator() as $sheet) //循环读取sheet
{
foreach ($sheet->getRowIterator() as $row) //逐行处理
{
if ($row->getRowIndex() < 2) //确定从哪一行开始读取
{
continue;
}
foreach ($row->getCellIterator() as $cell) //逐列读取
{
$data = $cell->getValue(); //获取cell中数据
if($data instanceof PHPExcel_RichText) $data = $data->__toString(); // 这一行最关键!!!!
//var_dump($data);
echo $data;
}
echo '<br/>';
}
}
百度网盘:PHPExcel-1.8.zip【官网下载的】
http://pan.baidu.com/s/1jHK84g2
来源:http://blog.csdn.net/s390124971/article/details/52911042
http://blog.csdn.net/helencoder/article/details/48541633
网友评论