使用NPOI中间件导出excel

C#使用NPOI导入导出EXCEL文件 NPOI可以通过右键解决方案->管理解决方案的NuGet程序包->下载NPOI控件,也可以在网上下载好NPOI DLL包然后倒入项目。 1.新建Windows窗体应用程序员项目,重命名为TestNOPIOperateExcel 2.在Form1界面中控件。添加button1、button2控件用于倒入、导出excel,label1、label2用来显示倒入、导出所需时间,dataGridView1用来查看Excel文件。 3.右键Form1.cs->查看代码,切换到代码界面。 4. 阅读详情

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;
            }
        }
c# 使用NPOI按模板导出excel excel模板设置 私车公用单 申请信息 申请单号: $header.ORDER_NO 申请日期: $header.CREATE_TIME $auotheight 申请部门: $header.APPLY_DEPT 申请人: $header.APPLY_USER $auotheight 项目: ... 阅读详情

相关推荐

C#使用NPOI将List数据导出Excel文档

NPOI是一个开源的C#读写Excel、WORD等微软OLE2组件文档的项目。使用 NPOI 可以在没有安装 Office 或者相应环境的机器上对 WORD/EXCEL 文档进行读写。这里

dnazhd的博客 3060

asp.net 利用NPOI导出Excel通用类的方法

解决中文文件名保存Excel乱码问题,主要是判断火狐或者IE浏览器,然后做对应的判断处理,核心代码如下: System.Web.HttpContext.Current.Response.ContentType = application/vnd.ms-excel; //设置下载的Excel文件名\ if (System.Web.HttpContext.Current.Request.ServerVariables[http_user_agent].ToString().IndexOf(Firefox) != -1) { //火狐浏览器 System.Web

ExcelNPOI导出和模板导出

Excel 导出:主要是利用了浏览器的下载功能。通过window.open(), 在一个新的窗口打开下载的路径 一、NPOI导出Excel.xls 后缀名 是1997~2003的版本,是Excel基本的版本,和.xlsx的版本相比,.xls的兼容性更强 .xlsx 后缀名,是比.xls更好的版本,只是代码实现相对.xls的更加复杂 导出步骤:一、查询需要导出的数据 二、创建工作簿和工作表 三、然后在工作表中创建行(注意:Excel的官方定义是先有行,再有列) 四、( 设置表标题及样式 -&g

shmily_Laowang的博客 1986

C#使用NPOI实现导入导出Excel数据

一、NPOI简介 1.1、NPOI是什么   NPOI是POI的.NET版本,POI是一套用Java写成的库,我们在开发中经常用到导入导出表格、文档的情况,NPOI能够帮助我们在没有安装微软Office的情况下读写Office文件,如xls, doc, ppt等。NPOI采用的是Apache 2.0许可证(poi也是采用这个许可证),这意味着它可以被用于任何商业或非商业项目,我们不用担心因为使用它而必须开放你自己的源代码,所以它对于很多从事业务系统开发的公司来说绝对是很不错的选择。 1.2、NPOI

提供C#相关开发 、云计算、运维测试、网络安全相关技术分享与服务,有意向可联系。 1万+

C# NPOI读取Excel中文乱码

Settings > Time & Language > Language & Region > Related Settings > Administrative Language Settings > Language for non-Unicode programs, 点击“Change system locale"联想到一个月前遇到过下载excel文件名乱码的问题,于是采用当时的解决方案尝试,成功!网上找了一圈,没找到NPOI中文乱码的解决方案,普遍都是比较顺利没遇到中文乱码问题。

小鹰信息技术服务部 1710

C#导出EXCEL显示乱码的问题

前台: 或换成gb2312 后台: Response.ContentEncoding = System.Text.Encoding.UTF8; Response.ContentType = "application/msexcel"; Response.AddHeader("content-Disposition", "attachm

Magic Bingo 6073

导出Excel文档 解决导出Excel文档显示乱码 在C#桌面程序导出Excel文档

//以下代码在Win程序运行功能成功,注意的一点是在Win程序中用了ASP.NET的WEB控件DataGrid1//代码亦可在WEB中运行 //绑定数据到DataGrid1 this.DataGrid1.DataSource = SourceTb.DefaultView; this.DataGrid1.DataBind();   //将DataGrid1构成的html代码写进Strin

kevery_net Q:214958266 1954

.NET Core6.0使用NPOI导入导出Excel

.NET6使用NPOI导入导出Excel

qq_43005276的博客 3446

NPOI实现EXCEL导出

NPOI实现EXCEL导出 技术栈: 基于NPOI+ExcelReport实现的导入与导出EXCEL类库:ExcelUtility 1.ExcelUntility 功能: 1.将数据导出EXCEL(支持XLS,XLSX,支持多种类型模板,支持列宽自适应)      类名:ExcelUtility. Export 2.EXCEL数据导入到数据对象中(DataTable、Dataset,支持XLS,XLSX)      类名:ExcelUtility. Import 2.ExcelUt

aristo 7433

C# 使用NPOIexcel导出

使用NPOIexcel文件导出 : 1.下载npoi引用文件 下载地址1:https://archive.codeplex.com/?p=npoi 下载地址2:链接:https://pan.baidu.com/s/1Zxq4NOCnaekdTei74d6UiQ 提取码:zrwn 下载地址3:https://downloa...

长流的博客 2972

C# NPOI 和 CSV 导出Excel 功能实现

1、引言 程序中经常会使用到的一个功能就是导出 Excel ,而导出 Excel 的实现主要有两种方法,一种是 CSV 导出,一种是 NPOI 导出,而从效果上来说,NPOI 更能够符合Excel 导出规范。 2、CSV与NPOI简介 CSV逗号分隔值(Comma-Separated Values 有时也称为字符分隔值,因为分隔字符也可以不是逗号),其...

lingshuangcanxue 9139

C#.net导出标准的Excelnpoi

不管用哪一种语言开发应用程序,导出功能是最常见的,一般导出文件格式最常见的有PDF 、Excel、CSV、Word、TXT等,今天我们在此介绍一下Excel导出方法。 微软提供了导出Excel的多种办法,但是今天我们在这里只介绍一种第三方的导出方法,因为它简单,更多符合我们的编程习惯(个人观点),下面开始: 一、下载,官网地址:https://npoi.codeplex.c

高彬的专栏 6480

C# NPOI读取Excel数据

using System; using System.Collections.Generic; using System.Data; using System.IO; using System.Linq; using System.Text; using System.Windows.Forms; using NPOI.HSSF.UserModel; using NPOI.SS.Use...

落泪的只有我 1万+

asp.net 利用NPOI导出Excel通用类

解决中文文件名保存Excel乱码问题,主要是判断火狐或者IE浏览器,然后做对应的判断处理,核心代码如下: System.Web.HttpContext.Current.Response.ContentType = "application/vnd.ms-excel"; //设置下载的Excel文件名\ if (System.Web.HttpContext.Current.Request.Ser

分享经验,共同进步. 4990

NPOI(v1.2.4)生成excel超链接地址中文乱码的问题

原文地址:https://www.cnblogs.com/kejianet/archive/2012/03/04/2379758.html NPOI(v1.2.4)生成excel超链接地址中文乱码的问题 近日项目中需要把某目录下所有文件信息导出excel中,并在文件名这一列中设置超链接,点击时可以直接打开该文件。 项目使用NPOI v1.2.4,代码如下:  1           ...

xujingcheng123的博客 1397
上一篇: C#--正则过滤网页及数据库敏感字符——网络安全
下一篇: C#中的AOP其一
西关月夜
博客等级 码龄10年 4粉丝 18原创
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值