7

有谁知道您是否可以以编程方式保存在 C# 中的 reportviewer 控件中显示的报告?

当显示报告时,有“导出到...”按钮,我想自动保存到 PDF 功能。

4

3 回答 3

9

您可以使用ReportViewer 控件(使用LocalReport.Render 方法)执行此操作,请查看http://www.gotreportviewer.com/上的“通过电子邮件发送报告”示例

于 2009-07-06T10:05:37.130 回答
3
string _sPathFilePDF = String.Empty;
String v_mimetype;
String v_encoding;
String v_filename_extension;
String[] v_streamids;
Microsoft.Reporting.WinForms.Warning[] warnings;
string _sSuggestedName = String.Empty;

Microsoft.Reporting.WinForms.ReportViewer reportViewer1;
Microsoft.Reporting.WinForms.LocalReport objRDLC = new Microsoft.Reporting.WinForms.LocalReport();
reportViewer1.LocalReport.ReportEmbeddedResource = "reportViewer1.rdlc";
reportViewer1.LocalReport.DisplayName  = _sSuggestedName;

objRDLC.DataSources.Clear();
byte[] byteViewer = rptvFlightPlan.LocalReport.Render("PDF", null, out v_mimetype, out v_encoding, out v_filename_extension, out v_streamids, out warnings);

SaveFileDialog saveFileDialog1 = new SaveFileDialog();

saveFileDialog1.Filter = "*PDF files (*.pdf)|*.pdf";
saveFileDialog1.FilterIndex = 2;
saveFileDialog1.RestoreDirectory = true;
saveFileDialog1.FileName = _sSuggestedName;
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
    {
        FileStream newFile = new FileStream(saveFileDialog1.FileName, FileMode.Create);
        newFile.Write(byteViewer, 0, byteViewer.Length);
        newFile.Close();
    }
于 2012-05-22T17:53:04.863 回答
-1

reportviewer就Web 表单而言,您无法导出到事件。

于 2013-08-19T12:17:29.407 回答