找回密码
 立即注册

QQ登录

只需一步,快速开始

wuliao5945

初级会员

8

主题

27

帖子

214

积分

初级会员

积分
214

[已处理] ar13导出Excel出错

wuliao5945
初级会员   /  发表于:2020-4-29 09:10  /   查看:3172  /  回复:5
我导出的代码如下,数据动态绑定的
    ''' <summary>
    ''' 导出
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    Protected Sub BtExcel_Click(sender As Object, e As EventArgs) Handles BtExcel.Click
        Dim _reportDef As New GrapeCity.ActiveReports.PageReport(New System.IO.FileInfo(Server.MapPath("ProcurementVolumeExcel.rdlx")))
        AddHandler _reportDef.Document.LocateDataSource, AddressOf Me.runtime_LocateDataSource
        'Me.WebViewer1.Report = _reportDef
        Dim _reportRuntime As New GrapeCity.ActiveReports.Document.PageDocument(_reportDef)
        Dim XlsExport1 As New GrapeCity.ActiveReports.Export.Excel.Section.XlsExport()
        Dim ms As New System.IO.MemoryStream()
        XlsExport1.FileFormat = GrapeCity.ActiveReports.Export.Excel.Section.FileFormat.Xlsx
        XlsExport1.Export(_reportRuntime, ms)
        Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
        Response.AddHeader("content-disposition", Server.UrlPathEncode("attachment;filename=" + "ProcurementVolume.xlsx"))
        Response.BinaryWrite(ms.ToArray())
        Response.End()
    End Sub
错误截图如下:

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x

5 个回复

倒序浏览
KearneyKang讲师达人认证 悬赏达人认证
超级版主   /  发表于:2020-4-29 09:19:35
沙发
你好导出Excel的代码,因为你使用的是动态数据源绑定,所以需要这样先加载动态数据源
  1. protected void Button1_Click(object sender, EventArgs e)
  2.         {
  3.             GrapeCity.ActiveReports.PageReport rpt = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(Server.MapPath(@"Reports\RDL报表.rdlx")));
复制代码

protected void Button1_Click(object sender, EventArgs e)
        {
            GrapeCity.ActiveReports.PageReport rpt = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(Server.MapPath(@"Reports\RDL报表.rdlx")));
           rpt.Document.LocateDataSource += new LocateDataSourceEventHandler(LocateData);
            GrapeCity.ActiveReports.Document.PageDocument reportDocument = new GrapeCity.ActiveReports.Document.PageDocument(rpt);

            // Provide settings for your rendering output.
            GrapeCity.ActiveReports.Export.Excel.Page.ExcelRenderingExtensionSettings excelSetting = new GrapeCity.ActiveReports.Export.Excel.Page.ExcelRenderingExtensionSettings();
            excelSetting.FileFormat = GrapeCity.ActiveReports.Export.Excel.Page.FileFormat.Xlsx;
            GrapeCity.ActiveReports.Extensibility.Rendering.ISettings setting = excelSetting;

            // Set the rendering extension and render the report.
            GrapeCity.ActiveReports.Export.Excel.Page.ExcelRenderingExtension excelRenderingExtension = new GrapeCity.ActiveReports.Export.Excel.Page.ExcelRenderingExtension();
            GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider outputProvider = new GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider();
            reportDocument.Render(excelRenderingExtension, outputProvider, setting.GetSettings());

            Response.ContentType = "application/vnd.ms-excel";
            Response.AddHeader("content-disposition", "inline;filename=MyExport.xls");
            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            //outputProvider.GetPrimaryStream().OpenStream().CopyTo(ms);
            Response.BinaryWrite(ms.ToArray());
            Response.End();

        }
回复 使用道具 举报
wuliao5945
初级会员   /  发表于:2020-4-29 13:41:39
板凳
一样的错误呀,而且加载动态数据源的代码我之前程序里已经加了
        Dim _reportDef As New GrapeCity.ActiveReports.PageReport(New System.IO.FileInfo(Server.MapPath("ProcurementVolumeExcel.rdlx")))
         AddHandler _reportDef.Document.LocateDataSource, AddressOf Me.runtime_LocateDataSource
加载事件如下:
    Sub runtime_LocateDataSource(sender As Object, args As GrapeCity.ActiveReports.LocateDataSourceEventArgs)

        If args.DataSet.Query.DataSourceName = "DataSource1" Then

            If args.DataSet.Name = "ProcurementVolume" Then

                args.Data = CreateProcurementVolume()

            End If

        End If

    End Sub
回复 使用道具 举报
KearneyKang讲师达人认证 悬赏达人认证
超级版主   /  发表于:2020-4-29 14:04:09
地板
现在具体报什么错误
回复 使用道具 举报
wuliao5945
初级会员   /  发表于:2020-4-30 09:45:31
6#
No data has been set. Please specify either a DataSet or a DataView to use
和上面截图里的一样
回复 使用道具 举报
Lenka.Guo讲师达人认证 悬赏达人认证
超级版主   /  发表于:2020-4-30 11:46:32
7#
您在打印的这个方法里面,加断点,调试下,看看有没有进这个方法,以及DataTable是否返回。
如果实在不行,建议您把示例给我们发过来,我们这边验证测试下。
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部