why phpexcel dont work?

Topics: Developer Forum, Project Management Forum, User Forum
Apr 15, 2009 at 2:38 PM
I can not use this library.
I followed all the instructions and enabled all extensions of php.ini, but file.xslx is not created.

The error that I have is as follows:

16:33:35 Create new PHPExcel object 16:33:35 Set properties 16:33:35 Add some data 16:33:35 Rename sheet 16:33:35 Write to Excel2007 format 16:33:35 Peak memory usage: 6 MB 16:33:35 Done writing file.

Have you advice, ideas, even the most elementary?

in reality it does not appear an error message! But the file is not created!


Developer
Apr 16, 2009 at 3:37 AM
Strange you don't get any error messages? Try to put this at the beginning of the script:

ini_set('display_errors', '1');

If this is on Linux, did you remember to set write permission on destination folder?

Apr 16, 2009 at 8:54 AM
I tried to use the script that you sent me, but I can not display any error in the video.

I wanted to tell you that I have the same problem for all "examples" of the library folder "test".

In my server using linux OS CentOS 5.3 and php is upgraded to version 5.2.

If you want to send the configuration of my php.ini?
Apr 16, 2009 at 9:37 AM
I forgot it .. Yes, I have given all permissions to the folder on the server ..
Developer
Apr 17, 2009 at 12:30 AM
Can you check if you are able to save a file from script. I know this sounds silly...

<?php
file_put_contents('test.txt', 'hello');
?>

Apr 17, 2009 at 9:14 AM
yes, the file is created correctly.
You consider that I also use other libraries like FPDF and phprtf that work well.

What other information can I provide?

Thank a lot for your attention.
Developer
Apr 18, 2009 at 2:23 AM
Is this happening only when you generate xlsx files or also for xls ? Can you try something like this:

<?php
error_reporting(E_ALL);
set_include_path(get_include_path() . PATH_SEPARATOR . '../Classes/');

include 'PHPExcel.php';
include 'PHPExcel/IOFactory.php';

$objPHPExcel = new PHPExcel();

$writer = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$writer->save('write.xls');
?>

Apr 21, 2009 at 8:33 AM
I made the changes you have reported.
 The "file.xls" is now created!
A nice step forward!
The file is saved on the server ... you can give the user the ability to save the file on computer?

Thanks
Apr 21, 2009 at 11:41 AM
Example of a script redirecting an Excel 2007 file to the client's browser:

<?php
/* Here there will be some code where you create $objPHPExcel */

// redirect output to client browser
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="myfile.xlsx"');
header('Cache-Control: max-age=0');

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

Example of a script redirecting an Excel5 file to the client's browser:

<?php
/* Here there will be some code where you create $objPHPExcel */

// redirect output to client browser
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="myfile.xls"');
header('Cache-Control: max-age=0');

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

Caution:
•    Make sure not to include any echo statements or output any other contents than the Excel file. There should be no whitespace before the opening <?php tag and at most one line break after the closing ?> tag (which can also be omitted to avoid problems).
•    Make sure that your script is saved without a BOM (Byte-order mark). (Because this counts as echoing output)
•    Same things apply to all included files

Failing to follow the above guidelines may result in corrupt Excel files arriving at the client browser, and/or that headers cannot be set by PHP (resulting in warning messages).


p.s. don't forget to read manuals before..
Apr 23, 2009 at 2:22 PM
I tried the solution that you have kindly said. 
The file.xlsx is corrupted. 
Instead the file.xls is created, but inside there are strange symbols. 
Place the following code that I tried:



<?php

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

/** Include path **/
set_include_path(get_include_path() . PATH_SEPARATOR . '../Classes/');

/** PHPExcel */
include 'PHPExcel.php';

/** PHPExcel_IOFactory */
include 'PHPExcel/IOFactory.php';

// Create new PHPExcel object
echo date('H:i:s') . " Create new PHPExcel object\n";
$objPHPExcel = new PHPExcel();

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


// Add some data
echo date('H:i:s') . " Add some data\n";
$objPHPExcel->setActiveSheetIndex(0);
$objPHPExcel->getActiveSheet()->setCellValue('A1', 'Hello');
$objPHPExcel->getActiveSheet()->setCellValue('B2', 'world!');
$objPHPExcel->getActiveSheet()->setCellValue('C1', 'Hello');
$objPHPExcel->getActiveSheet()->setCellValue('D2', 'world!');

// Rename sheet
echo date('H:i:s') . " Rename sheet\n";
$objPHPExcel->getActiveSheet()->setTitle('Simple');


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

/*
// Save Excel 2007 file
echo date('H:i:s') . " Write to Excel2007 format\n";
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save(str_replace('.php', '.xlsx', __FILE__));
*/



/*
// Echo memory peak usage
echo date('H:i:s') . " Peak memory usage: " . (memory_get_peak_usage(true) / 1024 / 1024) . " MB\r\n";

// Echo done
echo date('H:i:s') . " Done writing file.\r\n";
*/




/* Here there will be some code where you create $objPHPExcel */
// redirect output to client browser
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="myfile.xlsx"');
header('Cache-Control: max-age=0');

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('php://output'); 
?>
Apr 24, 2009 at 12:58 PM
have you read with a great attention EVERYTHING that I kindly said?

Caution:
•    Make sure not to include any echo statements or output any other contents than the Excel file. There should be no whitespace before the opening <?php tag and at most one line break after the closing ?> tag (which can also be omitted to avoid problems).

what is THIS?
echo date('H:i:s') . " Create new PHPExcel object\n";
echo date('H:i:s') . " Set properties\n";
echo date('H:i:s') . " Add some data\n";
echo date('H:i:s') . " Rename sheet\n";

What are you doing ?!?!
Apr 29, 2009 at 8:36 AM
forgive me I not had seen! 
Now, all is working so good 

Thanks a lot for the help.

I am very grateful