This commit is contained in:
liqionghai 2025-08-28 12:32:11 +08:00
parent 036dbdeb9b
commit b37f731bd2

View File

@ -144,6 +144,10 @@ namespace Pilot.Report.Exploitation.AccountsReceivable
cellStyle2.BorderRight = BorderStyle.Thin; cellStyle2.BorderRight = BorderStyle.Thin;
//设置字体和大小 //设置字体和大小
cellStyle2.SetFont(font1); cellStyle2.SetFont(font1);
// 设置垂直居中对齐
cellStyle2.VerticalAlignment = VerticalAlignment.Center;
//自动换行
cellStyle2.WrapText = true;
// 创建单元格样式--------------------------------------- // 创建单元格样式---------------------------------------
ICellStyle style = workbook.CreateCellStyle(); ICellStyle style = workbook.CreateCellStyle();
@ -226,6 +230,19 @@ namespace Pilot.Report.Exploitation.AccountsReceivable
style5.VerticalAlignment = VerticalAlignment.Center; style5.VerticalAlignment = VerticalAlignment.Center;
// 将字体应用到单元格样式 // 将字体应用到单元格样式
style5.SetFont(font3); style5.SetFont(font3);
// 创建单元格样式---------------------------------------
ICellStyle style6 = workbook.CreateCellStyle();
// 创建字体并设置为加粗
IFont font5 = workbook.CreateFont();
font5.FontName = "Times New Roman";
font5.FontHeightInPoints = 10;
//font5.IsBold = true; // 设置字体加粗
// 将字体应用到单元格样式
style6.SetFont(font5);
#endregion #endregion
#region #region
@ -345,9 +362,9 @@ namespace Pilot.Report.Exploitation.AccountsReceivable
IRow rr1 = sheet2.GetRow(15); IRow rr1 = sheet2.GetRow(15);
IRow rr2 = sheet2.GetRow(16); IRow rr2 = sheet2.GetRow(16);
IRow rr3 = sheet2.GetRow(17); IRow rr3 = sheet2.GetRow(17);
ICell cc1 = rr1.GetCell(6); ICell cc1 = rr1.GetCell(6 + 1);
ICell cc2 = rr2.GetCell(6); ICell cc2 = rr2.GetCell(6 + 1);
ICell cc3 = rr3.GetCell(6); ICell cc3 = rr3.GetCell(6 + 1);
cc1.SetCellValue(Convert.ToDouble(YFHpriceSum)); cc1.SetCellValue(Convert.ToDouble(YFHpriceSum));
cc2.SetCellValue(Convert.ToDouble(YFPpriceSum)); cc2.SetCellValue(Convert.ToDouble(YFPpriceSum));
cc3.SetCellValue(Convert.ToDouble(priceSum)); cc3.SetCellValue(Convert.ToDouble(priceSum));
@ -382,11 +399,11 @@ namespace Pilot.Report.Exploitation.AccountsReceivable
} }
ICell CR1 = r1.CreateCell(i); ICell CR1 = r1.CreateCell(i);
CR1.SetCellValue(test1); CR1.SetCellValue(test1);
if (i == 4 || i == 5 || i == 7 || i == 8 || i == 9) if (i == 4 + 1 || i == 5 + 1 || i == 7 + 1 || i == 8 + 1 || i == 9 + 1)
{ {
CR1.CellStyle = style; CR1.CellStyle = style;
} }
else if(i == 6) else if(i == 6 + 1)
{ {
CR1.SetCellValue(Convert.ToDouble(test1)); CR1.SetCellValue(Convert.ToDouble(test1));
CR1.CellStyle = style4; CR1.CellStyle = style4;
@ -407,11 +424,11 @@ namespace Pilot.Report.Exploitation.AccountsReceivable
} }
ICell CR1 = r2.CreateCell(i); ICell CR1 = r2.CreateCell(i);
CR1.SetCellValue(test1); CR1.SetCellValue(test1);
if (i == 4 || i == 5 || i == 7 || i == 8 || i == 9) if (i == 4 + 1 || i == 5 + 1 || i == 7 + 1 || i == 8 + 1 || i == 9 + 1)
{ {
CR1.CellStyle = style; CR1.CellStyle = style;
} }
else if (i == 6) else if (i == 6 + 1)
{ {
CR1.SetCellValue(Convert.ToDouble(test1)); CR1.SetCellValue(Convert.ToDouble(test1));
CR1.CellStyle = style4; CR1.CellStyle = style4;
@ -432,11 +449,11 @@ namespace Pilot.Report.Exploitation.AccountsReceivable
} }
ICell CR1 = r3.CreateCell(i); ICell CR1 = r3.CreateCell(i);
CR1.SetCellValue(test1); CR1.SetCellValue(test1);
if (i == 4 || i == 5 || i == 7 || i == 8 || i == 9) if (i == 4 + 1 || i == 5 + 1 || i == 7 + 1 || i == 8 + 1 || i == 9 + 1)
{ {
CR1.CellStyle = style; CR1.CellStyle = style;
} }
else if (i == 6) else if (i == 6 + 1)
{ {
CR1.SetCellValue(Convert.ToDouble(test1)); CR1.SetCellValue(Convert.ToDouble(test1));
CR1.CellStyle = style4; CR1.CellStyle = style4;
@ -474,6 +491,10 @@ namespace Pilot.Report.Exploitation.AccountsReceivable
{ {
CR1.CellStyle = style2; CR1.CellStyle = style2;
} }
else
{
CR1.CellStyle = style6;
}
} }
//第六行 //第六行
@ -490,6 +511,10 @@ namespace Pilot.Report.Exploitation.AccountsReceivable
{ {
CR1.CellStyle = style2; CR1.CellStyle = style2;
} }
else
{
CR1.CellStyle = style6;
}
} }
//第七行 //第七行
@ -506,6 +531,10 @@ namespace Pilot.Report.Exploitation.AccountsReceivable
{ {
CR1.CellStyle = style2; CR1.CellStyle = style2;
} }
else
{
CR1.CellStyle = style6;
}
} }
//合并单元格 //合并单元格
@ -514,12 +543,12 @@ namespace Pilot.Report.Exploitation.AccountsReceivable
// 合并单元格的起始行、结束行、起始列和结束列 // 合并单元格的起始行、结束行、起始列和结束列
int firstRow = n + i; // 比如第一行 int firstRow = n + i; // 比如第一行
int lastRow = n + i; // 合并到第三行0-based index int lastRow = n + i; // 合并到第三行0-based index
int firstCol = 4; // 比如第一列 int firstCol = 4 + 1; // 比如第一列
int firstCol2 = 7; // 比如第一列 int firstCol2 = 7 + 1; // 比如第一列
int firstCol3 = 0; // 比如第一列 int firstCol3 = 0; // 比如第一列
int lastCol = 5; // 合并到第三列0-based index int lastCol = 5 + 1; // 合并到第三列0-based index
int lastCol2 = 9; // 合并到第三列0-based index int lastCol2 = 9 + 1; // 合并到第三列0-based index
int lastCol3 = 3; // 合并到第三列0-based index int lastCol3 = 3 + 1; // 合并到第三列0-based index
// 创建CellRangeAddress对象 // 创建CellRangeAddress对象
CellRangeAddress cellRangeAddress = new CellRangeAddress(firstRow, lastRow, firstCol, lastCol); CellRangeAddress cellRangeAddress = new CellRangeAddress(firstRow, lastRow, firstCol, lastCol);
CellRangeAddress cellRangeAddress2 = new CellRangeAddress(firstRow, lastRow, firstCol2, lastCol2); CellRangeAddress cellRangeAddress2 = new CellRangeAddress(firstRow, lastRow, firstCol2, lastCol2);
@ -531,6 +560,8 @@ namespace Pilot.Report.Exploitation.AccountsReceivable
} }
//移除第二个工作表 //移除第二个工作表
workbook.RemoveSheetAt(1); workbook.RemoveSheetAt(1);
//重命名工作表
workbook.SetSheetName(0,string.Format("简易版{0}",DateTime.Now.ToString("yyyy-MM-dd")));
#endregion #endregion
#region Excel代码2 #region Excel代码2