2008-09-26 46 views
5

獨立可執行文件是否有可能生成報告並將其輸出爲PDF(或報告查看器中可用的其他導出選項之一)而不顯示ReportViewer控件?如何在沒有服務器或UI的情況下從嵌入式報表定義生成PDF?

報告定義應嵌入可執行文件中,不應使用Reporting Services Web服務。

+0

+1我正在尋找確切的問題。我無法使用StackOverflow的搜索功能找到它,但這是Google上第一個「本地報告pdf站點:stackoverflow.com」的結果。 – flipdoubt 2008-12-01 15:48:35

回答

7

其實你不需要的ReportViewer可言,你可以直接實例化和使用LocalReport:

LocalReport report = new LocalReport(); 
report.ReportPath = "templatepath"; 
// or use file from resource with report.ReportEmbeddedResource 

// add parameters, datasource, etc. 

Warning[] warnings; 
string[] streamids; 
string mimeType; 
string encoding; 
string filenameExtension; 

byte[] bytes; 
bytes =report.Render("PDF", null, out mimeType, out encoding, out filenameExtension, out streamids, out warnings); 

// save byte[] to file with FileStream or something else 
4

您不必顯示控件本身。

ReportViewer rv = new ReportViewer(); 
rv.LocalReport.ReportPath = "templatepath"; 
// or use file from resource with rv.LocalReport.ReportEmbeddedResource 

// add parameters, datasource, etc. 

Warning[] warnings; 
string[] streamids; 
string mimeType; 
string encoding; 
string filenameExtension; 

byte[] bytes; 
bytes = rv.LocalReport.Render("PDF", null, out mimeType, out encoding, out filenameExtension, out streamids, out warnings); 

// save byte[] to file with FileStream or something else 

然而,它只能呈現PDF和XLS(因爲ReportViewer控件無法導出到Word和其他報表服務可以)。

我忘了說上面的代碼是C#,使用.NET框架和ReportViewer控件。查看GotReportViewer快速入門。

+2

爲了記錄,用於渲染爲Excel的格式是「Excel」而不是「XLS」。 – flipdoubt 2008-12-01 16:54:40

1

你能直接傳遞.rdlc報告與參數PDF?我有兩個dropdownlists,我拉我的報告。自動導出爲pdf時無法使參數生效。這是我得到的錯誤:Microsoft.ReportingServices.ReportProcessing.ReportProcessingException:運行報告所需的一個或多個參數尚未指定。

當我使用reportviewer時,dropdownlist工作,但我想跳過這一步。如果沒有任何參數,我也可以直接將數據直接導入pdf。我的dropdownlist被稱爲ddlyear和ddlmonth。

相關問題