【问题标题】:Custom export reportviewer to excel file自定义导出reportviewer到excel文件
【发布时间】:2013-04-23 06:14:01
【问题描述】:

我想在单击按钮后将报表查看器导出为 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: 

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

【问题讨论】:

    标签: c# sql reportviewer


    【解决方案1】:

    您尝试导出的报告是否需要报告参数? (参数快速信息:how to add parameters in report viewer?

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

    【讨论】:

    • 是的,我在标题上有一些参数。如何传递报表参数。
    猜你喜欢
    • 2020-08-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-01
    相关资源
    最近更新 更多