Cannot render Excel download using SSRS SDK for PHP
I cannot render an excel file for download correctly using SSRS SDK for PHP. I can for a CSV, and I can render one for PDF inline. The contents of produced file is garbage when viewed in EXCEL. Here is my code:
$rende开发者_JAVA百科rAs = new RenderAsEXCEL();
$result = $ssrs_report->Render2($renderAs,
PageCountModeEnum::$Estimate,
$Extension,
$MimeType,
$Encoding,
$Warnings,
$StreamIds);
header("Content-Type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=\"".$reportName.".xls\";");
I've tried many different MIME Content-Type values.
A bit late but I had the same problem and it took me a while to figure it out:
There are more files that contain spaces before or after the php-tags than just the RenderAsEXCEL.php file.
Since the main php file of the SSRS library includes almost all files you need to remove all spaces before and after the php-tags from all files.
After you've done that use this code to download the Excel file.
$renderAsExcel = new RenderAsEXCEL();
$result = $ssrsServer->Render2($renderAsExcel,
PageCountModeEnum::$Estimate,
$Extension,
$MimeType,
$Encoding,
$Warnings,
$StreamIds
);
header("Content-Type: application/force-download");
header("Content-Disposition: attachment; filename=\"report.xls\"");
header("Content-length: ".(string)(strlen($result)));
header("Expires: ".gmdate("D, d M Y H:i:s", mktime(date("H")+2, date("i"),date("s"),date("m"), date("d"),date("Y")))." GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
echo $result;
i'm probably way to late but for anyone else that stumbles on this problem:
the problem is actually that there is a space in front of the first
<?php
in RenderAsEXCEL.php and there are a few lines after the last
?>
in RenderAsPDF.php remove these white spaces and you will not have to use an ugly ob_clean() workaround
I've not used that library, but i have had great results from this one: http://www.bettina-attack.de/jonny/view.php/projects/php_writeexcel/
Built it into many apps without having to think very much about it.
精彩评论