PHPExcel 读取excel 文件 问题

WBOY
Freigeben: 2016-06-20 12:30:27
Original
1556 Leute haben es durchsucht

读取代码如下:

$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);							}
Nach dem Login kopieren

这里不明白为什么时好时坏,好的时候可以正常输出数组数据,坏的时候输出的数据如下:
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;}" } } 
Nach dem Login kopieren


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


回复讨论(解决方案)

没有大神解答一下么?

问题都没描述全,时好时坏是什么情况?只传同一个文件还是不同的?不同的文件,有没有对比格式?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;  
      
    }  
  
}  

Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!