开发者

PHPExcel problem with importing online/generated csv

I have some problem with PHPExcel where it keep throws couldn't reading (generated) file, here's the code:

include 'PHPExcel/PHPExcel.php';

$rtype = $_REQUEST['rtype'];    
// set headers to redirect output to client browser as a file download
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="report_'.$rtype.'.xls"');
header('Cache-Control: no-cache');
header('Pragma: no-cache');
header('Expires: 0');

//-----Create a reader, set some parameters and read in the file-----
$objReader = PHPExcel_IOFactory::createReader('CSV');
$objReader->setDelimiter(','); 
$objReader->setEnclosure('');
$objReader->setLineEnding("\r\n");
$objReader->setSheetIndex(0);
$objPHPExcel = $objReader->load('db_report.php?rtype='.$rtype.'&type=csv');

//-----Create a Writer a开发者_运维问答nd output the file to the browser-----
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');

already checked db_report.php and it output a csv file, so nothing wrong for this file


You try to load String value 'db_report.php?rtype='.$rtype.'&type=csv' is it not url.

Load first data ex:

$data = file_get_contents('http://domen.com/db_report.php?rtype='.$rtype.'&type=csv');
$objPHPExcel = $objReader->load($data);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜