Problem using database configuration

Topics: Developer Forum, User Forum
Nov 29, 2011 at 11:58 AM

First of all, thanks you for your work, is perfect.
I'm trying to test the example of 01simple-download-xls.php, and it work's but when I try to include the configuration file of the database that it has the server user and password, the example doesn't work because the output .xls file is corrupt.
I will be very glad if someone can help me.
Thank you

<?php

// I have only added this line
require 'conf/configBD.inc';


/** Error reporting */
error_reporting(E_ALL);

date_default_timezone_set('Europe/London');

/** PHPExcel */
require_once '../Classes/PHPExcel.php';


// Create new PHPExcel object
$objPHPExcel = new PHPExcel();

// Set properties
$objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
							 ->setLastModifiedBy("Maarten Balliauw")
							 ->setTitle("Office 2007 XLSX Test Document")
							 ->setSubject("Office 2007 XLSX Test Document")
							 ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
							 ->setKeywords("office 2007 openxml php")
							 ->setCategory("Test result file");


// Add some data
$objPHPExcel->setActiveSheetIndex(0)
            ->setCellValue('A1', 'Hello')
            ->setCellValue('B2', 'world!')
            ->setCellValue('C1', 'Hello')
            ->setCellValue('D2', 'world!');

// Miscellaneous glyphs, UTF-8
$objPHPExcel->setActiveSheetIndex(0)
            ->setCellValue('A4', 'Miscellaneous glyphs')
            ->setCellValue('A5', '�����������������');

// Rename sheet
$objPHPExcel->getActiveSheet()->setTitle('Simple');


// Set active sheet index to the first sheet, so Excel opens this as the first sheet
$objPHPExcel->setActiveSheetIndex(0);


// Redirect output to a client�s web browser (Excel5)
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="01simple.xls"');
header('Cache-Control: max-age=0');

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');
exit;

I have only added this line:

require 'conf/configBD.inc';

That file has this information
<?php
  	define ( 'serverName', '192.xx.x.xx\cco' );
	define ( 'serverUser', 'user' );
	define ( 'serverPassword', 'password' );
	define ( 'Database', 'database' );

?> 
Nov 29, 2011 at 12:58 PM

Hi,

 

i'm guessing that either yoru have some white space in your db config, or perhaps a notice somewhere, caused by the error reporting.

 

 

Nov 29, 2011 at 1:18 PM
borft wrote:

Hi,

 

i'm guessing that either yoru have some white space in your db config, or perhaps a notice somewhere, caused by the error reporting.

 

 

Hi borft

Thank you for your response. I did that you say, I deleted the white space and deleted the error reporthing and doesn't work :( . How i can know if error reporting is writing some notice?

Nov 29, 2011 at 1:35 PM

try unzipping the generated .xlsx file. If that doesn't work, try opening the .xlsx file in a text editor and look for notices.

 

Another option is to save the output to a different file (for example /tmp/test.xlsx in stead of php://stdout). That way the notices/warnings/errors will be sent to stdout, but the xlsx output will be written to file.

Nov 29, 2011 at 2:02 PM
borft wrote:

try unzipping the generated .xlsx file. If that doesn't work, try opening the .xlsx file in a text editor and look for notices.

 

Another option is to save the output to a different file (for example /tmp/test.xlsx in stead of php://stdout). That way the notices/warnings/errors will be sent to stdout, but the xlsx output will be written to file.

I tried to find some notice in the file an didn´t find, so I change this:

$objWriter->save('php://output');

For this:

$objWriter->save('php://stdout');

And the output .xls are empty.

Then I changed for this:

$objWriter->save('/tmp/test.xlsx');

And the output .xls has this notice:

<b>Fatal error</b>:  Uncaught exception 'Exception' with message 'Can't open /tmp/test.xlsx. It may be in use or protected.' in C:\Guarita\LoginPrincipal\servicios\1.7.6\Classes\PHPExcel\Shared\OLE\PPS\Root.php:91

Stack trace:

#0 C:\Guarita\LoginPrincipal\servicios\1.7.6\Classes\PHPExcel\Writer\Excel5.php(185): PHPExcel_Shared_OLE_PPS_Root-&gt;save('/tmp/test.xlsx')

#1 C:\Guarita\LoginPrincipal\gerarRelatorioVeiculos.php(55): PHPExcel_Writer_Excel5-&gt;save('/tmp/test.xlsx')

#2 {main}

  thrown in <b>C:\Guarita\LoginPrincipal\servicios\1.7.6\Classes\PHPExcel\Shared\OLE\PPS\Root.php</b> on line <b>91</b><br />

 

Thank you for your responses