0
所以我真的可以使用線索來解釋爲什麼會發生這種情況以及如何解決它。我試着用下面發現代碼中的水晶報表導出爲PDF格式:嘗試導出到pdf時解析器錯誤異常
protected void ExportRptButton_Click(object sender, EventArgs e)
{
Datamart.UI.Reporting.Web.ReportParamsSvc.ReportDefinition rptCfg = SelectedReport;
if (null != SelectedReport)
{
rptParams.Clear();
rptParams = null;
// Get the report document
// string filePath = Server.MapPath(@"~\Reports\" + SelectedReport.FileName + ".rpt");
// Declare a new Crystal Report Document object and load the report file into the report document.
ReportDocument rptDoc = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
ConfigureCrystalReports(rptDoc);
// repDoc.Load(rptFileName);
// AddParameters();
// Set the report parameters the report object.
//LoadReportParameterValues(SelectedReport);
LoadParameterFields(rptDoc);
// Set the static text fields in the report object.
LoadStaticTextFields(rptDoc);
try
{
if (rptDoc.IsLoaded)
{
// Stop buffering the response
Response.Buffer = false;
// Clear the response content and headers
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/pdf";
// Export the Report to Response stream in PDF format and file name Customers
rptDoc.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, true, "DirectAccessReport");
// Response.Filter.Flush();
// Response.Flush();
// rptDoc.ExportToDisk(ExportFormatType.PortableDocFormat, "~/PDF_Folder");
// There are other format options available such as Word, Excel, CVS, and HTML in the ExportFormatType Enum given by crystal reports
}
}
catch (System.Threading.ThreadAbortException ex)
{
logger.ErrorFormat("Could not export to pdf: threading! {0}", ex);
}
catch (Exception ex)
{
logger.ErrorFormat("Could not export to pdf! {0}", ex);
}
}
}
的「ConfigureCrystalReports」剛剛得到報告的文件路徑。
「LoadParameterFields」填充報表的參數,我非常肯定它的工作原理,因爲它與在CRViewer中打開報表時使用相同的代碼來填充參數。但如果你想看看它做了什麼,那麼讓我知道,我會添加它。
對於「LoadStaticTextFields」也是如此,它只是獲取報表中標籤的文本值。
我收到錯誤可以在下面的IMG發現:
我最好的猜測,問題出在哪裏發生在嘗試循環。正如你所看到的,我已經用大多數註釋掉的代碼的Response字段嘗試了幾種不同的方法。
我花了很多時間尋找這個答案,大多數人說我必須從我的代碼中刪除所有的Response.Write()調用,但是我沒有使用Response.Write( )我的代碼中的任何地方。
任何幫助或建議,非常感謝。謝謝。
我試過你的建議,但它仍然拋出一個解析器錯誤。 – James213 2012-07-26 14:08:47