【问题标题】:how to export a local report to a pdf and excel file?如何将本地报告导出为 pdf 和 excel 文件?
【发布时间】:2012-11-08 17:41:01
【问题描述】:

我有两个网页,page1.aspx 和 page2.aspx。在page1中,有一个按钮;在第 2 页中,有一个本地报告 (rdlc)。当我点击按钮时,它会弹出 page2,并将报告导出为 pdf 和 excel 文件。如果报表是水晶报表,在page2的page_load中,我可以调用函数ExportToDisk(ExportFormatType, FileName)将报表导出为pdf/excel。但是现在我使用的是本地报告(rdlc),我想知道如何将其导出为 pdf/excel。

【问题讨论】:

    标签: asp.net rdlc


    【解决方案1】:

    http://weblogs.asp.net/rajbk/archive/2006/03/02/How-to-render-client-report-definition-files-_28002E00_rdlc_2900_-directly-to-the-Response-stream-without-preview.aspx

    /// <summary>
    /// References:
    /// </summary>
    private void RenderReport() {
        LocalReport localReport = new LocalReport();
        localReport.ReportPath = Server.MapPath("~/Report.rdlc"); 
    
        //A method that returns a collection for our report
        //Note: A report can have multiple data sources
        List<Employee> employeeCollection = GetData();
    
        //Give the collection a name (EmployeeCollection) so that we can reference it in our report designer
        ReportDataSource reportDataSource = new ReportDataSource("EmployeeCollection", employeeCollection);
        localReport.DataSources.Add(reportDataSource);
    
        string reportType = "PDF";
        string mimeType;
        string encoding;
        string fileNameExtension;
    
        //The DeviceInfo settings should be changed based on the reportType
        //http://msdn2.microsoft.com/en-us/library/ms155397.aspx
        string deviceInfo =
        "<DeviceInfo>" +
        "  <OutputFormat>PDF</OutputFormat>" +
        "  <PageWidth>8.5in</PageWidth>" +
        "  <PageHeight>11in</PageHeight>" +
        "  <MarginTop>0.5in</MarginTop>" +
        "  <MarginLeft>1in</MarginLeft>" +
        "  <MarginRight>1in</MarginRight>" +
        "  <MarginBottom>0.5in</MarginBottom>" +
        "</DeviceInfo>";
    
        Warning[] warnings;
        string[] streams;
        byte[] renderedBytes;
    
        //Render the report
        renderedBytes = localReport.Render(
            reportType,
            deviceInfo,
            out mimeType,
            out encoding,
            out fileNameExtension,
            out streams,
            out warnings);
    
        //Clear the response stream and write the bytes to the outputstream
        //Set content-disposition to "attachment" so that user is prompted to take an action
        //on the file (open or save)
        Response.Clear();
        Response.ContentType = mimeType;
        Response.AddHeader("content-disposition", "attachment; filename=foo." + fileNameExtension);
        Response.BinaryWrite(renderedBytes);
        Response.End();
    
    }
    

    【讨论】:

    • weblogs.asp.net/rajbk/…28002E00_rdlc_2900-directly-to-the-Response-stream-without-preview 未找到
    • 抱歉,我正在努力记住这是什么合同工作......我没有记忆问题,但这取决于数据。
    猜你喜欢
    • 2017-05-27
    • 1970-01-01
    • 1970-01-01
    • 2016-07-18
    • 2014-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多