使用NPOI中间件导出excel

NPOI插件使用
·安装NuGet包
选中工程右击——“管理NuGet程序包”,搜索安装“NPOI”

这是我从正式环境中copy的代码,有比较多的冗余,重复的代码比较多,具体实现比较简单。

	Guid guid = Guid.NewGuid();//用作文件名
	HSSFWorkbook book = new HSSFWorkbook();//添加一个表格
	//添加一张工作表(sheet)
	ISheet sheet1 = book.CreateSheet("Sheet1");
	//标题,单元格格式
	ICellStyle nameStyle = book.CreateCellStyle();
	nameStyle.VerticalAlignment = VerticalAlignment.Center;
	nameStyle.Alignment = HorizontalAlignment.Center;
	IFont fontName = null;//字体
	fontName = ExportManagementController.GetFontStyle(book, "宋体", 12, true);
	nameStyle.SetFont(fontName);

	//给sheet1添加第一行的头部标题
	IRow titleRow = sheet1.CreateRow(r++);//新建行,参数:行号
	ICell titleyCell = titleRow.CreateCell(0);//新建单元格,参数:列号
	titleyCell.SetCellValue("上海同济检测技术有限公司");//单元格内容
	titleyCell.CellStyle = nameStyle;//设置单元格格式

	IRow subtitleRow = sheet1.CreateRow(r++);
	ICell subtitleCell = subtitleRow.CreateCell(0);
	subtitleCell.SetCellValue(string.Format("项目成本费用明细表"));
	subtitleCell.CellStyle = nameStyle;

	subtitleRow = sheet1.CreateRow(r++);
	subtitleCell = subtitleRow.CreateCell(0);
	subtitleCell.SetCellValue(string.Format("合同编号:"+list[0].ContractCode));
	subtitleCell.CellStyle = nameStyle;
	subtitleCell = subtitleRow.CreateCell(7);
	subtitleCell.SetCellValue(string.Format("合同金额:" + list[0].ContractAmount));
	subtitleCell.CellStyle = nameStyle;

	subtitleRow = sheet1.CreateRow(r++);
	subtitleCell = subtitleRow.CreateCell(0);
	subtitleCell.SetCellValue(string.Format("项目名称:" + list[0].ContractName));
	subtitleCell.CellStyle = nameStyle;
	subtitleCell = subtitleRow.CreateCell(0);
	subtitleCell.SetCellValue(string.Format("项目负责人:" + list[0].LeaderName));
	subtitleCell.CellStyle = nameStyle;

	subtitleRow = sheet1.CreateRow(r++);
	subtitleCell = subtitleRow.CreateCell(0);
	subtitleCell.SetCellValue(string.Format("客户名称:" + list[0].PartyA));
	subtitleCell.CellStyle = nameStyle;
	#region 单元格格式
	IDataFormat dataFormatCustom = book.CreateDataFormat();
	ICellStyle footStyle = book.CreateCellStyle();
	footStyle.BorderBottom = BorderStyle.Thin;
	footStyle.BorderLeft = BorderStyle.Thin;
	footStyle.BorderRight = BorderStyle.Thin;
	footStyle.BorderTop = BorderStyle.Thin;
	footStyle.VerticalAlignment = VerticalAlignment.Center;
	footStyle.Alignment = HorizontalAlignment.Center;
	fontName = ExportManagementController.GetFontStyle(book, "宋体", 12, true);
	footStyle.SetFont(fontName);
	footStyle.DataFormat = dataFormatCustom.GetFormat("[>=10000000]##\\,##\\,##\\,##0;[>=100000] ##\\,##\\,##0;##,##0.00");
	//单元格格式
	ICellStyle contentStyle = book.CreateCellStyle();
	contentStyle.BorderBottom = BorderStyle.Thin;
	contentStyle.BorderLeft = BorderStyle.Thin;
	contentStyle.BorderRight = BorderStyle.Thin;
	contentStyle.BorderTop = BorderStyle.Thin;
	contentStyle.VerticalAlignment = VerticalAlignment.Center;
	contentStyle.Alignment = HorizontalAlignment.Center;
	contentStyle.WrapText = true;//设置换行这个要先设置
	contentStyle.SetFont(ExportManagementController.GetFontStyle(book, "宋体", 10, false));
	//单元格格式
	ICellStyle headerStyle = book.CreateCellStyle();
	headerStyle.BorderBottom = BorderStyle.Thin;
	headerStyle.BorderLeft = BorderStyle.Thin;
	headerStyle.BorderRight = BorderStyle.Thin;
	headerStyle.BorderTop = BorderStyle.Thin;
	headerStyle.VerticalAlignment = VerticalAlignment.Center;
	headerStyle.Alignment = HorizontalAlignment.Center;
	headerStyle.WrapText = true;//设置换行这个要先设置
	headerStyle.SetFont(ExportManagementController.GetFontStyle(book, "宋体", 10, false));
	headerStyle.DataFormat = dataFormatCustom.GetFormat("[>=10000000]##\\,##\\,##\\,##0;[>=100000] ##\\,##\\,##0;##,##0.00");//千位分格
	#endregion

	#region 合并单元格
	//参数 1:工作表 2:开始行号 3:结束行号 4:开始列号 5:结束列号 6:单元格格式
	ExportManagementController.SetCellRangeAddress(sheet1, 0, 0, 0, 10, nameStyle);
	ExportManagementController.SetCellRangeAddress(sheet1, 1, 1, 0, 10, nameStyle);
	ExportManagementController.SetCellRangeAddress(sheet1, 2, 2, 0, 6, nameStyle);
	ExportManagementController.SetCellRangeAddress(sheet1, 2, 2, 7, 10, nameStyle);
	ExportManagementController.SetCellRangeAddress(sheet1, 3, 3, 0, 6, nameStyle);
	ExportManagementController.SetCellRangeAddress(sheet1, 3, 3, 7, 10, nameStyle);
	ExportManagementController.SetCellRangeAddress(sheet1, 4, 4, 0, 10, nameStyle);
	ExportManagementController.SetCellRangeAddress(sheet1, 5, 5, 0, 2, contentStyle);

	ExportManagementController.SetCellRangeAddress(sheet1, 6, 36, 0, 0, contentStyle);
	ExportManagementController.SetCellRangeAddress(sheet1, 6, 13, 1, 1, contentStyle);
	ExportManagementController.SetCellRangeAddress(sheet1, 14, 21, 1, 1, contentStyle);
	ExportManagementController.SetCellRangeAddress(sheet1, 22, 35, 1, 1, contentStyle);
	ExportManagementController.SetCellRangeAddress(sheet1, 36, 36, 1, 2, contentStyle);

	ExportManagementController.SetCellRangeAddress(sheet1, 37, 53, 0, 0, contentStyle);
	ExportManagementController.SetCellRangeAddress(sheet1, 37, 49, 1, 1, contentStyle);
	ExportManagementController.SetCellRangeAddress(sheet1, 50, 52, 1, 1, contentStyle);
	ExportManagementController.SetCellRangeAddress(sheet1, 53, 53, 1, 2, contentStyle);

	ExportManagementController.SetCellRangeAddress(sheet1, 54, 63, 0, 0, contentStyle);
	ExportManagementController.SetCellRangeAddress(sheet1, 54, 57, 1, 1, contentStyle);
	//ExportManagementController.SetCellRangeAddress(sheet1, 58, 58, 1, 2, contentStyle);原小计

	ExportManagementController.SetCellRangeAddress(sheet1, 58, 62, 1, 1, contentStyle);
	ExportManagementController.SetCellRangeAddress(sheet1, 63, 63, 1, 2, contentStyle);

	ExportManagementController.SetCellRangeAddress(sheet1, 64, 64, 0, 2, contentStyle);



	#endregion

	#region 表格内容
	//费用类别
	ICell cell = null;
	IRow row1 = sheet1.CreateRow(r++);//新建行,参数:行号
	cell = row1.CreateCell(0);//新建单元格,参数:列号
	cell.SetCellValue("费用类别");//单元格内容
	cell.CellStyle = contentStyle;//单元格格式
	cell = row1.CreateCell(1);
	cell.CellStyle = contentStyle;
	cell = row1.CreateCell(2);
	cell.CellStyle = contentStyle;
	for (int i = 0; i < num; i++)
	{
		cell = row1.CreateCell(i + 3);
		cell.SetCellValue(list[i].DepartmentName);
		cell.CellStyle = contentStyle;
	}
	cell = row1.CreateCell(num + 3);
	cell.SetCellValue("合计");
	cell.CellStyle = contentStyle;
	//基本工资
	IRow row6 = sheet1.CreateRow(r++);
	cell = row6.CreateCell(0);
	cell.SetCellValue("人员费用");
	cell.CellStyle = contentStyle;
	cell = row6.CreateCell(1);
	cell.SetCellValue("人员工资");
	cell.CellStyle = contentStyle;
	cell = row6.CreateCell(2);
	cell.SetCellValue("基本工资");
	cell.CellStyle = contentStyle;
	for (int i = 0; i < num; i++)
	{
		cell = row6.CreateCell(i + 3);
		sum += (decimal)list[i].BasicSalary;
		cell.SetCellValue(list[i].BasicSalary?.ToString("N"));
		cell.CellStyle = contentStyle;
		sumArr[i] += (decimal)list[i].BasicSalary;
	}
	total += sum;
	cell = row6.CreateCell(num + 3);
	cell.SetCellValue(sum.ToString("N"));
	sum = 0;
	cell.CellStyle = contentStyle;
	

中间比较冗余部分

//岗位津贴
	IRow row7 = sheet1.CreateRow(r++);
	cell = row7.CreateCell(1);
	cell.CellStyle = contentStyle;
	cell = row7.CreateCell(2);
	cell.SetCellValue("岗位津贴");
	cell.CellStyle = contentStyle;
	for (int i = 0; i < num; i++)
	{
		cell = row7.CreateCell(i + 3);
		sum += (decimal)list[i].PostWage;
		cell.SetCellValue(list[i].PostWage?.ToString("N"));
		cell.CellStyle = contentStyle;
		sumArr[i] += (decimal)list[i].PostWage;
	}
	total += sum;
	cell = row7.CreateCell(num + 3);
	cell.SetCellValue(sum.ToString("N"));
	sum = 0;
	cell.CellStyle = contentStyle;
	//绩效奖励
	IRow row8 = sheet1.CreateRow(r++);
	cell = row8.CreateCell(1);
	cell.CellStyle = contentStyle;
	cell = row8.CreateCell(2);
	cell.SetCellValue("绩效奖励");
	cell.CellStyle = contentStyle;
	for (int i = 0; i < num; i++)
	{
		cell = row8.CreateCell(i + 3);
		sum += (decimal)list[i].PerformanceSalary;
		sumArr[i] += (decimal)list[i].PerformanceSalary;
		cell.SetCellValue(list[i].PerformanceSalary?.ToString("N"));
		cell.CellStyle = contentStyle;
	}
	total += sum;
	cell = row8.CreateCell(num + 3);
	cell.SetCellValue(sum.ToString("N"));
	sum = 0;
	cell.CellStyle = contentStyle;
	//交通补贴
	IRow row9 = sheet1.CreateRow(r++);
	cell = row9.CreateCell(1);
	cell.CellStyle = contentStyle;
	cell = row9.CreateCell(2);
	cell.SetCellValue("交通补贴");
	cell.CellStyle = contentStyle;
	for (int i = 0; i < num; i++)
	{
		cell = row9.CreateCell(i + 3);
		sum += (decimal)list[i].TrafficSubsidy;
		sumArr[i] += (decimal)list[i].TrafficSubsidy;
		cell.SetCellValue(list[i].TrafficSubsidy?.ToString("N"));
		cell.CellStyle = contentStyle;
	}
	total += sum;
	cell = row9.CreateCell(num + 3);
	cell.SetCellValue(sum.ToString("N"));
	sum = 0;
	cell.CellStyle = contentStyle;
	//独子补贴
	IRow row10 = sheet1.CreateRow(r++);
	cell = row10.CreateCell(1);
	cell.CellStyle = contentStyle;
	cell = row10.CreateCell(2);
	cell.SetCellValue("独子补贴");
	cell.CellStyle = contentStyle;
	for (int i = 0; i < num; i++)
	{
		cell = row10.CreateCell(i + 3);
		sum += (decimal)list[i].OnlyChildSubsidy;
		sumArr[i] += (decimal)list[i].OnlyChildSubsidy;
		cell.SetCellValue(list[i].OnlyChildSubsidy?.ToString("N"));
		cell.CellStyle = contentStyle;
	}
	total += sum;
	cell = row10.CreateCell(num + 3);
	cell.SetCellValue(sum.ToString("N"));
	sum = 0;
	cell.CellStyle = contentStyle;
	//高温补贴
	IRow row11 = sheet1.CreateRow(r++);
	cell = row11.CreateCell(1);
	cell.CellStyle = contentStyle;
	cell = row11.CreateCell(2);
	cell.SetCellValue("高温补贴");
	cell.CellStyle = contentStyle;
	for (int i = 0; i < num; i++)
	{
		cell = row11.CreateCell(i + 3);
		sum += (decimal)list[i].HighTempSubsidy;
		sumArr[i] += (decimal)list[i].HighTempSubsidy;
		cell.SetCellValue(list[i].HighTempSubsidy?.ToString("N"));
		cell.CellStyle = contentStyle;
	}
	total += sum;
	cell = row11.CreateCell(num + 3);
	cell.SetCellValue(sum.ToString("N"));
	sum = 0;
	cell.CellStyle = contentStyle;
	//通讯补贴
	IRow row12 = sheet1.CreateRow(r++);
	cell = row12.CreateCell(1);
	cell.CellStyle = contentStyle;
	cell = row12.CreateCell(2);
	cell.SetCellValue("通讯补贴");
	cell.CellStyle = contentStyle;
	for (int i = 0; i < num; i++)
	{
		cell = row12.CreateCell(i + 3);
		sum += (decimal)list[i].CommuSubsidy;
		sumArr[i] += (decimal)list[i].CommuSubsidy;
		cell.SetCellValue(list[i].CommuSubsidy?.ToString("N"));
		cell.CellStyle = contentStyle;
	}
	total += sum;
	cell = row12.CreateCell(num + 3);
	cell.SetCellValue(sum.ToString("N"));
	sum = 0;
	cell.CellStyle = contentStyle;
	//工龄工资
	IRow row13 = sheet1.CreateRow(r++);
	cell = row13.CreateCell(1);
	cell.CellStyle = contentStyle;
	cell = row13.CreateCell(2);
	cell.SetCellValue("工龄工资");
	cell.CellStyle = contentStyle;
	for (int i = 0; i < num; i++)
	{
		cell = row13.CreateCell(i + 3);
		sum += (decimal)list[i].WorkingYearSalary;
		sumArr[i] += (decimal)list[i].WorkingYearSalary;
		cell.SetCellValue(list[i].WorkingYearSalary?.ToString("N"));
		cell.CellStyle = contentStyle;
	}
	total += sum;
	cell = row13.CreateCell(num + 3);
	cell.SetCellValue(sum.ToString("N"));
	sum = 0;
	cell.CellStyle = contentStyle;

	//基本工资
	IRow row14 = sheet1.CreateRow(r++);
	cell = row14.CreateCell(1);
	cell.SetCellValue("聘用费用");
	cell.CellStyle = contentStyle;
	cell = row14.CreateCell(2);
	cell.SetCellValue("基本工资");
	cell.CellStyle = contentStyle;
	for (int i = 0; i < num; i++)
	{
		cell = row14.CreateCell(i + 3);
		sum += (decimal)list[i].BasicSalary2;
		cell.SetCellValue(list[i].BasicSalary2?.ToString("N"));
		cell.CellStyle = contentStyle;
		sumArr[i] += (decimal)list[i].BasicSalary2;
	}
	total += sum;
	cell = row14.CreateCell(num + 3);
	cell.SetCellValue(sum.ToString("N"));
	sum = 0;
	cell.CellStyle = contentStyle;
	//岗位津贴
	IRow row15 = sheet1.CreateRow(r++);
	cell = row15.CreateCell(1);
	cell.CellStyle = contentStyle;
	cell = row15.CreateCell(2);
	cell.SetCellValue("岗位津贴");
	cell.CellStyle = contentStyle;
	for (int i = 0; i < num; i++)
	{
		cell = row15.CreateCell(i + 3);
		sum += (decimal)list[i].PostWage2;
		cell.SetCellValue(list[i].PostWage2?.ToString("N"));
		cell.CellStyle = contentStyle;
		sumArr[i] += (decimal)list[i].PostWage2;
	}
	total += sum;
	cell = row15.CreateCell(num + 3);
	cell.SetCellValue(sum.ToString("N"));
	sum = 0;
	cell.CellStyle = contentStyle;
	//绩效奖励
	IRow row16 = sheet1.CreateRow(r++);
	cell = row16.CreateCell(1);
	cell.CellStyle = contentStyle;
	cell = row16.CreateCell(2);
	cell.SetCellValue("绩效奖励");
	cell.CellStyle = contentStyle;
	for (int i = 0; i < num; i++)
	{
		cell = row16.CreateCell(i + 3);
		sum += (decimal)list[i].PerformanceSalary2;
		sumArr[i] += (decimal)list[i].PerformanceSalary2;
		cell.SetCellValue(list[i].PerformanceSalary2?.ToString("N"));
		cell.CellStyle = contentStyle;
	}
	total += sum;
	cell = row16.CreateCell(num + 3);
	cell.SetCellValue(sum.ToString("N"));
	sum = 0;
	cell.CellStyle = contentStyle;
	//交通补贴
	IRow row17 = sheet1.CreateRow(r++);
	cell = row17.CreateCell(1);
	cell.CellStyle = contentStyle;
	cell = row17.CreateCell(2);
	cell.SetCellValue("交通补贴");
	cell.CellStyle = contentStyle;
	for (int i = 0; i < num; i++)
	{
		cell = row17.CreateCell(i + 3);
		sum += (decimal)list[i].TrafficSubsidy2;
		sumArr[i] += (decimal)list[i].TrafficSubsidy2;
		cell.SetCellValue(list[i].TrafficSubsidy2?.ToString("N"));
		cell.CellStyle = contentStyle;
	}
	total += sum;
	cell = row17.CreateCell(num + 3);
	cell.SetCellValue(sum.ToString("N"));
	sum = 0;
	cell.CellStyle = contentStyle;
	//独子补贴
	IRow row18 = sheet1.CreateRow(r++);
	cell = row18.CreateCell(1);
	cell.CellStyle = contentStyle;
	cell = row18.CreateCell(2);
	cell.SetCellValue("独子补贴");
	cell.CellStyle = contentStyle;
	for (int i = 0; i < num; i++)
	{
		cell = row18.CreateCell(i + 3);
		sum += (decimal)list[i].OnlyChildSubsidy2;
		sumArr[i] += (decimal)list[i].OnlyChildSubsidy2;
		cell.SetCellValue(list[i].OnlyChildSubsidy2?.ToString("N"));
		cell.CellStyle = contentStyle;
	}
	total += sum;
	cell = row18.CreateCell(num + 3);
	cell.SetCellValue(sum.ToString("N"));
	sum = 0;
	cell.CellStyle = contentStyle;
	//高温补贴
	IRow row19 = sheet1.CreateRow(r++);
	cell = row19.CreateCell(1);
	cell.CellStyle = contentStyle;
	cell = row19.CreateCell(2);
	cell.SetCellValue("高温补贴");
	cell.CellStyle = contentStyle;
	for (int i = 0; i < num; i++)
	{
		cell = row19.CreateCell(i + 3);
		sum += (decimal)list[i].HighTempSubsidy2;
		sumArr[i] += (decimal)list[i].HighTempSubsidy2;
		cell.SetCellValue(list[i].HighTempSubsidy2?.ToString("N"));
		cell.CellStyle = contentStyle;
	}
	total += sum;
	cell = row19.CreateCell(num + 3);
	cell.SetCellValue(sum.ToString("N"));
	sum = 0;
	cell.CellStyle = contentStyle;
	//通讯补贴
	IRow row20 = sheet1.CreateRow(r++);
	cell = row20.CreateCell(1);
	cell.CellStyle = contentStyle;
	cell = row20.CreateCell(2);
	cell.SetCellValue("通讯补贴");
	cell.CellStyle = contentStyle;
	for (int i = 0; i < num; i++)
	{
		cell = row20.CreateCell(i + 3);
		sum += (decimal)list[i].CommuSubsidy2;
		sumArr[i] += (decimal)list[i].CommuSubsidy2;
		cell.SetCellValue(list[i].CommuSubsidy2?.ToString("N"));
		cell.CellStyle = contentStyle;
	}
	total += sum;
	cell = row20.CreateCell(num + 3);
	cell.SetCellValue(sum.ToString("N"));
	sum = 0;
	cell.CellStyle = contentStyle;
	//工龄工资
	IRow row21 = sheet1.CreateRow(r++);
	cell = row21.CreateCell(1);
	cell.CellStyle = contentStyle;
	cell = row21.CreateCell(2);
	cell.SetCellValue("工龄工资");
	cell.CellStyle = contentStyle;
	for (int i = 0; i < num; i++)
	{
		cell = row21.CreateCell(i + 3);
		sum += (decimal)list[i].WorkingYearSalary2;
		sumArr[i] += (decimal)list[i].WorkingYearSalary2;
		cell.SetCellValue(list[i].WorkingYearSalary2?.ToString("N"));
		cell.CellStyle = contentStyle;
	}
	total += sum;
	cell = row21.CreateCell(num + 3);
	cell.SetCellValue(sum.ToString("N"));
	sum = 0;
	cell.CellStyle = contentStyle;
	//养老保险金
	IRow row22 = sheet1.CreateRow(r++);
	cell = row22.CreateCell(1);
	cell.SetCellValue("社保费用");
	cell.CellStyle = contentStyle;
	cell = row22.CreateCell(2);
	cell.SetCellValue("养老保险金");
	cell.CellStyle = contentStyle;
	for (int i = 0; i < num; i++)
	{
		cell = row22.CreateCell(i + 3);
		sum += (decimal)list[i].EndowmentInsurance;
		cell.SetCellValue(list[i].EndowmentInsurance?.ToString("N"));
		cell.CellStyle = contentStyle;
		sumArr[i] += (decimal)list[i].EndowmentInsurance;
	}
	total += sum;
	cell = row22.CreateCell(num + 3);
	cell.SetCellValue(sum.ToString("N"));
	sum = 0;
	cell.CellStyle = contentStyle;
	//医疗保险金
	IRow row23 = sheet1.CreateRow(r++);
	cell = row23.CreateCell(1);
	cell.CellStyle = contentStyle;
	cell = row23.CreateCell(2);
	cell.SetCellValue("医疗保险金");
	cell.CellStyle = contentStyle;
	for (int i = 0; i < num; i++)
	{
		cell = row23.CreateCell(i + 3);
		sum += (decimal)list[i].MedicalInsurance;
		cell.SetCellValue(list[i].MedicalInsurance?.ToString("N"));
		cell.CellStyle = contentStyle;
		sumArr[i] += (decimal)list[i].MedicalInsurance;
	}
	total += sum;
	cell = row23.CreateCell(num + 3);
	cell.SetCellValue(sum.ToString("N"));
	sum = 0;
	cell.CellStyle = contentStyle;
	//失业保险金
	IRow row24 = sheet1.CreateRow(r++);
	cell = row24.CreateCell(1);
	cell.CellStyle = contentStyle;
	cell = row24.CreateCell(2);
	cell.SetCellValue("失业保险金");
	cell.CellStyle = contentStyle;
	for (int i = 0; i < num; i++)
	{
		cell = row24.CreateCell(i + 3);
		sum += (decimal)list[i].UnEmploylInsurance;
		cell.SetCellValue(list[i].UnEmploylInsurance?.ToString("N"));
		cell.CellStyle = contentStyle;
		sumArr[i] += (decimal)list[i].UnEmploylInsurance;
	}
	total += sum;
	cell = row24.CreateCell(num + 3);
	cell.SetCellValue(sum.ToString("N"));
	sum = 0;
	cell.CellStyle = contentStyle;
	//工伤保险金
	IRow row25 = sheet1.CreateRow(r++);
	cell = row25.CreateCell(1);
	cell.CellStyle = contentStyle;
	cell = row25.CreateCell(2);
	cell.SetCellValue("工伤保险金");
	cell.CellStyle = contentStyle;
	for (int i = 0; i < num; i++)
	{
		cell = row25.CreateCell(i + 3);
		sum += (decimal)list[i].EmployInjuryInsurance;
		cell.SetCellValue(list[i].EmployInjuryInsurance?.ToString("N"));
		cell.CellStyle = contentStyle;
		sumArr[i] += (decimal)list[i].EmployInjuryInsurance;
	}
	total += sum;
	cell = row25.CreateCell(num + 3);
	cell.SetCellValue(sum.ToString("N"));
	sum = 0;
	cell.CellStyle = contentStyle;
	//生育保险金
	IRow row26 = sheet1.CreateRow(r++);
	cell = row26.CreateCell(1);
	cell.CellStyle = contentStyle;
	cell = row26.CreateCell(2);
	cell.SetCellValue("生育保险金");
	cell.CellStyle = contentStyle;
	for (int i = 0; i < num; i++)
	{
		cell = row26.CreateCell(i + 3);
		sum += (decimal)list[i].MaternityInsurance;
		cell.SetCellValue(list[i].MaternityInsurance?.ToString("N"));
		cell.CellStyle = contentStyle;
		sumArr[i] += (decimal)list[i].MaternityInsurance;
	}
	total += sum;
	cell = row26.CreateCell(num + 3);
	cell.SetCellValue(sum.ToString("N"));
	sum = 0;
	cell.CellStyle = contentStyle;
	//欠薪保险金
	IRow row27 = sheet1.CreateRow(r++);
	cell = row27.CreateCell(1);
	cell.CellStyle = contentStyle;
	cell = row27.CreateCell(2);
	cell.SetCellValue("欠薪保险金");
	cell.CellStyle = contentStyle;
	for (int i = 0; i < num; i++)
	{
		cell = row27.CreateCell(i + 3);
		sum += (decimal)list[i].PayArrears;
		cell.SetCellValue(list[i].PayArrears?.ToString("N"));
		cell.CellStyle = contentStyle;
		sumArr[i] += (decimal)list[i].PayArrears;
	}
	total += sum;
	cell = row27.CreateCell(num + 3);
	cell.SetCellValue(sum.ToString("N"));
	sum = 0;
	cell.CellStyle = contentStyle;
	//残疾金
	IRow row28 = sheet1.CreateRow(r++);
	cell = row28.CreateCell(1);
	cell.CellStyle = contentStyle;
	cell = row28.CreateCell(2);
	cell.SetCellValue("残疾金");
	cell.CellStyle = contentStyle;
	for (int i = 0; i < num; i++)
	{
		cell = row28.CreateCell(i + 3);
		sum += (decimal)list[i].DisabilityPayment;
		cell.SetCellValue(list[i].DisabilityPayment?.ToString("N"));
		cell.CellStyle = contentStyle;
		sumArr[i] += (decimal)list[i].DisabilityPayment;
	}
	total += sum;
	cell = row28.CreateCell(num + 3);
	cell.SetCellValue(sum.ToString("N"));
	sum = 0;
	cell.CellStyle = contentStyle;
	//年金
	IRow row29 = sheet1.CreateRow(r++);
	cell = row29.CreateCell(1);
	cell.CellStyle = contentStyle;
	cell = row29.CreateCell(2);
	cell.SetCellValue("年金");
	cell.CellStyle = contentStyle;
	for (int i = 0; i < num; i++)
	{
		cell = row29.CreateCell(i + 3);
		sum += (decimal)list[i].YearPayment;
		cell.SetCellValue(list[i].YearPayment?.ToString("N"));
		cell.CellStyle = contentStyle;
		sumArr[i] += (decimal)list[i].YearPayment;
	}
	total += sum;
	cell = row29.CreateCell(num + 3);
	cell.SetCellValue(sum.ToString("N"));
	sum = 0;
	cell.CellStyle = contentStyle;
	//公积金
	IRow row30 = sheet1.CreateRow(r++);
	cell = row30.CreateCell(1);
	cell.CellStyle = contentStyle;
	cell = row30.CreateCell(2);
	cell.SetCellValue("公积金");
	cell.CellStyle = contentStyle;
	for (int i = 0; i < num; i++)
	{
		cell = row30.CreateCell(i + 3);
		sum += (decimal)list[i].AccumulationFund;
		cell.SetCellValue(list[i].AccumulationFund?.ToString("N"));
		cell.CellStyle = contentStyle;
		sumArr[i] += (decimal)list[i].AccumulationFund;
	}
	total += sum;
	cell = row30.CreateCell(num + 3);
	cell.SetCellValue(sum.ToString("N"));
	sum = 0;
	cell.CellStyle = contentStyle;
	//劳务
	IRow row31 = sheet1.CreateRow(r++);
	cell = row31.CreateCell(1);
	cell.CellStyle = contentStyle;
	cell = row31.CreateCell(2);
	cell.SetCellValue("劳务");
	cell.CellStyle = contentStyle;
	for (int i = 0; i < num; i++)
	{
		cell = row31.CreateCell(i + 3);
		sum += (decimal)list[i].LaborPayment;
		cell.SetCellValue(list[i].LaborPayment?.ToString("N"));
		cell.CellStyle = contentStyle;
		sumArr[i] += (decimal)list[i].LaborPayment;
	}
	total += sum;
	cell = row31.CreateCell(num + 3);
	cell.SetCellValue(sum.ToString("N"));
	sum = 0;
	cell.CellStyle = contentStyle;
	//劳务酬金
	IRow row32 = sheet1.CreateRow(r++);
	cell = row32.CreateCell(1);
	cell.CellStyle = contentStyle;
	cell = row32.CreateCell(2);
	cell.SetCellValue("劳务酬金");
	cell.CellStyle = contentStyle;
	for (int i = 0; i < num; i++)
	{
		cell = row32.CreateCell(i + 3);
		sum += (decimal)list[i].LaborRemuneration;
		cell.SetCellValue(list[i].LaborRemuneration.ToString("N"));
		cell.CellStyle = contentStyle;
		sumArr[i] += list[i].LaborRemuneration;
	}
	total += sum;
	cell = row32.CreateCell(num + 3);
	cell.SetCellValue(sum.ToString("N"));
	sum = 0;
	cell.CellStyle = contentStyle;
	//职工福利
	IRow row33 = sheet1.CreateRow(r++);
	cell = row33.CreateCell(1);
	cell.CellStyle = contentStyle;
	cell = row33.CreateCell(2);
	cell.SetCellValue("职工福利");
	cell.CellStyle = contentStyle;
	for (int i = 0; i < num; i++)
	{
		cell = row33.CreateCell(i + 3);
		sum += (decimal)list[i].EmployeeBenefits;
		cell.SetCellValue(list[i].EmployeeBenefits.ToString("N"));
		cell.CellStyle = contentStyle;
		sumArr[i] += list[i].EmployeeBenefits;
	}
	total += sum;
	cell = row33.CreateCell(num + 3);
	cell.SetCellValue(sum.ToString("N"));
	sum = 0;
	cell.CellStyle = contentStyle;
	//职工培训
	IRow row34 = sheet1.CreateRow(r++);
	cell = row34.CreateCell(1);
	cell.CellStyle = contentStyle;
	cell = row34.CreateCell(2);
	cell.SetCellValue("职工培训");
	cell.CellStyle = contentStyle;
	for (int i = 0; i < num; i++)
	{
		cell = row34.CreateCell(i + 3);
		sum += (decimal)list[i].WorkersTraining;
		cell.SetCellValue(list[i].WorkersTraining.ToString("N"));
		cell.CellStyle = contentStyle;
		sumArr[i] += list[i].WorkersTraining;
	}
	total += sum;
	cell = row34.CreateCell(num + 3);
	cell.SetCellValue(sum.ToString("N"));
	sum = 0;
	cell.CellStyle = contentStyle;
	//劳动防护费用
	IRow row35 = sheet1.CreateRow(r++);
	cell = row35.CreateCell(1);
	cell.CellStyle = contentStyle;
	cell = row35.CreateCell(2);
	cell.SetCellValue("劳动防护费用");
	cell.CellStyle = contentStyle;
	for (int i = 0; i < num; i++)
	{
		cell = row35.CreateCell(i + 3);
		sum += (decimal)list[i].LaborProtection;
		cell.SetCellValue(list[i].LaborProtection.ToString("N"));
		cell.CellStyle = contentStyle;
		sumArr[i] += list[i].LaborProtection;
	}
	total += sum;
	cell = row35.CreateCell(num + 3);
	cell.SetCellValue(sum.ToString("N"));
	sum = 0;
	cell.CellStyle = contentStyle;
	//小计
	IRow row36 = sheet1.CreateRow(r++);
	cell = row36.CreateCell(1);
	cell.SetCellValue("小计");
	cell.CellStyle = contentStyle;
	for (int i = 0; i < num; i++)
	{
		cell = row36.CreateCell(i + 3);
		cell.SetCellValue(sumArr[i].ToString("N"));
		cell.CellStyle = contentStyle;
	}
	cell = row36.CreateCell(num + 3);
	cell.SetCellValue(total.ToString("N"));
	cell.CellStyle = contentStyle;
	sum = 0;
	projectSum[num] += total;
	total = 0;//总计清零
	for (int i = 0; i < num; i++)
	{
		projectSum[i] += sumArr[i];
		sumArr[i] = 0;
	}
	//业务费用
	IRow row37 = sheet1.CreateRow(r++);
	cell = row37.CreateCell(0);
	cell.SetCellValue("业务费用");
	cell.CellStyle = contentStyle;
	cell = row37.CreateCell(1);
	cell.SetCellValue("业务费用");
	cell.CellStyle = contentStyle;
	cell = row37.CreateCell(2);
	cell.SetCellValue("工程款");
	cell.CellStyle = contentStyle;
	for (int i = 0; i < num; i++)
	{
		cell = row37.CreateCell(i + 3);
		sum += (decimal)list[i].ProjectFunds;
		cell.SetCellValue(list[i].ProjectFunds.ToString("N"));
		cell.CellStyle = contentStyle;
		sumArr[i] += list[i].ProjectFunds;
	}
	total += sum;
	cell = row37.CreateCell(num + 3);
	cell.SetCellValue(sum.ToString("N"));
	sum = 0;
	cell.CellStyle = contentStyle;
	//办公费
	IRow row38 = sheet1.CreateRow(r++);
	cell = row38.CreateCell(1);
	cell.CellStyle = contentStyle;
	cell = row38.CreateCell(2);
	cell.SetCellValue("办公费");
	cell.CellStyle = contentStyle;
	for (int i = 0; i < num; i++)
	{
		cell = row38.CreateCell(i + 3);
		sum += (decimal)list[i].OfficeExpenses;
		cell.SetCellValue(list[i].OfficeExpenses.ToString("N"));
		cell.CellStyle = contentStyle;
		sumArr[i] += list[i].OfficeExpenses;
	}
	total += sum;
	cell = row38.CreateCell(num + 3);
	cell.SetCellValue(sum.ToString("N"));
	sum = 0;
	cell.CellStyle = contentStyle;
	//项目耗材
	IRow row39 = sheet1.CreateRow(r++);
	cell = row39.CreateCell(1);
	cell.CellStyle = contentStyle;
	cell = row39.CreateCell(2);
	cell.SetCellValue("项目耗材");
	cell.CellStyle = contentStyle;
	for (int i = 0; i < num; i++)
	{
		cell = row39.CreateCell(i + 3);
		sum += (decimal)list[i].ProjectConsumables;
		cell.SetCellValue(list[i].ProjectConsumables.ToString("N"));
		cell.CellStyle = contentStyle;
		sumArr[i] += list[i].ProjectConsumables;
	}
	total += sum;
	cell = row39.CreateCell(num + 3);
	cell.SetCellValue(sum.ToString("N"));
	sum = 0;
	cell.CellStyle = contentStyle;
	//资料费
	IRow row40 = sheet1.CreateRow(r++);
	cell = row40.CreateCell(1);
	cell.CellStyle = contentStyle;
	cell = row40.CreateCell(2);
	cell.SetCellValue("资料费");
	cell.CellStyle = contentStyle;
	for (int i = 0; i < num; i++)
	{
		cell = row40.CreateCell(i + 3);
		sum += (decimal)list[i].InformationFee;
		cell.SetCellValue(list[i].InformationFee.ToString("N"));
		cell.CellStyle = contentStyle;
		sumArr[i] += list[i].InformationFee;
	}
	total += sum;
	cell = row40.CreateCell(num + 3);
	cell.SetCellValue(sum.ToString("N"));
	sum = 0;
	cell.CellStyle = contentStyle;
	//通讯费用
	IRow row41 = sheet1.CreateRow(r++);
	cell = row41.CreateCell(1);
	cell.CellStyle = contentStyle;
	cell = row41.CreateCell(2);
	cell.SetCellValue("通讯费用");
	cell.CellStyle = contentStyle;
	for (int i = 0; i < num; i++)
	{
		cell = row41.CreateCell(i + 3);
		sum += (decimal)list[i].CorrespondenceFee;
		cell.SetCellValue(list[i].CorrespondenceFee.ToString("N"));
		cell.CellStyle = contentStyle;
		sumArr[i] += list[i].CorrespondenceFee;
	}
	total += sum;
	cell = row41.CreateCell(num + 3);
	cell.SetCellValue(sum.ToString("N"));
	sum = 0;
	cell.CellStyle = contentStyle;
	//会费
	IRow row42 = sheet1.CreateRow(r++);
	cell = row42.CreateCell(1);
	cell.CellStyle = contentStyle;
	cell = row42.CreateCell(2);
	cell.SetCellValue("会费");
	cell.CellStyle = contentStyle;
	for (int i = 0; i < num; i++)
	{
		cell = row42.CreateCell(i + 3);
		sum += (decimal)list[i].MembershipFees;
		cell.SetCellValue(list[i].MembershipFees.ToString("N"));
		cell.CellStyle = contentStyle;
		sumArr[i] += list[i].MembershipFees;
	}
	total += sum;
	cell = row42.CreateCell(num + 3);
	cell.SetCellValue(sum.ToString("N"));
	sum = 0;
	cell.CellStyle = contentStyle;
	//招待费
	IRow row43 = sheet1.CreateRow(r++);
	cell = row43.CreateCell(1);
	cell.CellStyle = contentStyle;
	cell = row43.CreateCell(2);
	cell.SetCellValue("招待费");
	cell.CellStyle = contentStyle;
	for (int i = 0; i < num; i++)
	{
		cell = row43.CreateCell(i + 3);
		sum += (decimal)list[i].EntertainmentExpenses;
		cell.SetCellValue(list[i].EntertainmentExpenses.ToString("N"));
		cell.CellStyle = contentStyle;
		sumArr[i] += list[i].EntertainmentExpenses;
	}
	total += sum;
	cell = row43.CreateCell(num + 3);
	cell.SetCellValue(sum.ToString("N"));
	sum = 0;
	cell.CellStyle = contentStyle;
	//企业所得税
	IRow row44 = sheet1.CreateRow(r++);
	cell = row44.CreateCell(1);
	cell.CellStyle = contentStyle;
	cell = row44.CreateCell(2);
	cell.SetCellValue("企业所得税");
	cell.CellStyle = contentStyle;
	for (int i = 0; i < num; i++)
	{
		cell = row44.CreateCell(i + 3);
		sum += (decimal)list[i].CorporateIncomeTax;
		cell.SetCellValue(list[i].CorporateIncomeTax.ToString("N"));
		cell.CellStyle = contentStyle;
		sumArr[i] += list[i].CorporateIncomeTax;
	}
	total += sum;
	cell = row44.CreateCell(num + 3);
	cell.SetCellValue(sum.ToString("N"));
	sum = 0;
	cell.CellStyle = contentStyle;
	//无形资产摊销
	IRow row45 = sheet1.CreateRow(r++);
	cell = row45.CreateCell(1);
	cell.CellStyle = contentStyle;
	cell = row45.CreateCell(2);
	cell.SetCellValue("无形资产摊销");
	cell.CellStyle = contentStyle;
	for (int i = 0; i < num; i++)
	{
		cell = row45.CreateCell(i + 3);
		sum += (decimal)list[i].AssetsAmortization;
		cell.SetCellValue(list[i].AssetsAmortization.ToString("N"));
		cell.CellStyle = contentStyle;
		sumArr[i] += list[i].AssetsAmortization;
	}
	total += sum;
	cell = row45.CreateCell(num + 3);
	cell.SetCellValue(sum.ToString("N"));
	sum = 0;
	cell.CellStyle = contentStyle;
	//研究费用
	IRow row46 = sheet1.CreateRow(r++);
	cell = row46.CreateCell(1);
	cell.CellStyle = contentStyle;
	cell = row46.CreateCell(2);
	cell.SetCellValue("研究费用");
	cell.CellStyle = contentStyle;
	for (int i = 0; i < num; i++)
	{
		cell = row46.CreateCell(i + 3);
		sum += (decimal)list[i].ResearchExpenditure;
		cell.SetCellValue(list[i].ResearchExpenditure.ToString("N"));
		cell.CellStyle = contentStyle;
		sumArr[i] += list[i].ResearchExpenditure;
	}
	total += sum;
	cell = row46.CreateCell(num + 3);
	cell.SetCellValue(sum.ToString("N"));
	sum = 0;
	cell.CellStyle = contentStyle;
	//开办费
	IRow row47 = sheet1.CreateRow(r++);
	cell = row47.CreateCell(1);
	cell.CellStyle = contentStyle;
	cell = row47.CreateCell(2);
	cell.SetCellValue("开办费");
	cell.CellStyle = contentStyle;
	for (int i = 0; i < num; i++)
	{
		cell = row47.CreateCell(i + 3);
		sum += (decimal)list[i].OrganizationCosts;
		cell.SetCellValue(list[i].OrganizationCosts.ToString("N"));
		cell.CellStyle = contentStyle;
		sumArr[i] += list[i].OrganizationCosts;
	}
	total += sum;
	cell = row47.CreateCell(num + 3);
	cell.SetCellValue(sum.ToString("N"));
	sum = 0;
	cell.CellStyle = contentStyle;
	//咨询费用
	IRow row48 = sheet1.CreateRow(r++);
	cell = row48.CreateCell(1);
	cell.CellStyle = contentStyle;
	cell = row48.CreateCell(2);
	cell.SetCellValue("咨询费用");
	cell.CellStyle = contentStyle;
	for (int i = 0; i < num; i++)
	{
		cell = row48.CreateCell(i + 3);
		sum += (decimal)list[i].ConsultingFee;
		cell.SetCellValue(list[i].ConsultingFee.ToString("N"));
		cell.CellStyle = contentStyle;
		sumArr[i] += list[i].ConsultingFee;
	}
	total += sum;
	cell = row48.CreateCell(num + 3);
	cell.SetCellValue(sum.ToString("N"));
	sum = 0;
	cell.CellStyle = contentStyle;
	//差旅费
	IRow row49 = sheet1.CreateRow(r++);
	cell = row49.CreateCell(1);
	cell.CellStyle = contentStyle;
	cell = row49.CreateCell(2);
	cell.SetCellValue("差旅费");
	cell.CellStyle = contentStyle;
	for (int i = 0; i < num; i++)
	{
		cell = row49.CreateCell(i + 3);
		sum += (decimal)list[i].TravelExpense;
		cell.SetCellValue(list[i].TravelExpense.ToString("N"));
		cell.CellStyle = contentStyle;
		sumArr[i] += list[i].TravelExpense;
	}
	total += sum;
	cell = row49.CreateCell(num + 3);
	cell.SetCellValue(sum.ToString("N"));
	sum = 0;
	cell.CellStyle = contentStyle;
	//汽油费
	IRow row50 = sheet1.CreateRow(r++);
	cell = row50.CreateCell(1);
	cell.SetCellValue("车辆费用");
	cell.CellStyle = contentStyle;
	cell = row50.CreateCell(2);
	cell.SetCellValue("汽油费");
	cell.CellStyle = contentStyle;
	for (int i = 0; i < num; i++)
	{
		cell = row50.CreateCell(i + 3);
		sum += (decimal)list[i].FuelBills;
		cell.SetCellValue(list[i].FuelBills.ToString("N"));
		cell.CellStyle = contentStyle;
		sumArr[i] += list[i].FuelBills;
	}
	total += sum;
	cell = row50.CreateCell(num + 3);
	cell.SetCellValue(sum.ToString("N"));
	sum = 0;
	cell.CellStyle = contentStyle;
	//过路费
	IRow row51 = sheet1.CreateRow(r++);
	cell = row51.CreateCell(1);
	cell.CellStyle = contentStyle;
	cell = row51.CreateCell(2);
	cell.SetCellValue("过路费");
	cell.CellStyle = contentStyle;
	for (int i = 0; i < num; i++)
	{
		cell = row51.CreateCell(i + 3);
		sum += (decimal)list[i].RoadToll;
		cell.SetCellValue(list[i].RoadToll.ToString("N"));
		cell.CellStyle = contentStyle;
		sumArr[i] += list[i].RoadToll;
	}
	total += sum;
	cell = row51.CreateCell(num + 3);
	cell.SetCellValue(sum.ToString("N"));
	sum = 0;
	cell.CellStyle = contentStyle;
	//其他费用
	IRow row52 = sheet1.CreateRow(r++);
	cell = row52.CreateCell(1);
	cell.CellStyle = contentStyle;
	cell = row52.CreateCell(2);
	cell.SetCellValue("过路费");
	cell.CellStyle = contentStyle;
	for (int i = 0; i < num; i++)
	{
		cell = row52.CreateCell(i + 3);
		sum += (decimal)list[i].OtherExpenses;
		cell.SetCellValue(list[i].OtherExpenses.ToString("N"));
		cell.CellStyle = contentStyle;
		sumArr[i] += list[i].OtherExpenses;
	}
	total += sum;
	cell = row52.CreateCell(num + 3);
	cell.SetCellValue(sum.ToString("N"));
	sum = 0;
	cell.CellStyle = contentStyle;
	//小计
	IRow row53 = sheet1.CreateRow(r++);
	cell = row53.CreateCell(1);
	cell.SetCellValue("小计");
	cell.CellStyle = contentStyle;
	for (int i = 0; i < num; i++)
	{
		cell = row53.CreateCell(i + 3);
		cell.SetCellValue(sumArr[i].ToString("N"));
		cell.CellStyle = contentStyle;
	}
	cell = row53.CreateCell(num + 3);
	cell.SetCellValue(total.ToString("N"));
	cell.CellStyle = contentStyle;
	sum = 0;
	projectSum[num] += total;
	total = 0;//总计清零
	for (int i = 0; i < num; i++)
	{
		projectSum[i] += sumArr[i];
		sumArr[i] = 0;
	}
	//设备计量费
	IRow row54 = sheet1.CreateRow(r++);
	cell = row54.CreateCell(0);
	cell.SetCellValue("设备房屋费用");
	cell.CellStyle = contentStyle;
	cell = row54.CreateCell(1);
	cell.SetCellValue("设备费用");
	cell.CellStyle = contentStyle;
	cell = row54.CreateCell(2);
	cell.SetCellValue("设备计量费");
	cell.CellStyle = contentStyle;
	for (int i = 0; i < num; i++)
	{
		cell = row54.CreateCell(i + 3);
		sum += (decimal)list[i].EquipmentMeteringFee;
		cell.SetCellValue(list[i].EquipmentMeteringFee.ToString("N"));
		cell.CellStyle = contentStyle;
		sumArr[i] += list[i].EquipmentMeteringFee;
	}
	total += sum;
	cell = row54.CreateCell(num + 3);
	cell.SetCellValue(sum.ToString("N"));
	sum = 0;
	cell.CellStyle = contentStyle;
	//电子设备修理费
	IRow row55 = sheet1.CreateRow(r++);
	cell = row55.CreateCell(1);
	cell.CellStyle = contentStyle;
	cell = row55.CreateCell(2);
	cell.SetCellValue("电子设备修理费");
	cell.CellStyle = contentStyle;
	for (int i = 0; i < num; i++)
	{
		cell = row55.CreateCell(i + 3);
		sum += (decimal)list[i].ElectricalMachineryRepair;
		cell.SetCellValue(list[i].ElectricalMachineryRepair.ToString("N"));
		cell.CellStyle = contentStyle;
		sumArr[i] += list[i].ElectricalMachineryRepair;
	}
	total += sum;
	cell = row55.CreateCell(num + 3);
	cell.SetCellValue(sum.ToString("N"));
	sum = 0;
	cell.CellStyle = contentStyle;
	//车辆修理
	IRow row56 = sheet1.CreateRow(r++);
	cell = row56.CreateCell(1);
	cell.CellStyle = contentStyle;
	cell = row56.CreateCell(2);
	cell.SetCellValue("车辆修理");
	cell.CellStyle = contentStyle;
	for (int i = 0; i < num; i++)
	{
		cell = row56.CreateCell(i + 3);
		sum += (decimal)list[i].vehicleRepair;
		cell.SetCellValue(list[i].vehicleRepair.ToString("N"));
		cell.CellStyle = contentStyle;
		sumArr[i] += list[i].vehicleRepair;
	}
	total += sum;
	cell = row56.CreateCell(num + 3);
	cell.SetCellValue(sum.ToString("N"));
	sum = 0;
	cell.CellStyle = contentStyle;
	//折旧费
	IRow equCost = sheet1.CreateRow(r++);
	cell = equCost.CreateCell(1);
	cell.CellStyle = contentStyle;
	cell = equCost.CreateCell(2);
	cell.SetCellValue("折旧");
	cell.CellStyle = contentStyle;
	for (int i = 0; i < num; i++)
	{
		cell = equCost.CreateCell(i + 3);
		sum += (decimal)list[i].EquipmentCost;
		cell.SetCellValue(list[i].EquipmentCost.ToString("N"));
		cell.CellStyle = contentStyle;
		sumArr[i] += list[i].EquipmentCost;
	}
	total += sum;
	cell = equCost.CreateCell(num + 3);
	cell.SetCellValue(sum.ToString("N"));
	sum = 0;
	cell.CellStyle = contentStyle;
	//小计
	//IRow row57 = sheet1.CreateRow(r++);
	//cell = row57.CreateCell(1);
	//cell.SetCellValue("小计");
	//cell.CellStyle = contentStyle;
	//for (int i = 0; i < num; i++)
	//{
	//    cell = row57.CreateCell(i + 3);
	//    cell.SetCellValue(sumArr[i].ToString("N"));
	//    cell.CellStyle = contentStyle;
	//}
	//cell = row57.CreateCell(num + 3);
	//cell.SetCellValue(total.ToString("N"));
	//cell.CellStyle = contentStyle;
	//sum = 0;
	//projectSum[num] += total;
	//total = 0;//总计清零
	//for (int i = 0; i < num; i++)
	//{
	//    projectSum[i] += sumArr[i];
	//    sumArr[i] = 0;
	//}
	//房屋使用费
	IRow row58 = sheet1.CreateRow(r++);
	cell = row58.CreateCell(1);
	cell.SetCellValue("房屋使用");
	cell.CellStyle = contentStyle;
	cell = row58.CreateCell(2);
	cell.SetCellValue("房屋使用费");
	cell.CellStyle = contentStyle;
	for (int i = 0; i < num; i++)
	{
		cell = row58.CreateCell(i + 3);
		sum += (decimal)list[i].HouseUseFee;
		cell.SetCellValue(list[i].HouseUseFee.ToString("N"));
		cell.CellStyle = contentStyle;
		sumArr[i] += list[i].HouseUseFee;
	}
	total += sum;
	cell = row58.CreateCell(num + 3);
	cell.SetCellValue(sum.ToString("N"));
	sum = 0;
	cell.CellStyle = contentStyle;
	//水电费
	IRow row59 = sheet1.CreateRow(r++);
	cell = row59.CreateCell(1);
	cell.CellStyle = contentStyle;
	cell = row59.CreateCell(2);
	cell.SetCellValue("水电费用");
	cell.CellStyle = contentStyle;
	for (int i = 0; i < num; i++)
	{
		cell = row59.CreateCell(i + 3);
		sum += (decimal)list[i].UtilityBills;
		cell.SetCellValue(list[i].UtilityBills.ToString("N"));
		cell.CellStyle = contentStyle;
		sumArr[i] += list[i].UtilityBills;
	}
	total += sum;
	cell = row59.CreateCell(num + 3);
	cell.SetCellValue(sum.ToString("N"));
	sum = 0;
	cell.CellStyle = contentStyle;
	//物业费用
	IRow row60 = sheet1.CreateRow(r++);
	cell = row60.CreateCell(1);
	cell.CellStyle = contentStyle;
	cell = row60.CreateCell(2);
	cell.SetCellValue("物业费用");
	cell.CellStyle = contentStyle;
	for (int i = 0; i < num; i++)
	{
		cell = row60.CreateCell(i + 3);
		sum += (decimal)list[i].PropertyManagementFee;
		cell.SetCellValue(list[i].PropertyManagementFee.ToString("N"));
		cell.CellStyle = contentStyle;
		sumArr[i] += list[i].PropertyManagementFee;
	}
	total += sum;
	cell = row60.CreateCell(num + 3);
	cell.SetCellValue(sum.ToString("N"));
	sum = 0;
	cell.CellStyle = contentStyle;
	//房租费用
	IRow row61 = sheet1.CreateRow(r++);
	cell = row61.CreateCell(1);
	cell.CellStyle = contentStyle;
	cell = row61.CreateCell(2);
	cell.SetCellValue("房租费用");
	cell.CellStyle = contentStyle;
	for (int i = 0; i < num; i++)
	{
		cell = row61.CreateCell(i + 3);
		sum += (decimal)list[i].RentExpense;
		cell.SetCellValue(list[i].RentExpense.ToString("N"));
		cell.CellStyle = contentStyle;
		sumArr[i] += list[i].RentExpense;
	}
	total += sum;
	cell = row61.CreateCell(num + 3);
	cell.SetCellValue(sum.ToString("N"));
	sum = 0;
	cell.CellStyle = contentStyle;
	//房屋维修费用
	IRow row62 = sheet1.CreateRow(r++);
	cell = row62.CreateCell(1);
	cell.CellStyle = contentStyle;
	cell = row62.CreateCell(2);
	cell.SetCellValue("房屋维修费用");
	cell.CellStyle = contentStyle;
	for (int i = 0; i < num; i++)
	{
		cell = row62.CreateCell(i + 3);
		sum += (decimal)list[i].BuildingMaintenanceFee;
		cell.SetCellValue(list[i].BuildingMaintenanceFee.ToString("N"));
		cell.CellStyle = contentStyle;
		sumArr[i] += list[i].BuildingMaintenanceFee;
	}
	total += sum;
	cell = row62.CreateCell(num + 3);
	cell.SetCellValue(sum.ToString("N"));
	sum = 0;
	cell.CellStyle = contentStyle;
	//小计
	IRow row63 = sheet1.CreateRow(r++);
	cell = row63.CreateCell(1);
	cell.SetCellValue("小计");
	cell.CellStyle = contentStyle;
	for (int i = 0; i < num; i++)
	{
		cell = row63.CreateCell(i + 3);
		cell.SetCellValue(sumArr[i].ToString("N"));
		cell.CellStyle = contentStyle;
	}
	cell = row63.CreateCell(num + 3);
	cell.SetCellValue(total.ToString("N"));
	cell.CellStyle = contentStyle;
	sum = 0;
	projectSum[num] += total;
	total = 0;//总计清零
	for (int i = 0; i < num; i++)
	{
		projectSum[i] += sumArr[i];
		sumArr[i] = 0;
	}
	//成本合计
	IRow row64 = sheet1.CreateRow(r++);
	cell = row64.CreateCell(0);
	cell.SetCellValue("成本合计");
	cell.CellStyle = contentStyle;
	cell = row64.CreateCell(1);
	cell.CellStyle = contentStyle;
	cell = row64.CreateCell(2);
	cell.CellStyle = contentStyle;
	for (int i = 0; i < num; i++)
	{
		cell = row64.CreateCell(i + 3);
		cell.SetCellValue(projectSum[i].ToString("N"));
		cell.CellStyle = contentStyle;
	}
	cell = row64.CreateCell(num + 3);
	cell.SetCellValue(projectSum[num].ToString("N"));
	cell.CellStyle = contentStyle;

	#endregion
	string path = Server.MapPath("/Export/" + guid.ToString());//路径
	if (!Directory.Exists(path))
	{
		Directory.CreateDirectory(path);
	}

保存和关闭流

	//设置新建文件路径及名称
	string savePath = path + "/" + "项目成本费用明细表" + DateTime.Now.ToString("yyyyMMddhhmmssfff") + ".xls";

	FileStream fileHSSF = new FileStream(savePath, FileMode.Create);//建立文件
	book.Write(fileHSSF);//写入内容
	fileHSSF.Close();//关闭流

	return savePath;

前台js

$.ajax({
        type: 'post',
        url: '/Finance/DepProjectExpense/ExportExpenseOfDetail',//具体导出的action
        data: {
            'startTime': startTime,
            "endTime": endTime,
            "dep": dep,
            "contractName": ContractName,
            "contractCode": ContractCode
        },
        success: function (data) {
            if (data != "没有数据" && data != "异常") {
                location.href = "/Finance/ExportManagement/DownExcel?dirName=" + data;
            } else {
                BJUI.alertmsg("error", data, { mask: false });
                auto_close_alertbox(1500);
                return;
            }
        }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值