When making an Excel file, you only need to define the template file and then fill in the data. Therefore, in order to reduce the error rate of new users and simplify development, a general base class is written to form a report, as long as the following code simply inherits the base class.
The Code is as follows: |
Copy code |
Using System; Using System. Data; Using Lee. Library. Reports. Office. Excel; Namespace Lee. Sample. Reports. Office. Excel { Public class SampleReport: BaseReport <DataSet> { 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 <string> ("ID "))); This. excel. sheets [0]. add (new WorkCell ("C" + (I + 3 ). toString (), dr. field <string> ("NAME "))); } } } } |