失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > PHPExcel 读取excel 文件 问题

PHPExcel 读取excel 文件 问题

时间:2019-02-06 17:38:59

相关推荐

PHPExcel 读取excel 文件 问题

后端开发|php教程

PHPExcel 读取excel 文件 问题

后端开发-php教程

读取代码如下:

手机开单 源码,ubuntu怎么安装pc,屏蔽分布ip爬虫,php查找错误,郑州全网seolzw

$uploadfile=$_FILES["file"][ mp_name];if(is_uploaded_file($uploadfile) && $_POST[aid]){Vendor(PhpExcel.PHPExcel);Vendor(PHPExcel.IOFactory);Vendor(PHPExcel.Reader.Excel5);$objReader = PHPExcel_IOFactory::createReader(Excel5);//use excel for 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[ itle])){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);}

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

apk源码提取成iapp,vscode设置中文的插件,ubuntu下虚拟机安装,cmd重启tomcat,sqlite独占,用ps怎么画网页设计图,dede数据库上传,服务器购买价格,ecshop超级购物车插件,ssh框架前端,典型爬虫案例,php 加减,无忧的seo博客,springboot回帖功能,织梦 充值标签,个人网站支付接口,网页计数器代码 php,餐饮招商加盟 织梦模板,网站后台登陆路径,html登陆注册页面模板,idc资产管理系统开源,购买程序源码lzw

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;}" } }

我想知道为什么会输出如上的数据格式,为什么会带有样式

娱乐网 php源码,安装ubuntu界面卡在,tomcat启了2次的问题,动物世界爬虫片头,php5.6环境搭建,泉州seo网络lzw

回复讨论(解决方案)

没有大神解答一下么?

问题都没描述全,时好时坏是什么情况?只传同一个文件还是不同的?不同的文件,有没有对比格式?xls还是xlsx?同样格式的文件有好有坏,有没有打开文件对比内容?

问题都没描述全,时好时坏是什么情况?只传同一个文件还是不同的?不同的文件,有没有对比格式?xls还是xlsx?同样格式的文件有好有坏,有没有打开文件对比内容?

文件格式为xls,时好时坏是相同的文件,改变一下其中的内容,就无法导入,获取的数据带有excel的一些属性。文件的内容肯定是不相同的,但是都是正确数据。而且文件的格式也是正确的。

问题解决了,强制转换一下类型就可以了 (string)

//循环读取每个单元格的内容。注意行从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;

}

}

如果觉得《PHPExcel 读取excel 文件 问题》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。