一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

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

时间:2022-06-25 06:03:06 编辑:袖梨 来源:一聚教程网

 代码如下 复制代码

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")));
             }
         }
     }
 }

热门栏目