|
|
@@ -961,7 +961,7 @@ namespace CallCenter.Utility
|
|
961
|
961
|
if (Factory3 != null)
|
|
962
|
962
|
productcode = Factory3.Count;
|
|
963
|
963
|
bool istrue = true; int a = 0, total = problem + productcode;
|
|
964
|
|
- if (factory>(total))
|
|
|
964
|
+ if (factory>total)
|
|
965
|
965
|
{
|
|
966
|
966
|
count = factory;
|
|
967
|
967
|
a = factory - total;
|
|
|
@@ -977,6 +977,7 @@ namespace CallCenter.Utility
|
|
977
|
977
|
cell7.CellStyle = cellStylebt;
|
|
978
|
978
|
cell7.CellStyle.WrapText=true ;
|
|
979
|
979
|
sheet.AddMergedRegion(new CellRangeAddress(t+1, t+ count, 0, 0));
|
|
|
980
|
+ SetMergedRegionBorders(sheet, new CellRangeAddress(t + 1, t + count, 0, 0), workbook);
|
|
980
|
981
|
ICell cell10 = irow5.CreateCell(7);
|
|
981
|
982
|
cell10.SetCellValue("各\n质\n量\n问\n题\n占\n比\n");
|
|
982
|
983
|
cell10.CellStyle = cellStylebt;
|
|
|
@@ -987,36 +988,35 @@ namespace CallCenter.Utility
|
|
987
|
988
|
if (a >1)
|
|
988
|
989
|
{
|
|
989
|
990
|
structure = t + problem + a / 2;
|
|
990
|
|
- sheet.AddMergedRegion(new CellRangeAddress(t+1, t + problem + a / 2, 7, 7));
|
|
|
991
|
+ sheet.AddMergedRegion(new CellRangeAddress(t+1, structure, 7, 7));
|
|
|
992
|
+
|
|
991
|
993
|
}
|
|
992
|
994
|
|
|
993
|
995
|
else
|
|
994
|
996
|
{
|
|
995
|
997
|
structure = t + problem;
|
|
996
|
|
- sheet.AddMergedRegion(new CellRangeAddress(t+1, t + problem, 7, 7));
|
|
|
998
|
+ sheet.AddMergedRegion(new CellRangeAddress(t+1, structure, 7, 7));
|
|
|
999
|
+
|
|
997
|
1000
|
}
|
|
998
|
1001
|
}
|
|
999
|
|
- else
|
|
1000
|
|
- sheet.AddMergedRegion(new CellRangeAddress(t+1, t + problem, 7, 7));
|
|
|
1002
|
+ else
|
|
|
1003
|
+ {
|
|
|
1004
|
+ sheet.AddMergedRegion(new CellRangeAddress(t + 1, structure, 7, 7));
|
|
|
1005
|
+
|
|
|
1006
|
+ }
|
|
|
1007
|
+
|
|
1001
|
1008
|
IRow irow7 = sheet.CreateRow(structure+1);
|
|
1002
|
1009
|
ICell cell11 = irow7.CreateCell(7);
|
|
1003
|
1010
|
cell11.SetCellValue("结\n构\n占\n比\n");
|
|
1004
|
1011
|
cell11.CellStyle = cellStylebt;
|
|
1005
|
1012
|
cell11.CellStyle.WrapText = true;
|
|
1006
|
|
- if (istrue)
|
|
1007
|
|
- {
|
|
1008
|
|
- if (a > 1)
|
|
1009
|
|
- sheet.AddMergedRegion(new CellRangeAddress(structure + 1, structure+ productcode+a/2, 7, 7));
|
|
1010
|
|
- else
|
|
1011
|
|
- sheet.AddMergedRegion(new CellRangeAddress(structure + 1, structure + productcode+a, 7, 7));
|
|
1012
|
|
- }
|
|
1013
|
|
- else
|
|
1014
|
|
- sheet.AddMergedRegion(new CellRangeAddress(structure + 1, structure + productcode, 7, 7));
|
|
|
1013
|
+ sheet.AddMergedRegion(new CellRangeAddress(structure + 1, t + count, 7, 7));
|
|
|
1014
|
+ int index = 0;
|
|
1015
|
1015
|
if (Factory1 != null)
|
|
1016
|
1016
|
{
|
|
1017
|
1017
|
for (int i = 0; i < count; i++)
|
|
1018
|
1018
|
{
|
|
1019
|
|
- if (i ==0 || t + i== structure)
|
|
|
1019
|
+ if (i ==0 || t +1+ i== structure+1)
|
|
1020
|
1020
|
{
|
|
1021
|
1021
|
if (Factory1.Count > i*2)
|
|
1022
|
1022
|
{
|
|
|
@@ -1097,6 +1097,7 @@ namespace CallCenter.Utility
|
|
1097
|
1097
|
}
|
|
1098
|
1098
|
|
|
1099
|
1099
|
}
|
|
|
1100
|
+ index++;
|
|
1100
|
1101
|
}
|
|
1101
|
1102
|
|
|
1102
|
1103
|
}
|
|
|
@@ -1186,7 +1187,7 @@ namespace CallCenter.Utility
|
|
1186
|
1187
|
ICell cell8 = irow6.CreateCell(8);
|
|
1187
|
1188
|
cell8.SetCellValue(Factory2[i].name);
|
|
1188
|
1189
|
cell8.CellStyle = cellStylebt;
|
|
1189
|
|
- sheet.AddMergedRegion(new CellRangeAddress(t +1+ i, t+1 + i+b , 8, 9));
|
|
|
1190
|
+ sheet.AddMergedRegion(new CellRangeAddress(t +1+ i, structure, 8, 9));
|
|
1190
|
1191
|
if (istrue )
|
|
1191
|
1192
|
{
|
|
1192
|
1193
|
ICell cell22 = irow6.CreateCell(9);
|
|
|
@@ -1197,20 +1198,20 @@ namespace CallCenter.Utility
|
|
1197
|
1198
|
ICell cell9 = irow6.CreateCell(10);
|
|
1198
|
1199
|
cell9.SetCellValue(Factory2[i].number.ToString());
|
|
1199
|
1200
|
cell9.CellStyle = cellStylebt;
|
|
1200
|
|
- sheet.AddMergedRegion(new CellRangeAddress(t+1 + i, t+1 + i + b, 10, 10));
|
|
|
1201
|
+ sheet.AddMergedRegion(new CellRangeAddress(t+1 + i, structure, 10, 10));
|
|
1201
|
1202
|
|
|
1202
|
1203
|
break;
|
|
1203
|
1204
|
case 2:
|
|
1204
|
1205
|
ICell cell12 = irow6.CreateCell(11);
|
|
1205
|
1206
|
cell12.SetCellValue(Factory2[i].proportion);
|
|
1206
|
1207
|
cell12.CellStyle = cellStylebt;
|
|
1207
|
|
- sheet.AddMergedRegion(new CellRangeAddress(t+1 + i, t+1 + i + b, 11, 11));
|
|
|
1208
|
+ sheet.AddMergedRegion(new CellRangeAddress(t+1 + i, structure, 11, 11));
|
|
1208
|
1209
|
break;
|
|
1209
|
1210
|
}
|
|
1210
|
1211
|
|
|
1211
|
1212
|
}
|
|
1212
|
1213
|
}
|
|
1213
|
|
- if (i <( Factory3.Count + Factory2.Count+b -1)&& i>= Factory2.Count + b)
|
|
|
1214
|
+ if (t +1+ i>structure + 1&& t + 1 + i < structure+ Factory3.Count)
|
|
1214
|
1215
|
{
|
|
1215
|
1216
|
for (int z = 0; z < 3; z++)
|
|
1216
|
1217
|
{
|
|
|
@@ -1219,28 +1220,28 @@ namespace CallCenter.Utility
|
|
1219
|
1220
|
{
|
|
1220
|
1221
|
case 0:
|
|
1221
|
1222
|
ICell cell8 = irow6.CreateCell(8);
|
|
1222
|
|
- cell8.SetCellValue(Factory3[i- Factory2.Count -b ].name);
|
|
1223
|
|
-
|
|
|
1223
|
+ cell8.SetCellValue(Factory3[index].name);
|
|
1224
|
1224
|
cell8.CellStyle = cellStylebt;
|
|
1225
|
|
- sheet.AddMergedRegion(new CellRangeAddress(t +1+ i, t +1+ i, 8, 9));
|
|
|
1225
|
+ sheet.AddMergedRegion(new CellRangeAddress(t+1+i, t + 1 + i, 8, 9));
|
|
1226
|
1226
|
ICell cel27 = irow6.CreateCell(9);
|
|
1227
|
1227
|
cel27.CellStyle = cellStylebt;
|
|
1228
|
1228
|
break;
|
|
1229
|
1229
|
case 1:
|
|
1230
|
1230
|
ICell cell9 = irow6.CreateCell(10);
|
|
1231
|
|
- cell9.SetCellValue(Factory3[i - Factory2.Count - b ].number.ToString());
|
|
|
1231
|
+ cell9.SetCellValue(Factory3[index].number.ToString());
|
|
1232
|
1232
|
cell9.CellStyle = cellStylebt;
|
|
1233
|
1233
|
|
|
1234
|
1234
|
break;
|
|
1235
|
1235
|
case 2:
|
|
1236
|
1236
|
ICell cell12 = irow6.CreateCell(11);
|
|
1237
|
|
- cell12.SetCellValue(Factory3[i - Factory2.Count - b ].proportion);
|
|
|
1237
|
+ cell12.SetCellValue(Factory3[index].proportion);
|
|
1238
|
1238
|
cell12.CellStyle = cellStylebt;
|
|
1239
|
1239
|
break;
|
|
1240
|
1240
|
}
|
|
1241
|
1241
|
}
|
|
|
1242
|
+ index++;
|
|
1242
|
1243
|
}
|
|
1243
|
|
- else if ( i== Factory2.Count + b+ Factory3.Count-1 )
|
|
|
1244
|
+ else if (t + 1 + i == structure + Factory3.Count)
|
|
1244
|
1245
|
{
|
|
1245
|
1246
|
for (int z = 0; z < 3; z++)
|
|
1246
|
1247
|
{
|
|
|
@@ -1248,26 +1249,29 @@ namespace CallCenter.Utility
|
|
1248
|
1249
|
{
|
|
1249
|
1250
|
case 0:
|
|
1250
|
1251
|
ICell cell8 = irow6.CreateCell(8);
|
|
1251
|
|
- cell8.SetCellValue(Factory3[i - Factory2.Count - b].name);
|
|
|
1252
|
+ cell8.SetCellValue(Factory3[index].name);
|
|
1252
|
1253
|
cell8.CellStyle = cellStylebt;
|
|
1253
|
1254
|
|
|
1254
|
|
- sheet.AddMergedRegion(new CellRangeAddress(t +1+ i, t+1 + i + b, 8, 9));
|
|
1255
|
|
- break;
|
|
|
1255
|
+ sheet.AddMergedRegion(new CellRangeAddress(t + 1 + i, t + count, 8, 9));
|
|
|
1256
|
+ SetMergedRegionBorders(sheet, new CellRangeAddress(t + 1 + i, t + 1 + i, 8, 9), workbook);
|
|
|
1257
|
+ break;
|
|
1256
|
1258
|
case 1:
|
|
1257
|
1259
|
ICell cell9 = irow6.CreateCell(10);
|
|
1258
|
|
- cell9.SetCellValue(Factory3[i - Factory2.Count - b].number.ToString());
|
|
|
1260
|
+ cell9.SetCellValue(Factory3[index].number.ToString());
|
|
1259
|
1261
|
cell9.CellStyle = cellStylebt;
|
|
1260
|
1262
|
|
|
1261
|
|
- sheet.AddMergedRegion(new CellRangeAddress(t + 1 + i, t + 1 + i + b, 10, 10));
|
|
|
1263
|
+ sheet.AddMergedRegion(new CellRangeAddress(t + 1 + i, t + count, 10, 10));
|
|
|
1264
|
+ SetMergedRegionBorders(sheet, new CellRangeAddress(t + 1 + i, t + 1 + i, 10, 10), workbook);
|
|
|
1265
|
+ break;
|
|
1262
|
1266
|
|
|
1263
|
|
- break;
|
|
1264
|
|
- case 2:
|
|
|
1267
|
+ case 2:
|
|
1265
|
1268
|
ICell cell12 = irow6.CreateCell(11);
|
|
1266
|
|
- cell12.SetCellValue(Factory3[i - Factory2.Count - b].proportion);
|
|
|
1269
|
+ cell12.SetCellValue(Factory3[index].proportion);
|
|
1267
|
1270
|
cell12.CellStyle = cellStylebt;
|
|
1268
|
1271
|
|
|
1269
|
|
- sheet.AddMergedRegion(new CellRangeAddress(t + 1 + i, t + 1 + i + b, 11, 11));
|
|
1270
|
|
- break;
|
|
|
1272
|
+ sheet.AddMergedRegion(new CellRangeAddress(t + 1 + i, t + count, 11, 11));
|
|
|
1273
|
+ SetMergedRegionBorders(sheet, new CellRangeAddress(t + 1 + i, t + 1 + i, 11, 11), workbook);
|
|
|
1274
|
+ break;
|
|
1271
|
1275
|
}
|
|
1272
|
1276
|
}
|
|
1273
|
1277
|
}
|
|
|
@@ -1334,6 +1338,11 @@ namespace CallCenter.Utility
|
|
1334
|
1338
|
ICell cell124 = irow6.CreateCell(6);
|
|
1335
|
1339
|
cell124.CellStyle = cellStylebt;
|
|
1336
|
1340
|
sheet.AddMergedRegion(new CellRangeAddress(t + 1 + i, t + 1 + i, 4, 6));
|
|
|
1341
|
+
|
|
|
1342
|
+ // sheet.AddMergedRegion(new CellRangeAddress(t + 1 + i, t + 1 + i, 8, 11));
|
|
|
1343
|
+ }
|
|
|
1344
|
+ if (t + 1 + i >structure + Factory3.Count)
|
|
|
1345
|
+ {
|
|
1337
|
1346
|
ICell cell132 = irow6.CreateCell(8);
|
|
1338
|
1347
|
cell132.CellStyle = cellStylebt;
|
|
1339
|
1348
|
ICell cell128 = irow6.CreateCell(9);
|
|
|
@@ -1342,7 +1351,6 @@ namespace CallCenter.Utility
|
|
1342
|
1351
|
cell129.CellStyle = cellStylebt;
|
|
1343
|
1352
|
ICell cell130 = irow6.CreateCell(11);
|
|
1344
|
1353
|
cell130.CellStyle = cellStylebt;
|
|
1345
|
|
- // sheet.AddMergedRegion(new CellRangeAddress(t + 1 + i, t + 1 + i, 8, 11));
|
|
1346
|
1354
|
}
|
|
1347
|
1355
|
}
|
|
1348
|
1356
|
|
|
|
@@ -1855,14 +1863,13 @@ namespace CallCenter.Utility
|
|
1855
|
1863
|
try
|
|
1856
|
1864
|
{
|
|
1857
|
1865
|
HSSFWorkbook workbook = new HSSFWorkbook();
|
|
1858
|
|
- ISheet sheet = workbook.CreateSheet("Sheet1");
|
|
|
1866
|
+ ISheet sheet = workbook.CreateSheet("各生产单位市场投诉对比情况");
|
|
1859
|
1867
|
ICellStyle cellStyle = workbook.CreateCellStyle();
|
|
1860
|
1868
|
NPOI.SS.UserModel.IFont cellfont = workbook.CreateFont();
|
|
1861
|
1869
|
// cellfont.Boldweight = (short)FontBoldWeight.Normal;
|
|
1862
|
1870
|
cellStyle.VerticalAlignment = VerticalAlignment.Center;
|
|
1863
|
1871
|
cellStyle.Alignment = HorizontalAlignment.Center;
|
|
1864
|
1872
|
// cellfont.FontHeightInPoints = 17;
|
|
1865
|
|
-
|
|
1866
|
1873
|
cellfont.FontHeight = 300;
|
|
1867
|
1874
|
cellStyle.SetFont(cellfont);
|
|
1868
|
1875
|
ICellStyle cellStylebt = workbook.CreateCellStyle();
|
|
|
@@ -1891,7 +1898,7 @@ namespace CallCenter.Utility
|
|
1891
|
1898
|
#region
|
|
1892
|
1899
|
ICellStyle cellStylebt3 = workbook.CreateCellStyle();
|
|
1893
|
1900
|
NPOI.SS.UserModel.IFont cellfontbt3 = workbook.CreateFont();
|
|
1894
|
|
- // cellfontbt3.Boldweight = (short)FontBoldWeight.Bold;
|
|
|
1901
|
+ // cellfontbt3.Boldweight = (short)FontBoldWeight.Bold;
|
|
1895
|
1902
|
// cellfontbt3.FontHeight = 400;
|
|
1896
|
1903
|
cellfontbt3.FontHeightInPoints = 15;
|
|
1897
|
1904
|
cellStylebt3.WrapText = true;//设置换行这个要先设置
|
|
|
@@ -2040,8 +2047,734 @@ namespace CallCenter.Utility
|
|
2040
|
2047
|
}
|
|
2041
|
2048
|
}
|
|
2042
|
2049
|
|
|
|
2050
|
+ public string Qualityproblem(DataTable dt, List<qualityproblem> jo,int size)
|
|
|
2051
|
+ {
|
|
|
2052
|
+ try
|
|
|
2053
|
+ {
|
|
|
2054
|
+ HSSFWorkbook workbook = new HSSFWorkbook();
|
|
|
2055
|
+ ISheet sheet = workbook.CreateSheet("质量问题情况统计分析表");
|
|
|
2056
|
+ ICellStyle cellStyle = workbook.CreateCellStyle();
|
|
|
2057
|
+ NPOI.SS.UserModel.IFont cellfont = workbook.CreateFont();
|
|
|
2058
|
+ cellfont.Boldweight = (short)FontBoldWeight.Normal;
|
|
|
2059
|
+ cellfont.FontHeight = 300;
|
|
|
2060
|
+ cellStyle.VerticalAlignment = VerticalAlignment.Center;
|
|
|
2061
|
+ cellStyle.Alignment = HorizontalAlignment.Center;
|
|
|
2062
|
+ cellStyle.SetFont(cellfont);
|
|
|
2063
|
+ ICellStyle cellStylebt = workbook.CreateCellStyle();
|
|
|
2064
|
+ NPOI.SS.UserModel.IFont cellfontbt = workbook.CreateFont();
|
|
|
2065
|
+ cellStylebt.SetFont(cellfontbt);
|
|
|
2066
|
+ cellStylebt.VerticalAlignment = VerticalAlignment.Center;
|
|
|
2067
|
+ cellStylebt.Alignment = HorizontalAlignment.Center;
|
|
|
2068
|
+
|
|
|
2069
|
+
|
|
|
2070
|
+ #region 标题
|
|
|
2071
|
+ ICellStyle cellStylebt1 = workbook.CreateCellStyle();
|
|
|
2072
|
+ NPOI.SS.UserModel.IFont cellfontbt1 = workbook.CreateFont();
|
|
|
2073
|
+ cellfontbt1.Boldweight = (short)FontBoldWeight.Bold;
|
|
|
2074
|
+ cellfontbt1.FontHeight = 500;
|
|
|
2075
|
+ cellStylebt1.SetFont(cellfontbt1);
|
|
|
2076
|
+ cellStylebt1.VerticalAlignment = VerticalAlignment.Center;
|
|
|
2077
|
+ cellStylebt1.Alignment = HorizontalAlignment.Center;
|
|
|
2078
|
+ IRow irow1 = sheet.CreateRow(0);
|
|
|
2079
|
+ ICell cell1 = irow1.CreateCell(0);
|
|
|
2080
|
+ cell1.SetCellValue("质量问题情况统计分析表");
|
|
|
2081
|
+ cell1.CellStyle = cellStylebt1;
|
|
|
2082
|
+ sheet.AddMergedRegion(new CellRangeAddress(0, 0, 0, size));
|
|
|
2083
|
+ #endregion
|
|
|
2084
|
+ #region 说明
|
|
|
2085
|
+ ICellStyle cellStylebt2 = workbook.CreateCellStyle();
|
|
|
2086
|
+ NPOI.SS.UserModel.IFont cellfontbt2 = workbook.CreateFont();
|
|
|
2087
|
+ //cellfontbt2.Boldweight = (short)FontBoldWeight.Bold;
|
|
|
2088
|
+ cellfontbt2.FontHeight = 300;
|
|
|
2089
|
+ cellStylebt2.SetFont(cellfontbt2);
|
|
|
2090
|
+ cellStylebt2.WrapText = true;//设置换行这个要先设置
|
|
|
2091
|
+ cellStylebt2.VerticalAlignment = VerticalAlignment.Center;
|
|
|
2092
|
+ cellStylebt2.Alignment = HorizontalAlignment.Center;
|
|
|
2093
|
+ IRow irow2 = sheet.CreateRow(1);
|
|
|
2094
|
+ IRow irow3 = sheet.CreateRow(2);
|
|
|
2095
|
+ int index = 0;
|
|
|
2096
|
+ foreach (var it in jo)
|
|
|
2097
|
+ {
|
|
|
2098
|
+ if (it.junior.Count==1&& it.junior[0].name == it.junior[0].type)
|
|
|
2099
|
+ {
|
|
|
2100
|
+ ICell cell2 = irow2.CreateCell(index);
|
|
|
2101
|
+ cell2.SetCellValue(it.name);
|
|
|
2102
|
+ cell2.CellStyle = cellStylebt2;
|
|
|
2103
|
+ sheet.AddMergedRegion(new CellRangeAddress(1, 2, index, index));
|
|
|
2104
|
+ }
|
|
|
2105
|
+ else
|
|
|
2106
|
+ {
|
|
|
2107
|
+ ICell cell2 = irow2.CreateCell(index);
|
|
|
2108
|
+ cell2.SetCellValue(it.name);
|
|
|
2109
|
+ cell2.CellStyle = cellStylebt2;
|
|
|
2110
|
+ sheet.AddMergedRegion(new CellRangeAddress(1, 1, index, index+ it.junior.Count-1));
|
|
|
2111
|
+ for(int i=0;i < it.junior.Count;i++)
|
|
|
2112
|
+ {
|
|
|
2113
|
+ ICell cell3 = irow3.CreateCell(index);
|
|
|
2114
|
+ cell3.SetCellValue(it.junior[i].name);
|
|
|
2115
|
+ cell3.CellStyle = cellStylebt2;
|
|
|
2116
|
+ index = index + 1;
|
|
|
2117
|
+ }
|
|
|
2118
|
+ index = index -1;
|
|
|
2119
|
+ }
|
|
|
2120
|
+ index++;
|
|
|
2121
|
+ }
|
|
|
2122
|
+ #endregion
|
|
|
2123
|
+
|
|
|
2124
|
+ DataView view = dt.DefaultView;
|
|
|
2125
|
+ view.RowFilter = "生产厂家 <> '肉制品事业部'"; // 设置筛选条件
|
|
|
2126
|
+ view.Sort = "序号 ASC"; // 设置排序条件
|
|
|
2127
|
+ DataTable dt1 = view.ToTable();
|
|
|
2128
|
+ // var dt1 = dt.Select("生产厂家 <> '合计'");
|
|
|
2129
|
+
|
|
|
2130
|
+ int iRowIndex = 2;
|
|
|
2131
|
+ foreach (DataRow dr in dt1.Rows)
|
|
|
2132
|
+ {
|
|
|
2133
|
+ int iCellIndex = 0;
|
|
|
2134
|
+ IRow irow = sheet.CreateRow(iRowIndex + 1);
|
|
|
2135
|
+ for (int i = 0; i < dt1.Rows.Count; i++)
|
|
|
2136
|
+ {
|
|
|
2137
|
+ string strsj = string.Empty;
|
|
|
2138
|
+ if (dr[i] != null)
|
|
|
2139
|
+ {
|
|
|
2140
|
+ strsj = dr[i].ToString();
|
|
|
2141
|
+ }
|
|
|
2142
|
+ ICell cell = irow.CreateCell(iCellIndex);
|
|
|
2143
|
+ cell.SetCellValue(strsj);
|
|
|
2144
|
+ cell.CellStyle = cellStyle;
|
|
|
2145
|
+ iCellIndex++;
|
|
|
2146
|
+ }
|
|
|
2147
|
+ iRowIndex++;
|
|
|
2148
|
+ }
|
|
|
2149
|
+ IRow irow4 = sheet.CreateRow(iRowIndex );
|
|
|
2150
|
+ var dt2 = dt.Select("生产厂家 ='肉制品事业部'");
|
|
|
2151
|
+ int iCellIndex1 = 0;
|
|
|
2152
|
+ for (int i = 0; i < dt.Columns.Count; i++)
|
|
|
2153
|
+ {
|
|
|
2154
|
+ if (i==0)
|
|
|
2155
|
+ {
|
|
|
2156
|
+ ICell cell = irow4.CreateCell(iCellIndex1);
|
|
|
2157
|
+ cell.SetCellValue("肉制品事业部");
|
|
|
2158
|
+ cell.CellStyle = cellStyle;
|
|
|
2159
|
+ sheet.AddMergedRegion(new CellRangeAddress(iRowIndex, iRowIndex, 0,1));
|
|
|
2160
|
+ }
|
|
|
2161
|
+ else if (i==1)
|
|
|
2162
|
+ {
|
|
|
2163
|
+ iCellIndex1++;
|
|
|
2164
|
+ continue;
|
|
|
2165
|
+ }
|
|
|
2166
|
+ else
|
|
|
2167
|
+ {
|
|
|
2168
|
+ string strsj = string.Empty;
|
|
|
2169
|
+ if (dt2[0][i] != null)
|
|
|
2170
|
+ {
|
|
|
2171
|
+ strsj = dt2[0][i].ToString();
|
|
|
2172
|
+ }
|
|
|
2173
|
+ ICell cell = irow4.CreateCell(iCellIndex1);
|
|
|
2174
|
+ cell.SetCellValue(strsj);
|
|
|
2175
|
+ cell.CellStyle = cellStyle;
|
|
|
2176
|
+ }
|
|
|
2177
|
+
|
|
|
2178
|
+ iCellIndex1++;
|
|
|
2179
|
+ }
|
|
|
2180
|
+
|
|
|
2181
|
+ //自适应列宽度
|
|
|
2182
|
+ for (int i = 0; i < size; i++)
|
|
|
2183
|
+ {
|
|
|
2184
|
+ //
|
|
|
2185
|
+ sheet.AutoSizeColumn(i);
|
|
|
2186
|
+ }
|
|
|
2187
|
+
|
|
|
2188
|
+ using (MemoryStream ms = new MemoryStream())
|
|
|
2189
|
+ {
|
|
|
2190
|
+ workbook.Write(ms);
|
|
|
2191
|
+
|
|
|
2192
|
+ HttpContext curContext = HttpContext.Current;
|
|
|
2193
|
+
|
|
|
2194
|
+
|
|
|
2195
|
+ // 设置编码和附件格式
|
|
|
2196
|
+ curContext.Response.ContentType = "application/vnd.ms-excel";
|
|
|
2197
|
+ curContext.Response.ContentEncoding = Encoding.UTF8;
|
|
|
2198
|
+ curContext.Response.Charset = "";
|
|
|
2199
|
+ curContext.Response.AppendHeader("Content-Disposition",
|
|
|
2200
|
+ "attachment;filename=" + HttpUtility.UrlEncode("质量问题情况统计分析表" + ".xls", Encoding.UTF8));
|
|
|
2201
|
+
|
|
|
2202
|
+ curContext.Response.BinaryWrite(ms.GetBuffer());
|
|
|
2203
|
+
|
|
|
2204
|
+ workbook = null;
|
|
|
2205
|
+ ms.Close();
|
|
|
2206
|
+ ms.Dispose();
|
|
|
2207
|
+
|
|
|
2208
|
+ curContext.Response.End();
|
|
|
2209
|
+ }
|
|
|
2210
|
+ return "";
|
|
|
2211
|
+ }
|
|
|
2212
|
+ catch
|
|
|
2213
|
+ {
|
|
|
2214
|
+ return "导出失败!";
|
|
|
2215
|
+ }
|
|
|
2216
|
+ }
|
|
|
2217
|
+
|
|
|
2218
|
+
|
|
|
2219
|
+ public string QualityComplaints(List<qualityComplaints> data)
|
|
|
2220
|
+ {
|
|
|
2221
|
+ try
|
|
|
2222
|
+ {
|
|
|
2223
|
+ HSSFWorkbook workbook = new HSSFWorkbook();
|
|
|
2224
|
+ ISheet sheet = workbook.CreateSheet("年度质量投诉问题情况对比");
|
|
|
2225
|
+ ICellStyle cellStyle = workbook.CreateCellStyle();
|
|
|
2226
|
+ NPOI.SS.UserModel.IFont cellfont = workbook.CreateFont();
|
|
|
2227
|
+ // cellfont.Boldweight = (short)FontBoldWeight.Normal;
|
|
|
2228
|
+ cellStyle.VerticalAlignment = VerticalAlignment.Center;
|
|
|
2229
|
+ cellStyle.Alignment = HorizontalAlignment.Center;
|
|
|
2230
|
+ cellStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
|
|
|
2231
|
+ cellStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
|
|
|
2232
|
+ cellStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
|
|
|
2233
|
+ cellStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
|
|
|
2234
|
+ cellStyle.BorderDiagonalLineStyle = BorderStyle.Thin;
|
|
|
2235
|
+ // cellfont.FontHeightInPoints = 17;
|
|
|
2236
|
+ cellfont.FontHeight = 300;
|
|
|
2237
|
+ cellStyle.SetFont(cellfont);
|
|
|
2238
|
+ ICellStyle cellStylebt = workbook.CreateCellStyle();
|
|
|
2239
|
+ NPOI.SS.UserModel.IFont cellfontbt = workbook.CreateFont();
|
|
|
2240
|
+ cellStylebt.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
|
|
|
2241
|
+ cellStylebt.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
|
|
|
2242
|
+ cellStylebt.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
|
|
|
2243
|
+ cellStylebt.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
|
|
|
2244
|
+ cellStylebt.BorderDiagonalLineStyle = BorderStyle.Thin;
|
|
|
2245
|
+ cellStylebt.SetFont(cellfontbt);
|
|
|
2246
|
+ cellStylebt.VerticalAlignment = VerticalAlignment.Center;
|
|
|
2247
|
+ cellStylebt.Alignment = HorizontalAlignment.Center;
|
|
|
2248
|
+
|
|
|
2249
|
+ //ICellStyle frame = workbook.CreateCellStyle();
|
|
|
2250
|
+ //frame.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
|
|
|
2251
|
+ //frame.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
|
|
|
2252
|
+ //frame.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
|
|
|
2253
|
+ //frame.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
|
|
|
2254
|
+
|
|
|
2255
|
+ #region 标题
|
|
|
2256
|
+ ICellStyle cellStylebt1 = workbook.CreateCellStyle();
|
|
|
2257
|
+ NPOI.SS.UserModel.IFont cellfontbt1 = workbook.CreateFont();
|
|
|
2258
|
+ // cellfontbt1.Boldweight = (short)FontBoldWeight.Bold;
|
|
|
2259
|
+ cellfontbt1.FontHeight = 500;
|
|
|
2260
|
+ cellStylebt1.SetFont(cellfontbt1);
|
|
|
2261
|
+ cellStylebt1.VerticalAlignment = VerticalAlignment.Center;
|
|
|
2262
|
+ cellStylebt1.Alignment = HorizontalAlignment.Center;
|
|
|
2263
|
+ cellStylebt1.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
|
|
|
2264
|
+ cellStylebt1.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
|
|
|
2265
|
+ cellStylebt1.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
|
|
|
2266
|
+ cellStylebt1.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
|
|
|
2267
|
+ cellStylebt1.BorderDiagonalLineStyle = BorderStyle.Thin;
|
|
|
2268
|
+ IRow irow1 = sheet.CreateRow(0);
|
|
|
2269
|
+ ICell cell1 = irow1.CreateCell(0);
|
|
|
2270
|
+ cell1.SetCellValue("年度质量投诉问题情况对比");
|
|
|
2271
|
+ cell1.CellStyle = cellStylebt1;
|
|
|
2272
|
+ CellRangeAddress region = new CellRangeAddress(0, 0, 0, 16);
|
|
|
2273
|
+ sheet.AddMergedRegion(region);
|
|
|
2274
|
+ SetMergedRegionBorders(sheet, region, workbook);
|
|
|
2275
|
+ #endregion
|
|
|
2276
|
+ ICellStyle style13 = workbook.CreateCellStyle();
|
|
|
2277
|
+ style13.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
|
|
|
2278
|
+ style13.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
|
|
|
2279
|
+ style13.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
|
|
|
2280
|
+ style13.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
|
|
|
2281
|
+ style13.BorderDiagonalLineStyle = BorderStyle.Thin;
|
|
|
2282
|
+ style13.BorderDiagonal = BorderDiagonal.Backward;
|
|
|
2283
|
+ style13.BorderDiagonalColor = IndexedColors.Black.Index;
|
|
|
2284
|
+ string sb = " 项目\n时间";
|
|
|
2285
|
+ IRow irow2 = sheet.CreateRow(1);
|
|
|
2286
|
+ ICell cell2 = irow2.CreateCell(0);
|
|
|
2287
|
+ cell2.SetCellValue(sb);
|
|
|
2288
|
+ cell2.CellStyle = cellStylebt;
|
|
|
2289
|
+ style13.WrapText = true;
|
|
|
2290
|
+ irow2.GetCell(0).CellStyle = style13;
|
|
|
2291
|
+ sheet.AddMergedRegion(new CellRangeAddress(1, 2, 0, 1));
|
|
|
2292
|
+ SetMergedRegionBorders(sheet, new CellRangeAddress(1, 2, 0, 1), workbook);
|
|
|
2293
|
+ #region
|
|
|
2294
|
+ ICellStyle cellStylebt3 = workbook.CreateCellStyle();
|
|
|
2295
|
+ NPOI.SS.UserModel.IFont cellfontbt3 = workbook.CreateFont();
|
|
|
2296
|
+ cellfontbt3.FontHeightInPoints = 15;
|
|
|
2297
|
+ cellStylebt3.WrapText = true;//设置换行这个要先设置
|
|
|
2298
|
+ cellStylebt3.SetFont(cellfontbt3);
|
|
|
2299
|
+ cellStylebt3.VerticalAlignment = VerticalAlignment.Center;
|
|
|
2300
|
+ cellStylebt3.Alignment = HorizontalAlignment.Center;
|
|
|
2301
|
+ cellStylebt3.Alignment = HorizontalAlignment.Center;
|
|
|
2302
|
+ cellStylebt3.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
|
|
|
2303
|
+ cellStylebt3.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
|
|
|
2304
|
+ cellStylebt3.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
|
|
|
2305
|
+ cellStylebt3.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
|
|
|
2306
|
+ cellStylebt3.BorderDiagonalLineStyle = BorderStyle.Thin;
|
|
|
2307
|
+ IRow irow6 = sheet.CreateRow(2);
|
|
|
2308
|
+
|
|
|
2309
|
+ ICell title1 = irow2.CreateCell(2);
|
|
|
2310
|
+ title1.SetCellValue("总投诉");
|
|
|
2311
|
+ title1.CellStyle = cellStylebt3;
|
|
|
2312
|
+ sheet.AddMergedRegion(new CellRangeAddress(1, 1, 2, 4));
|
|
|
2313
|
+ SetMergedRegionBorders(sheet, new CellRangeAddress(1, 1, 2, 4), workbook);
|
|
|
2314
|
+ ICell title13 = irow2.CreateCell(5);
|
|
|
2315
|
+ title13.SetCellValue("破袋发霉类(P)");
|
|
|
2316
|
+ title13.CellStyle = cellStylebt3;
|
|
|
2317
|
+ sheet.AddMergedRegion(new CellRangeAddress(1, 1, 5, 8));
|
|
|
2318
|
+ SetMergedRegionBorders(sheet, new CellRangeAddress(1, 1, 5, 8), workbook);
|
|
|
2319
|
+ ICell title14 = irow2.CreateCell(9);
|
|
|
2320
|
+ title14.SetCellValue("杂质异物类(Z**)");
|
|
|
2321
|
+ title14.CellStyle = cellStylebt3;
|
|
|
2322
|
+ sheet.AddMergedRegion(new CellRangeAddress(1, 1, 9, 12));
|
|
|
2323
|
+ SetMergedRegionBorders(sheet, new CellRangeAddress(1, 1, 9, 12), workbook);
|
|
|
2324
|
+ ICell title15 = irow2.CreateCell(13);
|
|
|
2325
|
+ title15.SetCellValue("变质异味类(B)");
|
|
|
2326
|
+ title15.CellStyle = cellStylebt3;
|
|
|
2327
|
+ sheet.AddMergedRegion(new CellRangeAddress(1, 1, 13, 16));
|
|
|
2328
|
+ SetMergedRegionBorders(sheet, new CellRangeAddress(1, 1, 13, 16), workbook);
|
|
|
2329
|
+
|
|
|
2330
|
+ ICell title16 = irow6.CreateCell(2);
|
|
|
2331
|
+ title16.SetCellValue("起数");
|
|
|
2332
|
+ title16.CellStyle = cellStylebt3;
|
|
|
2333
|
+
|
|
|
2334
|
+ ICell title17 = irow6.CreateCell(3);
|
|
|
2335
|
+ title17.SetCellValue("同期");
|
|
|
2336
|
+ title17.CellStyle = cellStylebt3;
|
|
|
2337
|
+
|
|
|
2338
|
+ ICell title18 = irow6.CreateCell(4);
|
|
|
2339
|
+ title18.SetCellValue("增幅");
|
|
|
2340
|
+ title18.CellStyle = cellStylebt3;
|
|
|
2341
|
+
|
|
|
2342
|
+ ICell title19 = irow6.CreateCell(5);
|
|
|
2343
|
+ title19.SetCellValue("起数");
|
|
|
2344
|
+ title19.CellStyle = cellStylebt3;
|
|
|
2345
|
+
|
|
|
2346
|
+ ICell title115 = irow6.CreateCell(6);
|
|
|
2347
|
+ title115.SetCellValue("占比");
|
|
|
2348
|
+ title115.CellStyle = cellStylebt3;
|
|
|
2349
|
+
|
|
|
2350
|
+ ICell title110 = irow6.CreateCell(7);
|
|
|
2351
|
+ title110.SetCellValue("同期");
|
|
|
2352
|
+ title110.CellStyle = cellStylebt3;
|
|
|
2353
|
+
|
|
|
2354
|
+
|
|
|
2355
|
+ ICell title111 = irow6.CreateCell(8);
|
|
|
2356
|
+ title111.SetCellValue("增幅");
|
|
|
2357
|
+ title111.CellStyle = cellStylebt3;
|
|
|
2358
|
+
|
|
|
2359
|
+ ICell title112 = irow6.CreateCell(9);
|
|
|
2360
|
+ title112.SetCellValue("起数");
|
|
|
2361
|
+ title112.CellStyle = cellStylebt3;
|
|
|
2362
|
+
|
|
|
2363
|
+ ICell title116 = irow6.CreateCell(10);
|
|
|
2364
|
+ title116.SetCellValue("占比");
|
|
|
2365
|
+ title116.CellStyle = cellStylebt3;
|
|
|
2366
|
+
|
|
|
2367
|
+ ICell title113 = irow6.CreateCell(11);
|
|
|
2368
|
+ title113.SetCellValue("同期");
|
|
|
2369
|
+ title113.CellStyle = cellStylebt3;
|
|
|
2370
|
+
|
|
|
2371
|
+ ICell title114 = irow6.CreateCell(12);
|
|
|
2372
|
+ title114.SetCellValue("增幅");
|
|
|
2373
|
+ title114.CellStyle = cellStylebt3;
|
|
2043
|
2374
|
|
|
2044
|
2375
|
|
|
|
2376
|
+ ICell title1122 = irow6.CreateCell(13);
|
|
|
2377
|
+ title1122.SetCellValue("起数");
|
|
|
2378
|
+ title1122.CellStyle = cellStylebt3;
|
|
|
2379
|
+
|
|
|
2380
|
+ ICell title117 = irow6.CreateCell(14);
|
|
|
2381
|
+ title117.SetCellValue("占比");
|
|
|
2382
|
+ title117.CellStyle = cellStylebt3;
|
|
|
2383
|
+
|
|
|
2384
|
+ ICell title1133 = irow6.CreateCell(15);
|
|
|
2385
|
+ title1133.SetCellValue("同期");
|
|
|
2386
|
+ title1133.CellStyle = cellStylebt3;
|
|
|
2387
|
+
|
|
|
2388
|
+ ICell title1144 = irow6.CreateCell(16);
|
|
|
2389
|
+ title1144.SetCellValue("增幅");
|
|
|
2390
|
+ title1144.CellStyle = cellStylebt3;
|
|
|
2391
|
+
|
|
|
2392
|
+
|
|
|
2393
|
+ IRow irow3 = sheet.CreateRow(3);
|
|
|
2394
|
+ string year = data.FirstOrDefault().year;
|
|
|
2395
|
+ char specialChar = '\n';
|
|
|
2396
|
+ StringBuilder sbyear = new StringBuilder();
|
|
|
2397
|
+ for (int i = 0; i < year.Length; i++)
|
|
|
2398
|
+ {
|
|
|
2399
|
+ sbyear.Append(year[i]);
|
|
|
2400
|
+ if (i < year.Length - 1)
|
|
|
2401
|
+ {
|
|
|
2402
|
+ sbyear.Append(specialChar);
|
|
|
2403
|
+ }
|
|
|
2404
|
+ }
|
|
|
2405
|
+ string result = sbyear.ToString();
|
|
|
2406
|
+ ICell cell3 = irow3.CreateCell(0);
|
|
|
2407
|
+ cell3.SetCellValue(sbyear.ToString());
|
|
|
2408
|
+ cell3.CellStyle = cellStyle;
|
|
|
2409
|
+ cell3.CellStyle.WrapText = true;
|
|
|
2410
|
+ sheet.AddMergedRegion(new CellRangeAddress(3, 21, 0, 0));
|
|
|
2411
|
+ #endregion
|
|
|
2412
|
+ //建立内容行
|
|
|
2413
|
+ int iRowIndex = 3;
|
|
|
2414
|
+ foreach(var it in data )
|
|
|
2415
|
+ {
|
|
|
2416
|
+ if (iRowIndex==3)
|
|
|
2417
|
+ {
|
|
|
2418
|
+ for(int i=1;i<17;i ++)
|
|
|
2419
|
+ {
|
|
|
2420
|
+ ICell cell = irow3.CreateCell(i);
|
|
|
2421
|
+ cell.SetCellValue(GetQualityComplaints(it ,i ));
|
|
|
2422
|
+ cell.CellStyle = cellStyle;
|
|
|
2423
|
+ }
|
|
|
2424
|
+
|
|
|
2425
|
+ }
|
|
|
2426
|
+ else
|
|
|
2427
|
+ {
|
|
|
2428
|
+ IRow irow = sheet.CreateRow(iRowIndex);
|
|
|
2429
|
+ if (iRowIndex == data.Count + 2)
|
|
|
2430
|
+ {
|
|
|
2431
|
+ ICell cell = irow.CreateCell(0);
|
|
|
2432
|
+ cell.CellStyle = cellStyle;
|
|
|
2433
|
+ }
|
|
|
2434
|
+ for (int i = 1; i < 17; i++)
|
|
|
2435
|
+ {
|
|
|
2436
|
+ ICell cell = irow.CreateCell(i);
|
|
|
2437
|
+ cell.SetCellValue(GetQualityComplaints(it, i));
|
|
|
2438
|
+ cell.CellStyle = cellStyle;
|
|
|
2439
|
+ }
|
|
|
2440
|
+ }
|
|
|
2441
|
+ iRowIndex++;
|
|
|
2442
|
+ }
|
|
|
2443
|
+ for (int i = 0; i < 17; i++)
|
|
|
2444
|
+ {
|
|
|
2445
|
+ //
|
|
|
2446
|
+ sheet.AutoSizeColumn(i);
|
|
|
2447
|
+ // sheet.SetColumnWidth(i, 12 * 400);
|
|
|
2448
|
+ }
|
|
|
2449
|
+
|
|
|
2450
|
+ using (MemoryStream ms = new MemoryStream())
|
|
|
2451
|
+ {
|
|
|
2452
|
+ workbook.Write(ms);
|
|
|
2453
|
+
|
|
|
2454
|
+ HttpContext curContext = HttpContext.Current;
|
|
|
2455
|
+
|
|
|
2456
|
+
|
|
|
2457
|
+ // 设置编码和附件格式
|
|
|
2458
|
+ curContext.Response.ContentType = "application/vnd.ms-excel";
|
|
|
2459
|
+ curContext.Response.ContentEncoding = Encoding.UTF8;
|
|
|
2460
|
+ curContext.Response.Charset = "";
|
|
|
2461
|
+ curContext.Response.AppendHeader("Content-Disposition",
|
|
|
2462
|
+ "attachment;filename=" + HttpUtility.UrlEncode("各生产单位市场投诉对比情况" + ".xls", Encoding.UTF8));
|
|
|
2463
|
+
|
|
|
2464
|
+ curContext.Response.BinaryWrite(ms.GetBuffer());
|
|
|
2465
|
+
|
|
|
2466
|
+ workbook = null;
|
|
|
2467
|
+ ms.Close();
|
|
|
2468
|
+ ms.Dispose();
|
|
|
2469
|
+
|
|
|
2470
|
+ curContext.Response.End();
|
|
|
2471
|
+ }
|
|
|
2472
|
+ return "";
|
|
|
2473
|
+ }
|
|
|
2474
|
+ catch
|
|
|
2475
|
+ {
|
|
|
2476
|
+ return "导出失败!";
|
|
|
2477
|
+ }
|
|
|
2478
|
+ }
|
|
|
2479
|
+
|
|
|
2480
|
+ public string DateOfManufacture(DataTable dt,DateTime time)
|
|
|
2481
|
+ {
|
|
|
2482
|
+ try
|
|
|
2483
|
+ {
|
|
|
2484
|
+ HSSFWorkbook workbook = new HSSFWorkbook();
|
|
|
2485
|
+ ISheet sheet = workbook.CreateSheet("近三年投诉产品生产日期分布表");
|
|
|
2486
|
+ ICellStyle cellStyle = workbook.CreateCellStyle();
|
|
|
2487
|
+ NPOI.SS.UserModel.IFont cellfont = workbook.CreateFont();
|
|
|
2488
|
+ // cellfont.Boldweight = (short)FontBoldWeight.Normal;
|
|
|
2489
|
+ cellStyle.VerticalAlignment = VerticalAlignment.Center;
|
|
|
2490
|
+ cellStyle.Alignment = HorizontalAlignment.Center;
|
|
|
2491
|
+ cellStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
|
|
|
2492
|
+ cellStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
|
|
|
2493
|
+ cellStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
|
|
|
2494
|
+ cellStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
|
|
|
2495
|
+ cellStyle.BorderDiagonalLineStyle = BorderStyle.Thin;
|
|
|
2496
|
+ // cellfont.FontHeightInPoints = 17;
|
|
|
2497
|
+ cellfont.FontHeight = 300;
|
|
|
2498
|
+ cellStyle.SetFont(cellfont);
|
|
|
2499
|
+ ICellStyle cellStylebt = workbook.CreateCellStyle();
|
|
|
2500
|
+ NPOI.SS.UserModel.IFont cellfontbt = workbook.CreateFont();
|
|
|
2501
|
+ cellStylebt.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
|
|
|
2502
|
+ cellStylebt.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
|
|
|
2503
|
+ cellStylebt.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
|
|
|
2504
|
+ cellStylebt.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
|
|
|
2505
|
+ cellStylebt.BorderDiagonalLineStyle = BorderStyle.Thin;
|
|
|
2506
|
+ cellStylebt.SetFont(cellfontbt);
|
|
|
2507
|
+ cellStylebt.VerticalAlignment = VerticalAlignment.Center;
|
|
|
2508
|
+ cellStylebt.Alignment = HorizontalAlignment.Center;
|
|
|
2509
|
+
|
|
|
2510
|
+ //ICellStyle frame = workbook.CreateCellStyle();
|
|
|
2511
|
+ //frame.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
|
|
|
2512
|
+ //frame.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
|
|
|
2513
|
+ //frame.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
|
|
|
2514
|
+ //frame.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
|
|
|
2515
|
+
|
|
|
2516
|
+ #region 标题
|
|
|
2517
|
+ ICellStyle cellStylebt1 = workbook.CreateCellStyle();
|
|
|
2518
|
+ NPOI.SS.UserModel.IFont cellfontbt1 = workbook.CreateFont();
|
|
|
2519
|
+ // cellfontbt1.Boldweight = (short)FontBoldWeight.Bold;
|
|
|
2520
|
+ cellfontbt1.FontHeight = 500;
|
|
|
2521
|
+ cellStylebt1.SetFont(cellfontbt1);
|
|
|
2522
|
+ cellStylebt1.VerticalAlignment = VerticalAlignment.Center;
|
|
|
2523
|
+ cellStylebt1.Alignment = HorizontalAlignment.Center;
|
|
|
2524
|
+ cellStylebt1.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
|
|
|
2525
|
+ cellStylebt1.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
|
|
|
2526
|
+ cellStylebt1.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
|
|
|
2527
|
+ cellStylebt1.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
|
|
|
2528
|
+ cellStylebt1.BorderDiagonalLineStyle = BorderStyle.Thin;
|
|
|
2529
|
+ IRow irow1 = sheet.CreateRow(0);
|
|
|
2530
|
+ ICell cell1 = irow1.CreateCell(0);
|
|
|
2531
|
+ cell1.SetCellValue("近三年投诉产品生产日期分布表");
|
|
|
2532
|
+ cell1.CellStyle = cellStylebt1;
|
|
|
2533
|
+ CellRangeAddress region = new CellRangeAddress(0, 0, 0, 37);
|
|
|
2534
|
+ sheet.AddMergedRegion(region);
|
|
|
2535
|
+ SetMergedRegionBorders(sheet, region, workbook);
|
|
|
2536
|
+ #endregion
|
|
|
2537
|
+ ICellStyle style13 = workbook.CreateCellStyle();
|
|
|
2538
|
+ style13.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
|
|
|
2539
|
+ style13.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
|
|
|
2540
|
+ style13.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
|
|
|
2541
|
+ style13.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
|
|
|
2542
|
+ style13.BorderDiagonalLineStyle = BorderStyle.Thin;
|
|
|
2543
|
+ style13.VerticalAlignment = VerticalAlignment.Center;
|
|
|
2544
|
+ style13.Alignment = HorizontalAlignment.Left;
|
|
|
2545
|
+ style13.BorderDiagonal = BorderDiagonal.Backward;
|
|
|
2546
|
+ style13.BorderDiagonalColor = IndexedColors.Black.Index;
|
|
|
2547
|
+ string sb = " 投诉月份\n生产月份";
|
|
|
2548
|
+ IRow irow2 = sheet.CreateRow(1);
|
|
|
2549
|
+ ICell cell2 = irow2.CreateCell(0);
|
|
|
2550
|
+ cell2.SetCellValue(sb);
|
|
|
2551
|
+ cell2.CellStyle = cellStylebt;
|
|
|
2552
|
+ style13.WrapText = true;
|
|
|
2553
|
+ irow2.GetCell(0).CellStyle = style13;
|
|
|
2554
|
+ sheet.AddMergedRegion(new CellRangeAddress(1, 2, 0, 0));
|
|
|
2555
|
+ SetMergedRegionBorders(sheet, new CellRangeAddress(1, 2, 0, 0), workbook);
|
|
|
2556
|
+
|
|
|
2557
|
+ ICellStyle cellStylebt3 = workbook.CreateCellStyle();
|
|
|
2558
|
+ NPOI.SS.UserModel.IFont cellfontbt3 = workbook.CreateFont();
|
|
|
2559
|
+ cellfontbt3.FontHeightInPoints = 15;
|
|
|
2560
|
+ cellStylebt3.WrapText = true;//设置换行这个要先设置
|
|
|
2561
|
+ cellStylebt3.SetFont(cellfontbt3);
|
|
|
2562
|
+ cellStylebt3.VerticalAlignment = VerticalAlignment.Center;
|
|
|
2563
|
+ cellStylebt3.Alignment = HorizontalAlignment.Center;
|
|
|
2564
|
+ cellStylebt3.Alignment = HorizontalAlignment.Center;
|
|
|
2565
|
+ cellStylebt3.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
|
|
|
2566
|
+ cellStylebt3.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
|
|
|
2567
|
+ cellStylebt3.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
|
|
|
2568
|
+ cellStylebt3.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
|
|
|
2569
|
+ cellStylebt3.BorderDiagonalLineStyle = BorderStyle.Thin;
|
|
|
2570
|
+ IRow irow6 = sheet.CreateRow(2);
|
|
|
2571
|
+
|
|
|
2572
|
+ ICell title1 = irow2.CreateCell(1);
|
|
|
2573
|
+ title1.SetCellValue(time.AddYears(-3).Year.ToString()+"年");
|
|
|
2574
|
+ title1.CellStyle = cellStylebt3;
|
|
|
2575
|
+ sheet.AddMergedRegion(new CellRangeAddress(1, 1, 1, 12));
|
|
|
2576
|
+ SetMergedRegionBorders(sheet, new CellRangeAddress(1, 1, 1, 12), workbook);
|
|
|
2577
|
+ ICell title13 = irow2.CreateCell(13);
|
|
|
2578
|
+ title13.SetCellValue(time.AddYears(-2).Year.ToString() + "年");
|
|
|
2579
|
+ title13.CellStyle = cellStylebt3;
|
|
|
2580
|
+ sheet.AddMergedRegion(new CellRangeAddress(1, 1, 13, 24));
|
|
|
2581
|
+ SetMergedRegionBorders(sheet, new CellRangeAddress(1, 1, 13, 24), workbook);
|
|
|
2582
|
+ ICell title14 = irow2.CreateCell(25);
|
|
|
2583
|
+ title14.SetCellValue(time.AddYears(-1).Year.ToString() + "年");
|
|
|
2584
|
+ title14.CellStyle = cellStylebt3;
|
|
|
2585
|
+ sheet.AddMergedRegion(new CellRangeAddress(1, 1, 25, 36));
|
|
|
2586
|
+ SetMergedRegionBorders(sheet, new CellRangeAddress(1, 1, 25, 36), workbook);
|
|
|
2587
|
+ ICell title15 = irow2.CreateCell(37);
|
|
|
2588
|
+ title15.SetCellValue("投诉起数");
|
|
|
2589
|
+ title15.CellStyle = cellStylebt3;
|
|
|
2590
|
+ sheet.AddMergedRegion(new CellRangeAddress(1, 2, 37, 37));
|
|
|
2591
|
+ SetMergedRegionBorders(sheet, new CellRangeAddress(1, 2, 37, 37), workbook);
|
|
|
2592
|
+ DateTime start = DateTime.Parse(time.AddYears(-3).Year.ToString() + "-01-01 00:00:00");
|
|
|
2593
|
+ DateTime end = DateTime.Parse(time.AddYears(-1).Year.ToString() + "-12-31 23:59:59");
|
|
|
2594
|
+ int index = 1;
|
|
|
2595
|
+ for (DateTime i = start; i <= end; i = i.AddMonths(1))
|
|
|
2596
|
+ {
|
|
|
2597
|
+ ICell title16 = irow6.CreateCell(index);
|
|
|
2598
|
+ title16.SetCellValue(i.ToString("MM月"));
|
|
|
2599
|
+ title16.CellStyle = cellStylebt3;
|
|
|
2600
|
+ index++;
|
|
|
2601
|
+ }
|
|
|
2602
|
+ int iRowIndex = 2;
|
|
|
2603
|
+ foreach (DataRow dr in dt.Rows)
|
|
|
2604
|
+ {
|
|
|
2605
|
+ int iCellIndex = 0;
|
|
|
2606
|
+ IRow irow = sheet.CreateRow(iRowIndex + 1);
|
|
|
2607
|
+ for (int i = 0; i < dt.Columns.Count; i++)
|
|
|
2608
|
+ {
|
|
|
2609
|
+ string strsj = string.Empty;
|
|
|
2610
|
+ if (dr[i] != null)
|
|
|
2611
|
+ {
|
|
|
2612
|
+ strsj = dr[i].ToString();
|
|
|
2613
|
+ }
|
|
|
2614
|
+ ICell cell = irow.CreateCell(iCellIndex);
|
|
|
2615
|
+ cell.SetCellValue(strsj);
|
|
|
2616
|
+ cell.CellStyle = cellStyle;
|
|
|
2617
|
+ iCellIndex++;
|
|
|
2618
|
+ }
|
|
|
2619
|
+ iRowIndex++;
|
|
|
2620
|
+ }
|
|
|
2621
|
+ for (int i = 0; i < 37; i++)
|
|
|
2622
|
+ {
|
|
|
2623
|
+ //
|
|
|
2624
|
+ sheet.AutoSizeColumn(i);
|
|
|
2625
|
+ // sheet.SetColumnWidth(i, 12 * 400);
|
|
|
2626
|
+ }
|
|
|
2627
|
+
|
|
|
2628
|
+ using (MemoryStream ms = new MemoryStream())
|
|
|
2629
|
+ {
|
|
|
2630
|
+ workbook.Write(ms);
|
|
|
2631
|
+
|
|
|
2632
|
+ HttpContext curContext = HttpContext.Current;
|
|
|
2633
|
+
|
|
|
2634
|
+
|
|
|
2635
|
+ // 设置编码和附件格式
|
|
|
2636
|
+ curContext.Response.ContentType = "application/vnd.ms-excel";
|
|
|
2637
|
+ curContext.Response.ContentEncoding = Encoding.UTF8;
|
|
|
2638
|
+ curContext.Response.Charset = "";
|
|
|
2639
|
+ curContext.Response.AppendHeader("Content-Disposition",
|
|
|
2640
|
+ "attachment;filename=" + HttpUtility.UrlEncode("近三年投诉产品生产日期分布表" + ".xls", Encoding.UTF8));
|
|
|
2641
|
+
|
|
|
2642
|
+ curContext.Response.BinaryWrite(ms.GetBuffer());
|
|
|
2643
|
+
|
|
|
2644
|
+ workbook = null;
|
|
|
2645
|
+ ms.Close();
|
|
|
2646
|
+ ms.Dispose();
|
|
|
2647
|
+
|
|
|
2648
|
+ curContext.Response.End();
|
|
|
2649
|
+ }
|
|
|
2650
|
+ return "";
|
|
|
2651
|
+ }
|
|
|
2652
|
+ catch
|
|
|
2653
|
+ {
|
|
|
2654
|
+ return "导出失败!";
|
|
|
2655
|
+ }
|
|
|
2656
|
+ }
|
|
|
2657
|
+ private void SetMergedRegionBorders(ISheet sheet, CellRangeAddress region, IWorkbook workbook)
|
|
|
2658
|
+ {
|
|
|
2659
|
+ int rowStart = region.FirstRow;
|
|
|
2660
|
+ int rowEnd = region.LastRow;
|
|
|
2661
|
+ int colStart = region.FirstColumn;
|
|
|
2662
|
+ int colEnd = region.LastColumn;
|
|
|
2663
|
+
|
|
|
2664
|
+ // 设置顶部边框
|
|
|
2665
|
+ for (int col = colStart; col <= colEnd; col++)
|
|
|
2666
|
+ {
|
|
|
2667
|
+ SetCellBorder(sheet, rowStart, col, "Top", BorderStyle.Thin, workbook);
|
|
|
2668
|
+ }
|
|
|
2669
|
+
|
|
|
2670
|
+ // 设置底部边框
|
|
|
2671
|
+ for (int col = colStart; col <= colEnd; col++)
|
|
|
2672
|
+ {
|
|
|
2673
|
+ SetCellBorder(sheet, rowEnd, col, "Bottom", BorderStyle.Thin, workbook);
|
|
|
2674
|
+ }
|
|
|
2675
|
+
|
|
|
2676
|
+ // 设置左侧边框
|
|
|
2677
|
+ for (int row = rowStart; row <= rowEnd; row++)
|
|
|
2678
|
+ {
|
|
|
2679
|
+ SetCellBorder(sheet, row, colStart, "Left", BorderStyle.Thin, workbook);
|
|
|
2680
|
+ }
|
|
|
2681
|
+
|
|
|
2682
|
+ // 设置右侧边框
|
|
|
2683
|
+ for (int row = rowStart; row <= rowEnd; row++)
|
|
|
2684
|
+ {
|
|
|
2685
|
+ SetCellBorder(sheet, row, colEnd, "Right", BorderStyle.Thin, workbook);
|
|
|
2686
|
+ }
|
|
|
2687
|
+ }
|
|
|
2688
|
+
|
|
|
2689
|
+ private void SetCellBorder(ISheet sheet, int rowIdx, int colIdx, string direction, BorderStyle style, IWorkbook workbook)
|
|
|
2690
|
+ {
|
|
|
2691
|
+ IRow row = sheet.GetRow(rowIdx) ?? sheet.CreateRow(rowIdx);
|
|
|
2692
|
+ ICell cell = row.GetCell(colIdx) ?? row.CreateCell(colIdx);
|
|
|
2693
|
+ ICellStyle originalStyle = cell.CellStyle;
|
|
|
2694
|
+ ICellStyle newStyle = workbook.CreateCellStyle();
|
|
|
2695
|
+
|
|
|
2696
|
+ // 复制原有样式
|
|
|
2697
|
+ if (originalStyle != null)
|
|
|
2698
|
+ {
|
|
|
2699
|
+ newStyle.CloneStyleFrom(originalStyle);
|
|
|
2700
|
+ }
|
|
|
2701
|
+
|
|
|
2702
|
+ // 设置边框
|
|
|
2703
|
+ switch (direction)
|
|
|
2704
|
+ {
|
|
|
2705
|
+ case "Top":
|
|
|
2706
|
+ newStyle.BorderTop = style;
|
|
|
2707
|
+ break;
|
|
|
2708
|
+ case "Bottom":
|
|
|
2709
|
+ newStyle.BorderBottom = style;
|
|
|
2710
|
+ break;
|
|
|
2711
|
+ case "Left":
|
|
|
2712
|
+ newStyle.BorderLeft = style;
|
|
|
2713
|
+ break;
|
|
|
2714
|
+ case "Right":
|
|
|
2715
|
+ newStyle.BorderRight = style;
|
|
|
2716
|
+ break;
|
|
|
2717
|
+ }
|
|
|
2718
|
+
|
|
|
2719
|
+ // 应用新样式
|
|
|
2720
|
+ cell.CellStyle = newStyle;
|
|
|
2721
|
+ }
|
|
|
2722
|
+ private string GetQualityComplaints(qualityComplaints data,int i)
|
|
|
2723
|
+ {
|
|
|
2724
|
+ object str = "";
|
|
|
2725
|
+ switch(i )
|
|
|
2726
|
+ {
|
|
|
2727
|
+ case 1:
|
|
|
2728
|
+ str = data.month;
|
|
|
2729
|
+ break;
|
|
|
2730
|
+ case 2:
|
|
|
2731
|
+ str = data.Total.ToString();
|
|
|
2732
|
+ break;
|
|
|
2733
|
+ case 3:
|
|
|
2734
|
+ str = data.Previous;
|
|
|
2735
|
+ break;
|
|
|
2736
|
+ case 4:
|
|
|
2737
|
+ str = data.Percent;
|
|
|
2738
|
+ break;
|
|
|
2739
|
+ case 5:
|
|
|
2740
|
+ str = data.P_Total;
|
|
|
2741
|
+ break;
|
|
|
2742
|
+ case 6:
|
|
|
2743
|
+ str = data.P_Proportion;
|
|
|
2744
|
+ break;
|
|
|
2745
|
+ case 7:
|
|
|
2746
|
+ str = data.P_Previous;
|
|
|
2747
|
+ break;
|
|
|
2748
|
+ case 8:
|
|
|
2749
|
+ str = data.P_Percent;
|
|
|
2750
|
+ break;
|
|
|
2751
|
+ case 9:
|
|
|
2752
|
+ str = data.Z_Total;
|
|
|
2753
|
+ break;
|
|
|
2754
|
+ case 10:
|
|
|
2755
|
+ str = data.Z_Proportion;
|
|
|
2756
|
+ break;
|
|
|
2757
|
+ case 11:
|
|
|
2758
|
+ str = data.Z_Previous;
|
|
|
2759
|
+ break;
|
|
|
2760
|
+ case 12:
|
|
|
2761
|
+ str = data.Z_Percent;
|
|
|
2762
|
+ break;
|
|
|
2763
|
+ case 13:
|
|
|
2764
|
+ str = data.B_Total;
|
|
|
2765
|
+ break;
|
|
|
2766
|
+ case 14:
|
|
|
2767
|
+ str = data.B_Proportion;
|
|
|
2768
|
+ break;
|
|
|
2769
|
+ case 15:
|
|
|
2770
|
+ str = data.B_Previous;
|
|
|
2771
|
+ break;
|
|
|
2772
|
+ case 16:
|
|
|
2773
|
+ str = data.B_Percent;
|
|
|
2774
|
+ break;
|
|
|
2775
|
+ }
|
|
|
2776
|
+ return str.ToString();
|
|
|
2777
|
+ }
|
|
2045
|
2778
|
/// <summary>
|
|
2046
|
2779
|
/// NPOI导出EXCEL
|
|
2047
|
2780
|
/// </summary>
|