【问题标题】:PDF exported without ReportViewer has No Data - It is empty没有 ReportViewer 导出的 PDF 没有数据 - 它是空的
【发布时间】:2016-07-05 11:05:21
【问题描述】:

我尝试使用以下代码将Datagridview 中的数据导出到 PDF 文件:

        LocalReport report = new LocalReport();

        ReportDataSource rds1 = new ReportDataSource(dt.TableName, dt);

        report.ReportPath = @"D:\Report1.rdlc";
                   report.DataSources.Add(rds1);

        byte[] data = report.Render("PDF");

        using (FileStream fs = File.Create(@"D:\output.pdf"))
        {               
            fs.Write(data,0, data.Length);
        }

数据表 'dt' 具有带值的行和列。

我没有对Report1.rdlc 做任何事。刚刚将其添加到项目中。

输出的 pdf 文件没有显示任何值。这只是一个空白页。

我在这里错过了什么?

【问题讨论】:

    标签: c# datagridview pdf-generation rdlc


    【解决方案1】:

    我过去也遇到过类似的问题。我通过使用动态创建的报表查看器解决了这个问题,它嵌入了LocalReport

    using (WinForms.ReportViewer reportViewer = new WinForms.ReportViewer()) {
        reportViewer.LocalReport.ReportPath = @"D:\Report1.rdlc";
    
        ReportDataSource rds1 = new ReportDataSource(dt.TableName, dt);
        reportViewer.LocalReport.DataSources.Add(rds1);
    
        reportViewer.refreshReport();
    
        byte[] data = reportViewer.LocalReport.Render("PDF");
    
        using (FileStream fs = File.Create(@"D:\output.pdf"))
        {               
            fs.Write(data,0, data.Length);
        }
    }
    

    注意:代码未经测试,但它或多或少是我所做的并且效果很好。

    【讨论】:

    • 没有朋友。它仍然是一样的。输出 pdf 只有 1KB,没有数据。 :(
    猜你喜欢
    • 1970-01-01
    • 2013-07-03
    • 1970-01-01
    • 1970-01-01
    • 2011-08-16
    • 2010-12-02
    • 1970-01-01
    • 2012-10-08
    • 1970-01-01
    相关资源
    最近更新 更多