PHPExcel 读取excel 文件 问题

feraner 2015-01-13 06:18:20
读取代码如下:

$uploadfile=$_FILES["file"]['tmp_name'];
if(is_uploaded_file($uploadfile) && $_POST['aid']){
Vendor('PhpExcel.PHPExcel');
Vendor('PHPExcel.IOFactory');
Vendor('PHPExcel.Reader.Excel5');

$objReader = PHPExcel_IOFactory::createReader('Excel5');//use excel2007 for 2007 format
$objPHPExcel = $objReader->load($uploadfile);


$sheet = $objPHPExcel->getSheet(0);
$highestRow = 0; // 取得总行数
$highestColumn = $sheet->getHighestColumn(); // 取得总列数

$start=1;//从哪一行开始录入/删除

if($_POST['diyihang']){
//忽略第一行
$highestRow = $sheet->getHighestRow(); // 取得总行数
$start=2;
}else{
$highestRow= ($sheet->getHighestRow()); // 取得总行数
}


$update=array();
$delete=array();
//获取信息字段
$fresult=M("form")->where("aid = %d",$_POST['aid'])->order("sort")->select();

for($start;$start<=$highestRow;$start++){

//读取单元格
$temp['title']=$objPHPExcel->getActiveSheet()->getCell("B".$start)->getValue();

//物业编号,认证码为空 不要
if(empty($temp['title'])){
continue;
}

$temp['assess']=$objPHPExcel->getActiveSheet()->getCell("C".$start)->getValue();
$temp['is_status']=$objPHPExcel->getActiveSheet()->getCell("D".$start)->getValue();
$temp['sort']=$objPHPExcel->getActiveSheet()->getCell("E".$start)->getValue();
$temp['aid']=$_POST['aid'];
$coll=ord("F");
foreach($fresult as $key=>$one){
$temp['form_content'][$one['id']]=$objPHPExcel->getActiveSheet()->getCell(chr($coll).$start)->getValue();
$coll++;
}

$temp['form_content']=serialize($temp['form_content']);

if($objPHPExcel->getActiveSheet()->getCell("A".$start)->getValue()){
$temp['id']=$objPHPExcel->getActiveSheet()->getCell("A".$start)->getValue();
array_push($delete, $temp);
}else{
array_push($update, $temp);

}


unset($temp);

}

这里不明白为什么时好时坏,好的时候可以正常输出数组数据,坏的时候输出的数据如下:

array(2) { [0]=> array(6) { ["title"]=> object(PHPExcel_RichText)#223 (1) { ["_richTextElements":"PHPExcel_RichText":private]=> array(2) { [0]=> object(PHPExcel_RichText_Run)#224 (2) { ["_font":"PHPExcel_RichText_Run":private]=> object(PHPExcel_Style_Font)#227 (12) { ["_name":protected]=> string(6) "瀹嬩綋" ["_size":protected]=> int(11) ["_bold":protected]=> bool(false) ["_italic":protected]=> bool(false) ["_superScript":protected]=> bool(false) ["_subScript":protected]=> bool(false) ["_underline":protected]=> string(4) "none" ["_strikethrough":protected]=> bool(false) ["_color":protected]=> object(PHPExcel_Style_Color)#228 (4) { ["_argb":protected]=> string(8) "FF000000" ["_parentPropertyName":protected]=> NULL ["_isSupervisor":protected]=> bool(false) ["_parent":protected]=> NULL } ["_isSupervisor":protected]=> bool(false) ["_parent":protected]=> NULL ["colorIndex"]=> int(8) } ["_text":"PHPExcel_RichText_TextElement":private]=> string(6) "椤烘櫙" } [1]=> object(PHPExcel_RichText_Run)#225 (2) { ["_font":"PHPExcel_RichText_Run":private]=> object(PHPExcel_Style_Font)#230 (12) { ["_name":protected]=> string(7) "Calibri" ["_size":protected]=> int(11) ["_bold":protected]=> bool(false) ["_italic":protected]=> bool(false) ["_superScript":protected]=> bool(false) ["_subScript":protected]=> bool(false) ["_underline":protected]=> string(4) "none" ["_strikethrough":protected]=> bool(false) ["_color":protected]=> object(PHPExcel_Style_Color)#231 (4) { ["_argb":protected]=> string(8) "FF000000" ["_parentPropertyName":protected]=> NULL ["_isSupervisor":protected]=> bool(false) ["_parent":protected]=> NULL } ["_isSupervisor":protected]=> bool(false) ["_parent":protected]=> NULL ["colorIndex"]=> int(8) } ["_text":"PHPExcel_RichText_TextElement":private]=> string(5) "1-502" } } } ["assess"]=> string(6) "宸蹭氦" ["is_status"]=> float(1) ["sort"]=> float(1000) ["aid"]=> string(3) "692" ["form_content"]=> string(32) "a:2:{i:829;d:123;i:830;d:42225;}" } [1]=> array(6) { ["title"]=> object(PHPExcel_RichText)#236 (1) { ["_richTextElements":"PHPExcel_RichText":private]=> array(2) { [0]=> object(PHPExcel_RichText_Run)#237 (2) { ["_font":"PHPExcel_RichText_Run":private]=> object(PHPExcel_Style_Font)#240 (12) { ["_name":protected]=> string(6) "瀹嬩綋" ["_size":protected]=> int(11) ["_bold":protected]=> bool(false) ["_italic":protected]=> bool(false) ["_superScript":protected]=> bool(false) ["_subScript":protected]=> bool(false) ["_underline":protected]=> string(4) "none" ["_strikethrough":protected]=> bool(false) ["_color":protected]=> object(PHPExcel_Style_Color)#241 (4) { ["_argb":protected]=> string(8) "FF000000" ["_parentPropertyName":protected]=> NULL ["_isSupervisor":protected]=> bool(false) ["_parent":protected]=> NULL } ["_isSupervisor":protected]=> bool(false) ["_parent":protected]=> NULL ["colorIndex"]=> int(8) } ["_text":"PHPExcel_RichText_TextElement":private]=> string(6) "椤烘櫙" } [1]=> object(PHPExcel_RichText_Run)#238 (2) { ["_font":"PHPExcel_RichText_Run":private]=> object(PHPExcel_Style_Font)#243 (12) { ["_name":protected]=> string(7) "Calibri" ["_size":protected]=> int(11) ["_bold":protected]=> bool(false) ["_italic":protected]=> bool(false) ["_superScript":protected]=> bool(false) ["_subScript":protected]=> bool(false) ["_underline":protected]=> string(4) "none" ["_strikethrough":protected]=> bool(false) ["_color":protected]=> object(PHPExcel_Style_Color)#244 (4) { ["_argb":protected]=> string(8) "FF000000" ["_parentPropertyName":protected]=> NULL ["_isSupervisor":protected]=> bool(false) ["_parent":protected]=> NULL } ["_isSupervisor":protected]=> bool(false) ["_parent":protected]=> NULL ["colorIndex"]=> int(8) } ["_text":"PHPExcel_RichText_TextElement":private]=> string(5) "1-503" } } } ["assess"]=> string(6) "鏈浜" ["is_status"]=> float(1) ["sort"]=> float(1001) ["aid"]=> string(3) "692" ["form_content"]=> string(32) "a:2:{i:829;d:125;i:830;d:42225;}" } }


我想知道为什么会输出如上的数据格式,为什么会带有样式
...全文
1709 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
jujusmile 2017-04-14
  • 打赏
  • 举报
回复
我想用PHPExcel读取上传的excel文件,不需要保存上传的文件,但是我用PHPExcel直接读取上传文件的临时文件,读取失败,你是怎么读取的?我看到你是直接读取的临时文件
zhong_0924 2016-11-11
  • 打赏
  • 举报
回复
EnhengQ 2016-09-23
  • 打赏
  • 举报
回复
PHPExcel操作excel文件,感觉会出现很多问题,不好解决啊。用插件么,不少插件都是蛮不错的,PageOffice插件就很不错,功能全面,集成方便,可以网上查查,他们也会提供事例代码的。
xubangwen2009 2016-04-26
  • 打赏
  • 举报
回复
//循环读取每个单元格的内容。注意行从1开始,列从A开始 for($rowIndex=1;$rowIndex<=$allRow;$rowIndex++){ for($colIndex='A';$colIndex<=$allColumn;$colIndex++){ $addr = $colIndex.$rowIndex; $cell = $currentSheet->getCell($addr)->getValue(); if($cell instanceof PHPExcel_RichText) //富文本转换字符串 $cell = $cell->__toString(); echo $cell; } }
feraner 2015-01-25
  • 打赏
  • 举报
回复
问题解决了,强制转换一下类型就可以了 (string)
feraner 2015-01-15
  • 打赏
  • 举报
回复
引用 2 楼 wander_wind 的回复:
问题都没描述全,时好时坏是什么情况?只传同一个文件还是不同的?不同的文件,有没有对比格式?xls还是xlsx?同样格式的文件有好有坏,有没有打开文件对比内容?
文件格式为xls,时好时坏是相同的文件,改变一下其中的内容,就无法导入,获取的数据带有excel的一些属性。文件的内容肯定是不相同的,但是都是正确数据。而且文件的格式也是正确的。
智商众筹 2015-01-15
  • 打赏
  • 举报
回复
问题都没描述全,时好时坏是什么情况?只传同一个文件还是不同的?不同的文件,有没有对比格式?xls还是xlsx?同样格式的文件有好有坏,有没有打开文件对比内容?
feraner 2015-01-14
  • 打赏
  • 举报
回复
没有大神解答一下么?

20,359

社区成员

发帖
与我相关
我的任务
社区描述
“超文本预处理器”,是在服务器端执行的脚本语言,尤其适用于Web开发并可嵌入HTML中。PHP语法利用了C、Java和Perl,该语言的主要目标是允许web开发人员快速编写动态网页。
phpphpstorm 技术论坛(原bbs)
社区管理员
  • 开源资源社区
  • phpstory
  • xuzuning
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧