简体   繁体   中英

PHPEXCEL export file is not working after session handler class

index.php contains

 .......
require_once('WABRegistry/helpers/Session_Handler.php');
session_start();
 .......

then i use PHPEXCEL:

$objPHPExcel->setActiveSheetIndex(0);

// Save Excel 2007 file
header('Content-type: application/vnd.ms-excel');
header('Content-Disposition: attachment; filename="polls_results_'.time().'.xlsx"');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->setIncludeCharts(TRUE); //First Sheet Chart
$objWriter->save('php://output');          

i can see the following error message

PROBLEM: and when i try to open the file it give me error on mac:

Excel cannot open this file
the file format or file extension is not valid. bla bla 

if i comment //require_once('WABRegistry/helpers/Session_Handler.php'); line it works fine

Session_Handler.php contains lots of code here is short, if required i will paste all

$session = new sessionHandle();
session_set_save_handler(array(&$session,"open"),
                         array(&$session,"close"),
                         array(&$session,"read"),
                         array(&$session,"write"),
                         array(&$session,"destroy"),
                         array(&$session,"gc"));

Open the Excel file in a text editor, and look for any leading or trailing whitespace characters, or a leading BOM header, or any obvious plaintext error messages that yoru session handler might be injecting into the output stream

The most common cause of this problem is whitespace that's echoed to output (perhaps after a closing ?> ).

Using output buffering, and then discarding the buffer immediately before the call to save() is a common workround; but better to fix the problem rather than simply hiding it with output buffering. You'll notice that none of the PHPExcel code has any closing ?> to ensure that it's impossible for the library itself to cause this problem

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM