1

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并在其中选择一种保存格式

我该怎么做 ?

4

1 回答 1

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

}
于 2013-02-19T09:29:30.140 回答