|
|
@@ -9,6 +9,7 @@ using NPOI.SS.UserModel;
|
|
9
|
9
|
using NPOI.SS.Util;
|
|
10
|
10
|
using NPOI.XSSF.UserModel;
|
|
11
|
11
|
using System.Collections.Generic;
|
|
|
12
|
+using System.Linq;
|
|
12
|
13
|
|
|
13
|
14
|
namespace CallCenter.Utility
|
|
14
|
15
|
{
|
|
|
@@ -115,7 +116,8 @@ namespace CallCenter.Utility
|
|
115
|
116
|
/// <param name="Name"></param>
|
|
116
|
117
|
/// <param name="dt"></param>
|
|
117
|
118
|
/// <returns></returns>
|
|
118
|
|
- public string ExportToExcel(string Name, DataTable dt, string[] cols = null)
|
|
|
119
|
+ public string ExportToExcel(string Name, DataTable dt, string[] cols = null
|
|
|
120
|
+ ,int [] Format=null)
|
|
119
|
121
|
{
|
|
120
|
122
|
try
|
|
121
|
123
|
{
|
|
|
@@ -151,6 +153,7 @@ namespace CallCenter.Utility
|
|
151
|
153
|
ICell cell = headerRow.CreateCell(icolIndex);
|
|
152
|
154
|
cell.SetCellValue(dc.ColumnName);
|
|
153
|
155
|
cell.CellStyle = HeadercellStyle;
|
|
|
156
|
+
|
|
154
|
157
|
icolIndex++;
|
|
155
|
158
|
}
|
|
156
|
159
|
}
|
|
|
@@ -161,6 +164,7 @@ namespace CallCenter.Utility
|
|
161
|
164
|
ICell cell = headerRow.CreateCell(icolIndex);
|
|
162
|
165
|
cell.SetCellValue(dc);
|
|
163
|
166
|
cell.CellStyle = HeadercellStyle;
|
|
|
167
|
+
|
|
164
|
168
|
icolIndex++;
|
|
165
|
169
|
}
|
|
166
|
170
|
}
|
|
|
@@ -178,6 +182,17 @@ namespace CallCenter.Utility
|
|
178
|
182
|
cellfont.Boldweight = (short)FontBoldWeight.Normal;
|
|
179
|
183
|
cellStyle.SetFont(cellfont);
|
|
180
|
184
|
|
|
|
185
|
+
|
|
|
186
|
+ ICellStyle cellStyle1 = workbook.CreateCellStyle();
|
|
|
187
|
+
|
|
|
188
|
+ //为避免日期格式被Excel自动替换,所以设定 format 为 『@』 表示一率当成text來看
|
|
|
189
|
+ cellStyle1.DataFormat = HSSFDataFormat.GetBuiltinFormat("#,##0.00");
|
|
|
190
|
+ cellStyle1.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
|
|
|
191
|
+ cellStyle1.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
|
|
|
192
|
+ cellStyle1.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
|
|
|
193
|
+ cellStyle1.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
|
|
|
194
|
+ cellStyle1.SetFont(cellfont);
|
|
|
195
|
+
|
|
181
|
196
|
//建立内容行
|
|
182
|
197
|
int iRowIndex = 0;
|
|
183
|
198
|
foreach (DataRow dr in dt.Rows)
|
|
|
@@ -193,7 +208,15 @@ namespace CallCenter.Utility
|
|
193
|
208
|
}
|
|
194
|
209
|
ICell cell = irow.CreateCell(iCellIndex);
|
|
195
|
210
|
cell.SetCellValue(strsj);
|
|
196
|
|
- cell.CellStyle = cellStyle;
|
|
|
211
|
+ if (Format!=null&&Array.Exists(Format, element => element == i) )
|
|
|
212
|
+ {
|
|
|
213
|
+ cell.CellStyle = cellStyle1;
|
|
|
214
|
+ }
|
|
|
215
|
+ else
|
|
|
216
|
+ {
|
|
|
217
|
+ cell.CellStyle = cellStyle;
|
|
|
218
|
+ }
|
|
|
219
|
+
|
|
197
|
220
|
iCellIndex++;
|
|
198
|
221
|
}
|
|
199
|
222
|
iRowIndex++;
|