2009-07-06 25 views
7

Có ai biết nếu bạn có thể lưu một báo cáo theo chương trình được hiển thị trong điều khiển trình kiểm tra báo cáo trong C# không?Xuất khẩu C# reportviewer kiểm soát lập trình

Khi báo cáo được hiển thị, có các nút "Xuất sang ..." và tôi muốn tự động hóa chức năng lưu thành PDF.

Trả lời

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(); 
    } 
+0

Cảm ơn rất nhiều. Điều đó làm việc cho tôi. Tôi rất biết ơn :) Tôi thậm chí không biết rằng những thứ như vậy có thể được thực hiện, tôi đã cố gắng yêu cầu trang báo cáo và hack mã HTML/JS kết quả bên trong :) – Rowan

0

Bạn không thể xuất khẩu sang một sự kiện như xa như reportviewer trong các hình thức web có liên quan.

Các vấn đề liên quan