Asp.net 如何将本地报告导出为pdf和excel文件?

Asp.net 如何将本地报告导出为pdf和excel文件?,asp.net,rdlc,Asp.net,Rdlc,我有两个网页,page1.aspx和page2.aspx。在第1页,有一个按钮;在第2页中,有一个本地报告(rdlc)。当我点击按钮时,它将显示第2页,并将报告导出为pdf和excel文件。如果报告是Crystal report,则在第2页的页面加载中,我可以调用函数ExportToDisk(ExportFormatType,FileName)将报告导出为pdf/excel。但现在我正在使用本地报告(rdlc),我想知道如何将其导出为pdf/excel。 // ///参考资料: /// 私有v

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

//
///参考资料:
/// 
私有void RenderReport(){
LocalReport LocalReport=新建LocalReport();
localReport.ReportPath=Server.MapPath(“~/Report.rdlc”);
//为报表返回集合的方法
//注意:报表可以有多个数据源
List employeeCollection=GetData();
//为集合指定一个名称(EmployeeCollection),以便我们可以在报表设计器中引用它
ReportDataSource ReportDataSource=新的ReportDataSource(“EmployeeCollection”,EmployeeCollection);
localReport.DataSources.Add(reportDataSource);
string reportType=“PDF”;
字符串模拟类型;
字符串编码;
字符串文件名扩展名;
//应根据报告类型更改DeviceInfo设置
//http://msdn2.microsoft.com/en-us/library/ms155397.aspx
字符串设备信息=
"" +
“PDF”+
“8.5英寸”+
“11英寸”+
“0.5英寸”+
“1英寸”+
“1英寸”+
“0.5英寸”+
"";
警告[]警告;
字符串[]流;
字节[]渲染字节;
//提交报告
renderedBytes=localReport.Render(
报告类型,
deviceInfo,
输出mimeType,
输出编码,
输出文件名扩展名,
流出的溪流,
发出警告);
//清除响应流并将字节写入outputstream
//将内容处置设置为“附件”,以便提示用户采取操作
//在文件上(打开或保存)
Response.Clear();
Response.ContentType=mimeType;
AddHeader(“内容处置”、“附件;文件名=foo.”+文件名扩展名);
BinaryWrite(renderBytes);
Response.End();
}

28002E00\u rdlc\u 2900-直接到-响应-流-不带预览找不到抱歉,我正试图记住这是哪项合同工作,甚至是在。。。我没有内存问题,但这取决于数据。
/// <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();

}