在ReportView
我希望导出以下格式:.docx,.pdf或.xlsx
导出到.pdf:
reportViewer.ExportDialog(_reportViewer.LocalReport.ListRenderingExtensions()[3]);
导出到.docx:
reportViewer.ExportDialog(_reportViewer.LocalReport.ListRenderingExtensions()[5]);
导出到.xlsx:
reportViewer.ExportDialog(_reportViewer.LocalReport.ListRenderingExtensions()[1]);
但首先我必须选择一种保存格式。 我想首先打开 SaveFileDialog 并在其中选择保存格式
我该怎么做?
答案 0 :(得分:1)
这是我提出的代码:
string _sSuggestedName = String.Empty;
byte[] byteViewerPDF = _reportViewer.LocalReport.Render("PDF");
byte[] byteViewerExcel = _reportViewer.LocalReport.Render("Excel");
byte[] byteViewerWord = _reportViewer.LocalReport.Render("Word");
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.Filter = "PDF files (*.pdf)|*.pdf| Doc files
(*.doc)|*.doc| Excel files (*.xls)|*.xls";
if (saveFileDialog1.ShowDialog() == DialogResult.Ok)
{
FileStream newFile = new FileStream(saveFileDialog1.FileName, FileMode.Create);
if (saveFileDialog1.FilterIndex == 1)
{
newFile.Write(byteViewerPDF, 0, byteViewerPDF.Length);
newFile.Close();
}
else
if (saveFileDialog1.FilterIndex == 2)
{
newFile.Write(byteViewerWord, 0, byteViewerWord.Length);
newFile.Close();
}
else
if (saveFileDialog1.FilterIndex == 3)
{
newFile.Write(byteViewerExcel, 0, byteViewerExcel.Length);
newFile.Close();
}
}