Generated Excel Files have errors (part II)

Topics: User Forum
Nov 26, 2009 at 9:10 PM
Edited Nov 26, 2009 at 9:41 PM


I have the same problem as posted by Urkman Oct 14 at 10:58 AM.

My generated file is valid on localhost using XAMP but the same code from server bring me broken xls file. I checked iconv and works fine in my case. I'm using latest (1.7.1) version of library. I alsow check if any errors will occur by using:

ini_set('display_errors', '1');

but nothing showed.

I used Tests\01simple-download-xls.php to generate both files. Localhost PHP 5.2.9, server PHP 5.2.4


If i save file on serwer and then download everything works fine and file is valid but encoding fails.

Nov 26, 2009 at 9:14 PM

I posted files in

Nov 27, 2009 at 1:46 AM

Somehow a line break got inserted at the beginning of the file called 76354-01simple(server).xls as seen when opened in a text editor

It should look like in 76354-01simple(local).xls

Perhaps you have a newline before the opening <?php in your script?

Nov 27, 2009 at 8:35 AM
Edited Nov 27, 2009 at 8:35 AM

Thank you for fast replay. You were right, that was empty line in my application. I have another question about speed. My code:



		$objPHPExcel = new PHPExcel();
		// Set properties
		// Add some data
		$styleHeaderArray = array(
			'font' => array(
				'bold' => true,
			'alignment' => array(
				'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
				'vertical' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
			'borders' => array(
				'allborders' => array(
					'style' => PHPExcel_Style_Border::BORDER_THIN,
				'color' => array(
					'rgb' => PHPExcel_Style_Color::COLOR_BLACK,			 
			'fill' => array(
				'type' => PHPExcel_Style_Fill::FILL_SOLID,
				'startcolor' => array(
					'rgb' => 'FFFFCC',
		// Set headers & autosize
		foreach($this->headers as $key => $val){
			$objPHPExcel->getActiveSheet()->setCellValueExplicitByColumnAndRow($key, 1, $val);
			$objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($key, 1)->applyFromArray($styleHeaderArray);
		foreach($this->result as $row => $rowData){
			//set values 
			foreach($rowData as $column => $cellValue){
				$objPHPExcel->getActiveSheet()->setCellValueExplicitByColumnAndRow($column, ($row+2), $cellValue);
			//row height
		// Rename sheet
		// Redirect output to a client’s web browser (Excel5)
		header('Content-Type: application/');
		header('Content-Disposition: attachment;filename="test.xls"');
		header('Cache-Control: max-age=0');
		$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');




9 columns and 7245 rows generation time is about 34s. Is there any way to speed up this process?

Jan 22, 2010 at 6:25 AM
pawaroti wrote:

9 columns and 7245 rows generation time is about 34s. Is there any way to speed up this process?

AutoSize columns is known to slow down the process.

Sep 20, 2013 at 9:01 AM
Hello all,

I have the same proble. When I open a generated file i have`t a empty line. Can you help me?
Sep 20, 2013 at 9:51 AM

Just must clean the buffer before settin the header part like this:

if (ob_get_contents()) ob_end_clean();
Sep 20, 2013 at 10:03 AM
Cleaning the output buffer is hiding the problem: somewhere in your script, there is still something that's generating output, whether that output is whitespace, a BOM header, an error message or whatever