0

我想在单击按钮后将报表查看器导出到 excel 文件并隐藏可用于报表查看器的现有导出工具条按钮。

下面是我的 ExportFile 函数代码:

 private void ExportFile()
    {
  SaveFileDialog saveFileDialog1 = new SaveFileDialog();
        saveFileDialog1.Filter = "*PDF files (*.pdf)|*.pdf|Excel files (*.xls)|*.xls|Doc files      (*.doc)|*.doc";
        // Variables
        Warning[] warnings;
        string[] streamids;
        string mimeType;
        string encoding;
        string extension;
        string path = " ";
        DialogResult dr = saveFileDialog1.ShowDialog();
        path = saveFileDialog1.FileName;

        byte[] bytes = reportViewerForm.reportViewer1.LocalReport.Render("Excel", null, out   mimeType, out encoding, out extension, out streamids, out warnings);

        FileStream fs = new FileStream(path + ".xls", FileMode.Create);
        fs.Write(bytes, 0, bytes.Length);
        fs.Close();}

button_click 事件的代码:

private void btnExport_Click(object sender, EventArgs e)
    {
        this.GetData();
        this.ExportFile();
    }

但是,尝试导出时出现异常错误。这是我内心的例外:

 InnerException: Microsoft.ReportingServices.ReportProcessing.ReportProcessingException
   Message=One or more parameters required to run the report have not been specified.
   Source=Microsoft.ReportViewer.Common
   ExceptionLevelHelpLink=http://go.microsoft.com/fwlink/?LinkId=20476&EvtSrc=Microsoft.ReportingServices.Diagnostics.Utilities.ErrorStrings&EvtID=rsParametersNotSpecified&ProdName=Microsoft%20SQL%20Server%20Reporting%20Services&ProdVer=1.0
   SkipTopLevelMessage=false
   StackTrace:
        at Microsoft.ReportingServices.ReportProcessing.ReportProcessing.RenderReport(IRenderingExtension newRenderer, DateTime executionTimeStamp, ProcessingContext pc, RenderingContext rc, IChunkFactory cacheDataChunkFactory, IChunkFactory yukonCompiledDefinition, Boolean& dataCached)
        at Microsoft.Reporting.LocalService.CreateSnapshotAndRender(CatalogItemContextBase itemContext, ReportProcessing repProc, IRenderingExtension renderer, ProcessingContext pc, RenderingContext rc, SubreportCallbackHandler subreportHandler, ParameterInfoCollection parameters, DatasourceCredentialsCollection credentials)
        at Microsoft.Reporting.LocalService.Render(CatalogItemContextBase itemContext, Boolean allowInternalRenderers, ParameterInfoCollection reportParameters, IEnumerable dataSources, DatasourceCredentialsCollection credentials, CreateAndRegisterStream createStreamCallback, ReportRuntimeSetup runtimeSetup)
        at Microsoft.Reporting.WinForms.LocalReport.InternalRender(String format, Boolean allowInternalRenderers, String deviceInfo, PageCountMode pageCountMode, CreateAndRegisterStream createStreamCallback, Warning[]& warnings)
   InnerException: 

我错过了什么参数?任何帮助将不胜感激。谢谢你。

4

1 回答 1

1

您尝试导出的报告是否需要报告参数?(参数快速信息:如何在报表查看器中添加参数?

我问是因为这通常是我忘记传递报告参数时得到的异常。

于 2013-04-22T22:14:01.217 回答