1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingSystem.Web;5 usingSystem.Web.UI.WebControls;6 usingSystem.Web.UI;7 usingSystem.Data;8 usingSystem.Text;9 usingSystem.Globalization;10 usingSystem.IO;11
12 namespaceVMS.Test.Classes13 {14 public classExcelHelper {15
16 #region Fields
17
18 string_fileName;19 DataTable _dataSource;20 string[] _titles = null;21 string[] _fields = null;22 int _maxRecords = 1000;23
24 #endregion
25
26 #region Properties
27
28 /**
29 ///限制输出到 Excel 的最大记录数。超出则抛出异常30 ///
31 public intMaxRecords {32 set { _maxRecords =value; }33 get { return_maxRecords; }34 }35
36 /**
37 ///输出到浏览器的 Excel 文件名38 ///
39 public stringFileName {40 set { _fileName =value; }41 get { return_fileName; }42 }43
44 #endregion
45
46 #region .ctor
47
48 /**
49 ///构造函数50 ///
51 /// 要输出到 Excel 的列标题的数组
52 /// 要输出到 Excel 的字段名称数组
53 /// 数据源
54 public ExcelHelper(string[] titles, string[] fields, DataTable dataSource): this(titles, dataSource) {55 if (fields == null || fields.Length == 0)56 throw new ArgumentNullException("fields");57
58 if (titles.Length !=fields.Length)59