$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;$startgetactivesheet()->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;} } }
我想知道为什么会输出如上的数据格式,为什么会带有样式
回复讨论(解决方案) 没有大神解答一下么?
问题都没描述全,时好时坏是什么情况?只传同一个文件还是不同的?不同的文件,有没有对比格式?xls还是xlsx?同样格式的文件有好有坏,有没有打开文件对比内容?
问题都没描述全,时好时坏是什么情况?只传同一个文件还是不同的?不同的文件,有没有对比格式?xls还是xlsx?同样格式的文件有好有坏,有没有打开文件对比内容?
文件格式为xls,时好时坏是相同的文件,改变一下其中的内容,就无法导入,获取的数据带有excel的一些属性。文件的内容肯定是不相同的,但是都是正确数据。而且文件的格式也是正确的。 问题解决了,强制转换一下类型就可以了 (string)
//循环读取每个单元格的内容。注意行从1开始,列从a开始
for($rowindex=1;$rowindex for($colindex='a';$colindex $addr = $colindex.$rowindex;
$cell = $currentsheet->getcell($addr)->getvalue();
if($cell instanceof phpexcel_richtext) //富文本转换字符串
$cell = $cell->__tostring();
echo $cell;
}
}
