读取代码如下:
$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;}" } }
没有大神解答一下么?
问题都没描述全,时好时坏是什么情况?只传同一个文件还是不同的?不同的文件,有没有对比格式?xls还是xlsx?同样格式的文件有好有坏,有没有打开文件对比内容?
问题都没描述全,时好时坏是什么情况?只传同一个文件还是不同的?不同的文件,有没有对比格式?xls还是xlsx?同样格式的文件有好有坏,有没有打开文件对比内容?
问题解决了,强制转换一下类型就可以了 (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;
}
}
全网最新最细最实用WPS零基础入门到精通全套教程!带你真正掌握WPS办公! 内含Excel基础操作、函数设计、数据透视表等
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号