problem with Excel5 and special characters

Topics: Developer Forum
Aug 29, 2012 at 1:04 PM
Edited Aug 29, 2012 at 1:13 PM

I am using PHPExcel 1.7.7 with Linux server, and running on PHP5.2.17.

My code is as follows, (in utf-8)

 

			$objPHPExcel = new PHPExcel(); 
			$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
			
			$names = array(
				"林珊",
				"陳大文",
				"Chan Tai Man
			);
			
			$objSheet = $objPHPExcel->getActiveSheet();

			foreach ($names as $key => $tmp_string)	{
				$objSheet->getCell('A'.($key+1))->setValue($tmp_string);
				$objSheet->getCell('B'.($key+1))->setValue("1");
				$objSheet->getCell('C'.($key+1))->setValue("2");
			}
			

			header('Content-Type: application/vnd.ms-excel');
			header("Content-Disposition: attachment; filename=foo_bar.xls" );
			
			ob_end_clean();
			$objWriter->save('php://output');  

 

And turns out, the Excel prompted that "excel found unreadable content", and thus open in protected view, and the whole column A are empty.  It is OK when i move "" from the content.  

The content should be crashed by some special characters, and it is perfectly OK when saved in Excel2007.

Would anyone help advising how I could detect/remove the problem characters with Excel5?  I must have the file in Excel5, in extension .xls.  Many thanks.

Aug 29, 2012 at 1:14 PM

(repost, as the special characters missing after editing the post)

I am using PHPExcel 1.7.7 with Linux server, and running on PHP5.2.17.

My code is as follows, (in utf-8)

 

			$objPHPExcel = new PHPExcel(); 
			$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
			
			$names = array(
				"林𩓙珊",
				"陳大文",
				"Chan Tai Man
			);
			
			$objSheet = $objPHPExcel->getActiveSheet();

			foreach ($names as $key => $tmp_string)	{
				$objSheet->getCell('A'.($key+1))->setValue($tmp_string);
				$objSheet->getCell('B'.($key+1))->setValue("1");
				$objSheet->getCell('C'.($key+1))->setValue("2");
			}
			

			header('Content-Type: application/vnd.ms-excel');
			header("Content-Disposition: attachment; filename=foo_bar.xls" );
			
			ob_end_clean();
			$objWriter->save('php://output');  

 

And turns out, the Excel prompted that "excel found unreadable content", and thus open in protected view, and the whole column A are empty.  It is OK when i move "𩓙" from the content.  

The content should be crashed by some special characters, and it is perfectly OK when saved in Excel2007.

Would anyone help advising how I could detect/remove the problem characters with Excel5?  I must have the file in Excel5, in extension .xls.  Many thanks.

Coordinator
Aug 29, 2012 at 3:05 PM

Is your script saved as UTF-8 without BOM?

Aug 31, 2012 at 3:48 AM

Yes, I have saved my script as UTF-8 without BOM with Notepad++