效果图:  周月季效果一样

protected void btn_impor()
{
#region 样式

HSSFWorkbook workbook = new HSSFWorkbook();
HSSFCellStyle headStyle = workbook.CreateCellStyle();
headStyle.Alignment = CellHorizontalAlignment.CENTER;
headStyle.VerticalAlignment = CellVerticalAlignment.CENTER;
headStyle.WrapText = true;
HSSFSheet sheet = null;
string HeadcolumnName = "";

//第一行样式
HSSFCellStyle style2 = workbook.CreateCellStyle();
style2.BorderTop = NPOI.HSSF.UserModel.CellBorderType.THIN;
style2.BorderBottom = NPOI.HSSF.UserModel.CellBorderType.THIN;
style2.BorderLeft = NPOI.HSSF.UserModel.CellBorderType.THIN;
style2.BorderRight = NPOI.HSSF.UserModel.CellBorderType.THIN;
HSSFFont font2 = workbook.CreateFont();
font2.FontHeightInPoints = 10;
//font.Color=HSSFColor.RED.index;
font2.Boldweight = HSSFFont.BOLDWEIGHT_BOLD;
font2.FontName = "宋体";
style2.Alignment = CellHorizontalAlignment.CENTER;
style2.VerticalAlignment = CellVerticalAlignment.CENTER;
style2.SetFont(font2);

//中间数据样式
HSSFCellStyle style1 = workbook.CreateCellStyle();
//style1.BorderTop = NPOI.HSSF.UserModel.CellBorderType.THIN;
//style1.BorderBottom = NPOI.HSSF.UserModel.CellBorderType.THIN;
//style1.BorderLeft = NPOI.HSSF.UserModel.CellBorderType.THIN;
//style1.BorderRight = NPOI.HSSF.UserModel.CellBorderType.THIN;
style1.Alignment = CellHorizontalAlignment.CENTER;
style1.VerticalAlignment = CellVerticalAlignment.CENTER;

//数据样式
HSSFCellStyle style3 = workbook.CreateCellStyle();
style3.Rotation = 90;
HSSFFont font3 = workbook.CreateFont();
font3.FontHeightInPoints = 10;
//font.Color=HSSFColor.RED.index;
font3.Boldweight = HSSFFont.BOLDWEIGHT_BOLD;
font3.FontName = "宋体";
style3.Alignment = CellHorizontalAlignment.CENTER;
style3.VerticalAlignment = CellVerticalAlignment.CENTER;
style3.SetFont(font3);
//表头样式
HSSFCellStyle style = workbook.CreateCellStyle();
style.BorderTop = NPOI.HSSF.UserModel.CellBorderType.THIN;
style.BorderBottom = NPOI.HSSF.UserModel.CellBorderType.THIN;
style.BorderLeft = NPOI.HSSF.UserModel.CellBorderType.THIN;
style.BorderRight = NPOI.HSSF.UserModel.CellBorderType.THIN;
HSSFFont font = workbook.CreateFont();
font.FontHeightInPoints = 20;
//font.Color=HSSFColor.RED.index;
font.Boldweight = HSSFFont.BOLDWEIGHT_BOLD;
font.FontName = "宋体";
style.Alignment = CellHorizontalAlignment.CENTER;
style.VerticalAlignment = CellVerticalAlignment.CENTER;
style.SetFont(font);

GridPanel gp;
string wordType;
GetGrid(out gp, out wordType);

List<ArtificialWeekOverhaulPlanEntity> weekPlanlist = new List<ArtificialWeekOverhaulPlanEntity>();
List<ArtificialWeekOverhaulPlanEntity> weekDeviceIdlist = new List<ArtificialWeekOverhaulPlanEntity>();

List<ArtificialDeviceYearOverhaulPlanEntity> monthPlanList = new List<ArtificialDeviceYearOverhaulPlanEntity>();
List<ArtificialDeviceYearOverhaulPlanEntity> monthDeviceIdList = new List<ArtificialDeviceYearOverhaulPlanEntity>();

List<ArtificialSeasonOverhaulPlanEntity> seasonPlanList = new List<ArtificialSeasonOverhaulPlanEntity>();
List<ArtificialSeasonOverhaulPlanEntity> deviceIdList = new List<ArtificialSeasonOverhaulPlanEntity>();
string type = Convert.ToString(select_type.SelectedItem.Text);//设备种类
string DeviceType = Inspect_box.SelectedItem.Text;//设备类别
#endregion
switch (wordType)
{
#region 周计划
case "周计划":

//weekPlanlist = ArtificialWeekPlanDomain.FindWeekBaoBiaoData("周计划", Convert.ToInt32(Convert.ToDateTime(week_year.Value.ToString()).Year), 0);
//weekDeviceIdlist = ArtificialWeekPlanDomain.FindWeekdeviceIdData(Convert.ToInt32(Convert.ToDateTime(week_year.Value.ToString()).Year), 0);
int lenzhou = 0;
int lenzhou1 = 0;
int zhouYear = Convert.ToDateTime(week_year.Value.ToString()).Year;
//一年的周数
int zhouSum = 54;

HeadcolumnName = "设备巡检周计划年度报表";
sheet = workbook.CreateSheet("统计报表");
sheet.AddMergedRegion(new CellRangeAddress(0, 2, 0, 9));
HSSFRow rowZhou = sheet.CreateRow(0);
HSSFCell cellZhou = rowZhou.CreateCell(0);
cellZhou.SetCellValue(HeadcolumnName);
cellZhou.CellStyle.Alignment = CellHorizontalAlignment.CENTER;
cellZhou.CellStyle.VerticalAlignment = CellVerticalAlignment.CENTER;
cellZhou.CellStyle = style;

for (int zhou = 1; zhou <= zhouSum + 1; zhou++)
{
List<ArtificialWeekOverhaulPlanEntity> listZhou = new List<ArtificialWeekOverhaulPlanEntity>();
List<ArtificialWeekOverhaulPlanEntity> listZhou1 = new List<ArtificialWeekOverhaulPlanEntity>();
int jhSum = 0;
int wcSum = 0;
int fsgzSum = 0;
int wcgzSum = 0;
int rowLenYue = 0;

if (zhou != zhouSum + 1)
{
if (zhou == 1)
{
listZhou = ArtificialWeekPlanDomain.FindWeekNianDuBaoBiaoData("周计划", zhouYear, zhou);
lenzhou = 3;
lenzhou1 = 3 + listZhou.Count() + zhou * 4 - 1;
rowLenYue = 6;
}
else
{
listZhou = ArtificialWeekPlanDomain.FindWeekNianDuBaoBiaoData("周计划", zhouYear, zhou);
listZhou1 = ArtificialWeekPlanDomain.FindWeekNianDuBaoBiaoData("周计划", zhouYear, zhou - 1);
lenzhou = 3 + listZhou1.Count() + (zhou - 1) * 4;
lenzhou1 = 3 + listZhou.Count() + zhou * 4 - 1;
rowLenYue = 6 + listZhou1.Count() + (zhou - 1) * 4;
}
weekPlanlist = ArtificialWeekPlanDomain.FindWeekBaoBiaoData("周计划", Convert.ToInt32(Convert.ToDateTime(week_year.Value.ToString()).Year), zhou);
weekDeviceIdlist = ArtificialWeekPlanDomain.FindWeekdeviceIdData(Convert.ToInt32(Convert.ToDateTime(week_year.Value.ToString()).Year), zhou);
}
else
{
weekPlanlist = ArtificialWeekPlanDomain.FindWeekBaoBiaoData("周计划", Convert.ToInt32(Convert.ToDateTime(week_year.Value.ToString()).Year), 0);
weekDeviceIdlist = ArtificialWeekPlanDomain.FindWeekdeviceIdData(Convert.ToInt32(Convert.ToDateTime(week_year.Value.ToString()).Year), 0);
listZhou = ArtificialWeekPlanDomain.FindWeekNianDuBaoBiaoData("周计划", zhouYear, zhou);
listZhou1 = ArtificialWeekPlanDomain.FindWeekNianDuBaoBiaoData("周计划", zhouYear, zhou);
lenzhou = 3 + listZhou1.Count() + (zhou - 1) * 4;
lenzhou1 = 3 + listZhou.Count() + zhou * 4 + weekPlanlist.Count() - 1;
rowLenYue = 6 + listZhou1.Count() + (zhou - 1) * 4;
}

HSSFRow row1 = sheet.CreateRow(lenzhou);

sheet.AddMergedRegion(new CellRangeAddress(lenzhou, lenzhou + 1, 2, 2));
HSSFCell row1Cell0 = row1.CreateCell(2);
row1Cell0.SetCellValue("项目设备分类");
row1Cell0.CellStyle = style1;

sheet.AddMergedRegion(new CellRangeAddress(lenzhou, lenzhou, 3, 4));
HSSFCell row1Cell9 = row1.CreateCell(3);
row1Cell9.SetCellValue("巡检");
row1Cell9.CellStyle = style1;

sheet.AddMergedRegion(new CellRangeAddress(lenzhou, lenzhou, 5, 6));
HSSFCell row1Cell13 = row1.CreateCell(5);
row1Cell13.SetCellValue("故障修");
row1Cell13.CellStyle = style1;

sheet.AddMergedRegion(new CellRangeAddress(lenzhou, lenzhou + 1, 7, 7));
HSSFCell row1Cell14 = row1.CreateCell(7);
row1Cell14.SetCellValue("设备质量分析");
row1Cell14.CellStyle = style1;

sheet.AddMergedRegion(new CellRangeAddress(lenzhou, lenzhou + 1, 8, 8));
HSSFCell row1Cell15 = row1.CreateCell(8);
row1Cell15.SetCellValue("设备变更情况");
row1Cell15.CellStyle = style1;

sheet.AddMergedRegion(new CellRangeAddress(lenzhou, lenzhou + 1, 9, 9));
HSSFCell row1Cell16 = row1.CreateCell(9);
row1Cell16.SetCellValue("备注");
row1Cell16.CellStyle = style1;

sheet.AddMergedRegion(new CellRangeAddress(lenzhou, lenzhou1, 0, 0));
HSSFCell row1Ce2 = row1.CreateCell(0);
row1Ce2.SetCellValue("设备巡检");
row1Ce2.CellStyle = style3;

sheet.AddMergedRegion(new CellRangeAddress(lenzhou, lenzhou1, 1, 1));
HSSFCell row1Ce3 = row1.CreateCell(1);

if (zhou == 55)
{
row1Ce3.SetCellValue("1-54周(全年)");
}
else
{
row1Ce3.SetCellValue("" + zhou + "周");
}
row1Ce3.CellStyle = style3;

string[] row2columns = new string[4] { "计划台/次", "完成台/次", "发生故障件/次", "完成故障件/次" };
HSSFRow row2 = sheet.CreateRow(lenzhou + 1);
for (int i = 0; i < row2columns.Length; i++)
{
sheet.AddMergedRegion(new CellRangeAddress(lenzhou + 1, lenzhou + 1, i + 3, i + 3));
HSSFCell row2Cell0 = row2.CreateCell(i + 3);
row2Cell0.SetCellValue(row2columns[i]);
row2Cell0.CellStyle = style1;
}

for (int i = 0; i < weekPlanlist.Count(); i++)//周计划
{
HSSFRow row = sheet.CreateRow(i + rowLenYue);//创建行号
ArtificialWeekOverhaulPlanEntity entity = weekPlanlist[i];

List<ArtificialWeekOverhaulPlanEntity> entityList = weekDeviceIdlist.Where(p => p.Type == entity.Type).ToList();

bx_infoDomain bx = new bx_infoDomain();
string startTime = "";
string endTime = "";
string deviceId = "";
for (int a = 0; a < entityList.Count(); a++)
{
if (a == entityList.Count() - 1)
{
deviceId += "'" + entityList[a].DeviceId + "'";
}
else
{
deviceId += "'" + entityList[a].DeviceId + "'" + ",";
}

}
DateTime mDatetime = new DateTime(Convert.ToInt32(Convert.ToDateTime(week_year.Value.ToString()).Year), 1, 1);//year为要求的那一年
if (zhou != 55)
{
startTime = mDatetime.AddDays((zhou - 1) * 7).ToString();//第N周第一天
endTime = mDatetime.AddDays((zhou - 1) * 7 + 6).ToString();//第N周最后一天
}
else
{
startTime = mDatetime.AddDays((1 - 1) * 7).ToString();
endTime = mDatetime.AddDays((54 - 1) * 7).ToString();
}

List<bx_infoEntity> ds = bx.getNumberByTimeNo(wordType, startTime, endTime, deviceId);
List<bx_infoEntity> dt = ds.Where(p => p.jindu == 4).ToList();

string[] array = new string[8];
array[0] = entity.Type;
array[1] = entity.sumCount;
array[2] = entity.wcCount;
array[3] = ds.Count().ToString();
array[4] = dt.Count().ToString();
array[5] = "";
array[6] = "";
array[7] = "";
for (int j = 0; j < array.Length; j++)
{
HSSFCell cell = row.CreateCell(j + 2);
cell.SetCellValue(array[j]);
cell.CellStyle = style1;
}

jhSum += Convert.ToInt32(entity.sumCount);
wcSum += Convert.ToInt32(entity.wcCount);
fsgzSum += ds.Count();
wcgzSum += dt.Count();
}

HSSFRow rowzhou = sheet.CreateRow(lenzhou1);//创建行号
string[] arrayzhou = new string[8];
arrayzhou[0] = "总计";
arrayzhou[1] = jhSum.ToString();
arrayzhou[2] = wcSum.ToString();
arrayzhou[3] = fsgzSum.ToString();
arrayzhou[4] = wcgzSum.ToString();
arrayzhou[5] = "";
arrayzhou[6] = "";
arrayzhou[7] = "";
for (int j = 0; j < arrayzhou.Length; j++)
{
HSSFCell cell = rowzhou.CreateCell(j + 2);
cell.SetCellValue(arrayzhou[j]);
cell.CellStyle = style1;
}

}
#endregion
break;
#region 月计划
case "月计划":
int lenyue = 0;
int lenyue1 = 0;
int YueYear = DateTime.Now.Year;
if (date_year.Value.ToString() != "0001/1/1 0:00:00" && date_year.Value != null)
{
YueYear = Convert.ToDateTime(date_year.Value.ToString()).Year;
}
string staYue = YueYear + "-01";
string endYue = "";
string endYue1 = "";
HeadcolumnName = "设备巡检月计划年度报表";
sheet = workbook.CreateSheet("统计报表");
sheet.AddMergedRegion(new CellRangeAddress(0, 2, 0, 9));
HSSFRow rowYue = sheet.CreateRow(0);
HSSFCell cellYue = rowYue.CreateCell(0);
cellYue.SetCellValue(HeadcolumnName);
cellYue.CellStyle.Alignment = CellHorizontalAlignment.CENTER;
cellYue.CellStyle.VerticalAlignment = CellVerticalAlignment.CENTER;
cellYue.CellStyle = style;
for (int ji = 1; ji <= 13; ji++)
{
List<ArtificialDeviceYearOverhaulPlanEntity> lstYue = new List<ArtificialDeviceYearOverhaulPlanEntity>();
List<ArtificialDeviceYearOverhaulPlanEntity> lstYue1 = new List<ArtificialDeviceYearOverhaulPlanEntity>();
if (ji != 13)
{
if (ji < 10)
{
endYue = YueYear + "-0" + ji + "";
}
else
{
endYue = YueYear + "-" + ji + "";
}
lstYue = ArtificialPlanDomain.GetNianduBaoBiaodataBySearch(staYue, endYue);
if (ji < 11)
{
endYue1 = YueYear + "-0" + (ji - 1) + "";

}
else
{
endYue1 = YueYear + "-" + (ji - 1) + "";
}
if (ji != 1)
{
lstYue1 = ArtificialPlanDomain.GetNianduBaoBiaodataBySearch(staYue, endYue1);
}
if (ji == 1)
{
lenyue = 3;
lenyue1 = 3 + lstYue.Count() + ji * 4 - 1;
}
else
{
lenyue = 3 + lstYue1.Count() + (ji - 1) * 4;
lenyue1 = 3 + lstYue.Count() + ji * 4 - 1;
}
}
else
{
lstYue = ArtificialPlanDomain.GetNianduBaoBiaodataBySearch(YueYear + "-01", YueYear + "-12");
lstYue1 = ArtificialPlanDomain.GetNianduBaoBiaodataBySearch(YueYear + "-01", YueYear + "-12");

monthPlanList = ArtificialPlanDomain.GetBaoBiaodataBySearch(YueYear + "-01", YueYear + "-12");

lenyue = 3 + lstYue1.Count() + (ji - 1) * 4;
lenyue1 = 3 + lstYue.Count() + ji * 4 + monthPlanList.Count() - 1;
}
#region 样式

HSSFRow row1 = sheet.CreateRow(lenyue);

sheet.AddMergedRegion(new CellRangeAddress(lenyue, lenyue + 1, 2, 2));
HSSFCell row1Cell0 = row1.CreateCell(2);
row1Cell0.SetCellValue("项目设备分类");
row1Cell0.CellStyle = style1;

sheet.AddMergedRegion(new CellRangeAddress(lenyue, lenyue, 3, 4));
HSSFCell row1Cell9 = row1.CreateCell(3);
row1Cell9.SetCellValue("巡检");
row1Cell9.CellStyle = style1;

sheet.AddMergedRegion(new CellRangeAddress(lenyue, lenyue, 5, 6));
HSSFCell row1Cell13 = row1.CreateCell(5);
row1Cell13.SetCellValue("故障修");
row1Cell13.CellStyle = style1;

sheet.AddMergedRegion(new CellRangeAddress(lenyue, lenyue + 1, 7, 7));
HSSFCell row1Cell14 = row1.CreateCell(7);
row1Cell14.SetCellValue("设备质量分析");
row1Cell14.CellStyle = style1;

sheet.AddMergedRegion(new CellRangeAddress(lenyue, lenyue + 1, 8, 8));
HSSFCell row1Cell15 = row1.CreateCell(8);
row1Cell15.SetCellValue("设备变更情况");
row1Cell15.CellStyle = style1;

sheet.AddMergedRegion(new CellRangeAddress(lenyue, lenyue + 1, 9, 9));
HSSFCell row1Cell16 = row1.CreateCell(9);
row1Cell16.SetCellValue("备注");
row1Cell16.CellStyle = style1;

sheet.AddMergedRegion(new CellRangeAddress(lenyue, lenyue1, 0, 0));
HSSFCell row1Ce2 = row1.CreateCell(0);
row1Ce2.SetCellValue("设备巡检");
row1Ce2.CellStyle = style3;

sheet.AddMergedRegion(new CellRangeAddress(lenyue, lenyue1, 1, 1));
HSSFCell row1Ce3 = row1.CreateCell(1);
if (ji == 13)
{
row1Ce3.SetCellValue("1-12月(全年)");
}
else
{
row1Ce3.SetCellValue("" + ji + "月");
}
row1Ce3.CellStyle = style3;

string[] row2columns = new string[4] { "计划台/次", "完成台/次", "发生故障件/次", "完成故障件/次" };
HSSFRow row2 = sheet.CreateRow(lenyue + 1);
for (int i = 0; i < row2columns.Length; i++)
{
sheet.AddMergedRegion(new CellRangeAddress(lenyue + 1, lenyue + 1, i + 3, i + 3));
HSSFCell row2Cell0 = row2.CreateCell(i + 3);
row2Cell0.SetCellValue(row2columns[i]);
row2Cell0.CellStyle = style1;
}
#endregion
#region 数据绑定
int rowLenYue = 0;
int jhSumYue = 0;
int wcSumYue = 0;
int fsgzSumYue = 0;
int wcgzSumYue = 0;
string startTime = "";
string endTime = "";

if (ji != 13)
{
if (ji < 10)
{
startTime = YueYear + "-0" + ji + "";
endTime = YueYear + "-0" + ji + "";
}
else
{
startTime = YueYear + "-" + ji + "";
endTime = YueYear + "-" + ji + "";
}
monthPlanList = ArtificialPlanDomain.GetBaoBiaodataBySearch(startTime, endTime);
monthDeviceIdList = ArtificialPlanDomain.GetDeviceiddataBySearch(startTime, endTime);

if (ji == 1)
{
rowLenYue = 6;
}
else
{
rowLenYue = 6 + lstYue1.Count() + (ji - 1) * 4;
}
}
else
{
monthPlanList = ArtificialPlanDomain.GetBaoBiaodataBySearch(YueYear + "-01", YueYear + "-12");
monthDeviceIdList = ArtificialPlanDomain.GetDeviceiddataBySearch(YueYear + "-01", YueYear + "-12");
rowLenYue = 6 + lstYue1.Count() + (ji - 1) * 4;
}

for (int i = 0; i < monthPlanList.Count(); i++)//月计划
{
HSSFRow row = sheet.CreateRow(i + rowLenYue);//创建行号
ArtificialDeviceYearOverhaulPlanEntity entity = monthPlanList[i];
List<ArtificialDeviceYearOverhaulPlanEntity> entityList = monthDeviceIdList.Where(p => p.Type == entity.Type).ToList();
bx_infoDomain bx = new bx_infoDomain();
string deviceId = "";

for (int a = 0; a < entityList.Count(); a++)
{
if (a == entityList.Count() - 1)
{
deviceId += "'" + entityList[a].DeviceId + "'";
}
else
{
deviceId += "'" + entityList[a].DeviceId + "'" + ",";
}

}

List<bx_infoEntity> ds = bx.getNumberByTimeNo(wordType, startTime, endTime, deviceId);
List<bx_infoEntity> dt = ds.Where(p => p.jindu == 4).ToList();

string[] array = new string[8];
array[0] = entity.Type;
array[1] = entity.sumCount;
array[2] = entity.wcCount;
array[3] = ds.Count().ToString();
array[4] = dt.Count().ToString();
array[5] = "";
array[6] = "";
array[7] = "";

for (int j = 0; j < array.Length; j++)
{
HSSFCell cell = row.CreateCell(j + 2);
cell.SetCellValue(array[j]);
cell.CellStyle = style1;
}

jhSumYue += Convert.ToInt32(entity.sumCount);
wcSumYue += Convert.ToInt32(entity.wcCount);
fsgzSumYue += ds.Count();
wcgzSumYue += dt.Count();
}

HSSFRow rowyue = sheet.CreateRow(lenyue1);//创建行号
string[] arrayyue = new string[8];
arrayyue[0] = "总计";
arrayyue[1] = jhSumYue.ToString();
arrayyue[2] = wcSumYue.ToString();
arrayyue[3] = fsgzSumYue.ToString();
arrayyue[4] = wcgzSumYue.ToString();
arrayyue[5] = "";
arrayyue[6] = "";
arrayyue[7] = "";
for (int j = 0; j < arrayyue.Length; j++)
{
HSSFCell cell = rowyue.CreateCell(j + 2);
cell.SetCellValue(arrayyue[j]);
cell.CellStyle = style1;
}

#endregion

}

#endregion
break;
#region 季计划
case "季计划":
seasonPlanList = ArtificialSeasonPlanDomain.FindSeasonPlanBaoBiaoData(Convert.ToDateTime(Date_Year_Season.Value).Year, "全部");
deviceIdList = ArtificialSeasonPlanDomain.FindSeasonDeviceIdData(Convert.ToDateTime(Date_Year_Season.Value).Year, "全部");

int jidu1 = ArtificialSeasonPlanDomain.FindSeasonPlanBaoBiaoData(Convert.ToDateTime(Date_Year_Season.Value).Year, "1").Count();
int jidu2 = ArtificialSeasonPlanDomain.FindSeasonPlanBaoBiaoData(Convert.ToDateTime(Date_Year_Season.Value).Year, "2").Count();
int jidu3 = ArtificialSeasonPlanDomain.FindSeasonPlanBaoBiaoData(Convert.ToDateTime(Date_Year_Season.Value).Year, "3").Count();
int jidu4 = ArtificialSeasonPlanDomain.FindSeasonPlanBaoBiaoData(Convert.ToDateTime(Date_Year_Season.Value).Year, "4").Count();

int len = 0;
int len1 = 0;

HeadcolumnName = "设备巡检季计划年度报表";
sheet = workbook.CreateSheet("统计报表");
sheet.AddMergedRegion(new CellRangeAddress(0, 2, 0, 9));
HSSFRow row0 = sheet.CreateRow(0);
HSSFCell cell0 = row0.CreateCell(0);
cell0.SetCellValue(HeadcolumnName);
cell0.CellStyle.Alignment = CellHorizontalAlignment.CENTER;
cell0.CellStyle.VerticalAlignment = CellVerticalAlignment.CENTER;
cell0.CellStyle = style;
for (int ji = 1; ji <= 5; ji++)
{
#region 第一季度

if (ji == 1)
{
len = 3;
len1 = 3 + jidu1 + ji * 4 - 1;
}
#endregion
#region 第二季度
if (ji == 2)
{
len = 3 + jidu1 + (ji - 1) * 4;
len1 = 3 + jidu1 + jidu2 + ji * 4 - 1;
}
#endregion
#region 第三季度
if (ji == 3)
{
len = 3 + jidu1 + jidu2 + (ji - 1) * 4;
len1 = 3 + jidu1 + jidu2 + jidu3 + ji * 4 - 1;
}
#endregion
#region 第四季度
if (ji == 4)
{
len = 3 + jidu1 + jidu2 + jidu3 + (ji - 1) * 4;
len1 = 3 + jidu1 + jidu2 + jidu3 + jidu4 + ji * 4 - 1;
}

#endregion
#region 全年

if (ji == 5)
{
len = 3 + jidu1 + jidu2 + jidu3 + jidu4 + (ji - 1) * 4;
len1 = 3 + jidu1 + jidu2 + jidu3 + jidu4 + ji * 4 + seasonPlanList.Count() - 1;
}
#endregion
#region 样式

HSSFRow row1 = sheet.CreateRow(len);

sheet.AddMergedRegion(new CellRangeAddress(len, len + 1, 2, 2));
HSSFCell row1Cell0 = row1.CreateCell(2);
row1Cell0.SetCellValue("项目设备分类");
row1Cell0.CellStyle = style1;

sheet.AddMergedRegion(new CellRangeAddress(len, len, 3, 4));
HSSFCell row1Cell9 = row1.CreateCell(3);
row1Cell9.SetCellValue("巡检");
row1Cell9.CellStyle = style1;

sheet.AddMergedRegion(new CellRangeAddress(len, len, 5, 6));
HSSFCell row1Cell13 = row1.CreateCell(5);
row1Cell13.SetCellValue("故障修");
row1Cell13.CellStyle = style1;

sheet.AddMergedRegion(new CellRangeAddress(len, len + 1, 7, 7));
HSSFCell row1Cell14 = row1.CreateCell(7);
row1Cell14.SetCellValue("设备质量分析");
row1Cell14.CellStyle = style1;

sheet.AddMergedRegion(new CellRangeAddress(len, len + 1, 8, 8));
HSSFCell row1Cell15 = row1.CreateCell(8);
row1Cell15.SetCellValue("设备变更情况");
row1Cell15.CellStyle = style1;

sheet.AddMergedRegion(new CellRangeAddress(len, len + 1, 9, 9));
HSSFCell row1Cell16 = row1.CreateCell(9);
row1Cell16.SetCellValue("备注");
row1Cell16.CellStyle = style1;

sheet.AddMergedRegion(new CellRangeAddress(len, len1, 0, 0));
HSSFCell row1Ce2 = row1.CreateCell(0);
row1Ce2.SetCellValue("设备巡检");
row1Ce2.CellStyle = style3;

sheet.AddMergedRegion(new CellRangeAddress(len, len1, 1, 1));
HSSFCell row1Ce3 = row1.CreateCell(1);
if (ji == 5)
{
row1Ce3.SetCellValue("1-4季度(全年)");
}
else
{
row1Ce3.SetCellValue("" + ji + "季度");
}
row1Ce3.CellStyle = style3;

string[] row2columns = new string[4] { "计划台/次", "完成台/次", "发生故障件/次", "完成故障件/次" };
HSSFRow row2 = sheet.CreateRow(len + 1);
for (int i = 0; i < row2columns.Length; i++)
{
sheet.AddMergedRegion(new CellRangeAddress(len + 1, len + 1, i + 3, i + 3));
HSSFCell row2Cell0 = row2.CreateCell(i + 3);
row2Cell0.SetCellValue(row2columns[i]);
row2Cell0.CellStyle = style1;
}
}
#endregion
#region 数据绑定
for (int ji = 1; ji <= 5; ji++)
{
#region 第一季度

if (ji == 1)
{
len = 3;
len1 = 3 + jidu1 + ji * 4;
}
#endregion
#region 第二季度
if (ji == 2)
{
len = 3 + jidu1 + (ji - 1) * 4;
len1 = 3 + jidu1 + jidu2 + ji * 4;
}
#endregion
#region 第三季度
if (ji == 3)
{
len = 3 + jidu1 + jidu2 + (ji - 1) * 4;
len1 = 3 + jidu1 + jidu2 + jidu3 + ji * 4;
}
#endregion
#region 第四季度
if (ji == 4)
{
len = 3 + jidu1 + jidu2 + jidu3 + (ji - 1) * 4;
len1 = 3 + jidu1 + jidu2 + jidu3 + jidu4 + ji * 4;
}

#endregion
#region 全年

if (ji == 5)
{
len = 3 + jidu1 + jidu2 + jidu3 + jidu4 + (ji - 1) * 4;
len1 = 3 + jidu1 + jidu2 + jidu3 + jidu4 + ji * 4 + seasonPlanList.Count();
}
#endregion

int rowLen = 0;
int jhSumji = 0;
int wcSumji = 0;
int fsgzSumji = 0;
int wcgzSumji = 0;
List<ArtificialSeasonOverhaulPlanEntity> lst = new List<ArtificialSeasonOverhaulPlanEntity>();
List<ArtificialSeasonOverhaulPlanEntity> dList = new List<ArtificialSeasonOverhaulPlanEntity>();
if (ji == 1)
{
lst = ArtificialSeasonPlanDomain.FindSeasonPlanBaoBiaoData(Convert.ToDateTime(Date_Year_Season.Value).Year, "1").ToList();
dList = deviceIdList.Where(p => p.Quarterly == "1").ToList();
rowLen = 6;
}
if (ji == 2)
{
lst = ArtificialSeasonPlanDomain.FindSeasonPlanBaoBiaoData(Convert.ToDateTime(Date_Year_Season.Value).Year, "2").ToList();
dList = deviceIdList.Where(p => p.Quarterly == "2").ToList();
rowLen = jidu1 + 4 + 6;
}
if (ji == 3)
{
lst = ArtificialSeasonPlanDomain.FindSeasonPlanBaoBiaoData(Convert.ToDateTime(Date_Year_Season.Value).Year, "3").ToList();
dList = deviceIdList.Where(p => p.Quarterly == "3").ToList();
rowLen = jidu1 + 4 + 6 + jidu2 + 4;
}
if (ji == 4)
{
lst = ArtificialSeasonPlanDomain.FindSeasonPlanBaoBiaoData(Convert.ToDateTime(Date_Year_Season.Value).Year, "4").ToList();
dList = deviceIdList.Where(p => p.Quarterly == "4").ToList();
rowLen = jidu1 + 4 + 6 + jidu2 + 4 + jidu3 + 4;
}
if (ji == 5)
{
lst = seasonPlanList.ToList();
dList = deviceIdList.ToList();
rowLen = jidu1 + 4 + 6 + jidu2 + 4 + jidu3 + 4 + seasonPlanList.Count() + 2;
}
for (int i = 0; i < lst.Count(); i++)//季计划
{
HSSFRow row = sheet.CreateRow(i + rowLen);//创建行号
ArtificialSeasonOverhaulPlanEntity entity = lst[i];
List<ArtificialSeasonOverhaulPlanEntity> entityList = dList.Where(p => p.Type == entity.Type).ToList();
bx_infoDomain bx = new bx_infoDomain();
string startTime = "";
string endTime = "";
string deviceId = "";
if (ji == 1)
{
startTime = Convert.ToDateTime(Date_Year_Season.Value).Year + "-" + "01-01";
endTime = Convert.ToDateTime(Date_Year_Season.Value).Year + "-" + "03-31";
}
else if (ji == 2)
{
startTime = Convert.ToDateTime(Date_Year_Season.Value).Year + "-" + "04-01";
endTime = Convert.ToDateTime(Date_Year_Season.Value).Year + "-" + "06-30";
}
else if (ji == 3)
{
startTime = Convert.ToDateTime(Date_Year_Season.Value).Year + "-" + "07-01";
endTime = Convert.ToDateTime(Date_Year_Season.Value).Year + "-" + "09-30";
}
else if (ji == 4)
{
startTime = Convert.ToDateTime(Date_Year_Season.Value).Year + "-" + "10-01";
endTime = Convert.ToDateTime(Date_Year_Season.Value).Year + "-" + "12-31";
}
else
{
startTime = Convert.ToDateTime(Date_Year_Season.Value).Year + "-" + "01-01";
endTime = Convert.ToDateTime(Date_Year_Season.Value).Year + "-" + "12-31";
}

for (int a = 0; a < entityList.Count(); a++)
{
if (a == entityList.Count() - 1)
{
deviceId += "'" + entityList[a].DeviceId + "'";
}
else
{
deviceId += "'" + entityList[a].DeviceId + "'" + ",";
}

}
List<bx_infoEntity> ds = bx.getNumberByTimeNo(wordType, startTime, endTime, deviceId);
List<bx_infoEntity> dt = ds.Where(p => p.jindu == 4).ToList();
string[] array = new string[8];
array[0] = entity.Type;
array[1] = entity.sumCount;
array[2] = entity.wcCount;
array[3] = ds.Count().ToString();
array[4] = dt.Count().ToString();
array[5] = "";
array[6] = "";
array[7] = "";

for (int j = 0; j < array.Length; j++)
{
HSSFCell cell = row.CreateCell(j + 2);
cell.SetCellValue(array[j]);
cell.CellStyle = style1;
}

jhSumji += Convert.ToInt32(entity.sumCount);
wcSumji += Convert.ToInt32(entity.wcCount);
fsgzSumji += ds.Count();
wcgzSumji += dt.Count();
}

HSSFRow row1 = sheet.CreateRow(len1 - 1);//创建行号
string[] array1 = new string[8];
array1[0] = "总计";
array1[1] = jhSumji.ToString();
array1[2] = wcSumji.ToString();
array1[3] = fsgzSumji.ToString();
array1[4] = wcgzSumji.ToString();
array1[5] = "";
array1[6] = "";
array1[7] = "";
for (int j = 0; j < array1.Length; j++)
{
HSSFCell cell = row1.CreateCell(j + 2);
cell.SetCellValue(array1[j]);
cell.CellStyle = style1;
}

}
#endregion
#endregion
break;
}

string strPath = "/Export/" + Guid.NewGuid() + ".xls";
string filePath = Server.MapPath(strPath);

//写入
MemoryStream ms = new MemoryStream();
workbook.Write(ms);
using (FileStream fs = new FileStream(filePath, FileMode.Create, FileAccess.Write))
{
byte[] bArr = ms.ToArray();
fs.Write(bArr, 0, bArr.Length);
fs.Flush();
}
FileInfo fileInfo = new FileInfo(filePath);
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=" + DateTime.Now.ToString("yyyy-MM-dd") + ".xls");//文件名
Response.AddHeader("content-length", fileInfo.Length.ToString());//文件大小
Response.ContentType = "application/octet-stream";
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.WriteFile(filePath);
}

转载于:https://www.cnblogs.com/niesiao/p/9342885.html

nopi 的使用记录相关推荐

  1. mysql建立联合索引,mysql建立唯一键,mysql如何解决重复记录联合索引

    在项目中,常常要用到联合唯一   在一些配置表中,一些列的组合成为一条记录.   比如,在游戏中,游戏的分区和用户id会形成一条记录.(比如,一个qq用户可以在艾欧尼亚.德玛西亚创建两个账号) 添加联 ...

  2. 实现 连续15签到记录_MySQL和Redis实现用户签到,你喜欢怎么实现?

    现在的网站和app开发中,签到是一个很常见的功能 如微博签到送积分,签到排行榜 微博签到 如移动app ,签到送流量等活动, 移动app签到 用户签到是提高用户粘性的有效手段,用的好能事半功倍! 下面 ...

  3. 记录一次http请求失败的问题分析

    问题背景 当前我有一个基于Flask编写的Restful服务,由于业务的需求,我需要将该服务打包成docker 镜像进行离线部署,原始服务的端口是在6661端口进行开启,为了区分,在docker中启动 ...

  4. Pytorch学习记录-torchtext和Pytorch的实例( 使用神经网络训练Seq2Seq代码)

    Pytorch学习记录-torchtext和Pytorch的实例1 0. PyTorch Seq2Seq项目介绍 1. 使用神经网络训练Seq2Seq 1.1 简介,对论文中公式的解读 1.2 数据预 ...

  5. LeetCode简单题之学生出勤记录 I

    题目 给你一个字符串 s 表示一个学生的出勤记录,其中的每个字符用来标记当天的出勤情况(缺勤.迟到.到场).记录中只含下面三种字符: 'A':Absent,缺勤 'L':Late,迟到 'P':Pre ...

  6. 关于TVM的点滴记录

    关于TVM的点滴记录

  7. MySql数据库Update批量更新与批量更新多条记录的不同值实现方法

    批量更新 mysql更新语句很简单,更新一条数据的某个字段,一般这样写: UPDATE mytable SET myfield = 'value' WHERE other_field = 'other ...

  8. 记录篇,自己在项目中使用过的。

    图片选择器,6.0已经适配过,类似qq空间上传 点击打开链接_胡小牧记录 下面是效果图: PictureSelector PhotoPicker 类似qq空间发布心情. 点击打开链接 BubbleSe ...

  9. HTML5与CSS3权威指南之CSS3学习记录

    title: HTML5与CSS3权威指南之CSS3学习记录 toc: true date: 2018-10-14 00:06:09 学习资料--<HTML5与CSS3权威指南>(第3版) ...

最新文章

  1. 关于line-height的一些理解
  2. 动态添加JavaScript
  3. VTK:可视化算法之CarotidFlowGlyphs
  4. 检索数据_18_按照多个字段排序查询结果
  5. NGINX轻松管理10万长连接
  6. maven的eclipse找不到本地仓库的的jar包
  7. pythoncopy函数_Python的shutil模块中文件的复制操作函数详解
  8. linux内核并发教程,修改Linux内核参数提高Nginx服务器并发性能
  9. 分布式存储系统Minio简介
  10. 拜托,面试别再问我TopK了!!!
  11. 关联分析中FPGrowth算法原理及实战
  12. 安卓手机怎么设置蓝牙耳机弹窗动画_AirPods Pro 搭配安卓一个月深度体验
  13. Entrez检索实例 - NCBI
  14. android apk安装包 华为提示安装包无效或与操作系统不兼容,魅族提示apk仅为测试版,要求下载正式版安装
  15. ThinkPHP 工作流设计
  16. 互联网大厂的如厕自由
  17. 天蝎项目整机柜服务器技术规格,天蝎项目整机柜服务器技术规范v1.01天蝎项目整机柜服务器技术规范v1.01.pdf...
  18. 《心经》经典段落及释义
  19. c开头英文语言,字母C开头的英文名
  20. 1080驱动此图形驱动程序_如何更新图形驱动程序以获得最佳游戏性能

热门文章

  1. Java NIO 选择器(Selector)的内部实现(poll epoll)
  2. 【php】windows安装PHP5.5+Apache2.4
  3. centos7 python3安装numpy_Centos7安装python3、numpy、scipy、matplotlib、pandas等
  4. body click js 委托_自动化测试之selenium调用JS语句
  5. HTML超文本描述语言,HTML超文本标记语言的介绍
  6. java客户服务器程序预约口罩_团队作业(二):Github实训:口罩预约
  7. vsftp匿名访问目录_vsftp 匿名访问设置设置
  8. python request timeout是什么意思_request timeout是什么意思
  9. 前端分页php,PHP分页类 – 前端开发,JQUERY特效,全栈开发,vue开发
  10. sql取最大值的那一行_从零学会SQL:SQL高级功能