asp.net将数据导出为Excel报表

作者:袖梨 2022-06-25
 代码如下 复制代码

using System;
 using System.Data;
 using Lee.Library.Reports.Office.Excel;
 
 namespace Lee.Sample.Reports.Office.Excel
 {
     public class SampleReport : BaseReport
     {
         public SampleReport(DataSet ds) : base(ds) { }
 
         protected override void InitReport()
         {
             this.ReportName = @"UserInfo";
             this.ReportSavePath = AppDomain.CurrentDomain.BaseDirectory + @"ReportsOfficeExcel";
             this.Excel = new WorkBook(AppDomain.CurrentDomain.BaseDirectory + @"ReportsOfficeExcelUserInfo.xls", "UserInfo");
             this.Excel.Sheets.Add(new WorkSheet("MyUserInfo"));
             for (int i = 0; i < this.DataSource.Tables[0].Rows.Count; i++)
             {
                 DataRow dr = this.DataSource.Tables[0].Rows[i];
                 this.Excel.Sheets[0].Add(new WorkCell("B" + (i + 3).ToString(), dr.Field("ID")));
                 this.Excel.Sheets[0].Add(new WorkCell("C" + (i + 3).ToString(), dr.Field("NAME")));
             }
         }
     }
 }

相关文章

精彩推荐