以编程方式导出C#reportviewer控件

时间:2009-07-06 09:57:00

标签: c# export reportviewer

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

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

3 个答案:

答案 0 :(得分:9)

您可以使用ReportViewer ControlLocalReport.Render Method)执行此操作,请在http://www.gotreportviewer.com/

上查看“通过电子邮件发送报告”示例

答案 1 :(得分: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();
    }

答案 2 :(得分:-1)

就网络表单中的reportviewer而言,您无法导出到某个活动。