2013-02-19 94 views
1

ReportView我想導出.docx .pdf .xlsx。c#ReportViewer導出

例: 我可以導出到PDF:

_reportViewer.ExportDialog(_reportViewer.LocalReport.ListRenderingExtensions()[3]);

爲.docx:

_reportViewer.ExportDialog(_reportViewer.LocalReport.ListRenderingExtensions()[5]);

爲原來的.xlsx:

_reportViewer.ExportDialog(_reportViewer.LocalReport.ListRenderingExtensions()[1]);

但是起初我必須選擇一種保存格式。 我想先打開SaveFileDialog並在其中選擇一種保存格式 我該怎麼辦?

回答

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文件(.PDF)| .PDF | DOC文件 (.DOC)| .DOC | Excel文件(.xls的)|的.xls」;

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

     }