From 036dbdeb9b3655add7d2bd168f6dd7a9bb4965bb Mon Sep 17 00:00:00 2001 From: liqionghai <1> Date: Thu, 28 Aug 2025 00:32:00 +0800 Subject: [PATCH 1/2] 1 --- .../AccountsReceivable/LiteVersionPlugIn.cs | 71 +++++++++++++++---- 1 file changed, 57 insertions(+), 14 deletions(-) diff --git a/Pilot.Report.Exploitation/AccountsReceivable/LiteVersionPlugIn.cs b/Pilot.Report.Exploitation/AccountsReceivable/LiteVersionPlugIn.cs index 94879b9..66df55e 100644 --- a/Pilot.Report.Exploitation/AccountsReceivable/LiteVersionPlugIn.cs +++ b/Pilot.Report.Exploitation/AccountsReceivable/LiteVersionPlugIn.cs @@ -101,17 +101,38 @@ namespace Pilot.Report.Exploitation.AccountsReceivable // 创建一个单元格样式------------------------------- ICellStyle cellStyle = workbook.CreateCellStyle(); + //创建字体格式为Times New Roman,字体大小为10号 + IFont font1 = workbook.CreateFont(); + font1.FontName = "Times New Roman"; + font1.FontHeightInPoints = 10; + // 设置边框样式 cellStyle.BorderTop = BorderStyle.Thin; cellStyle.BorderBottom = BorderStyle.Thin; cellStyle.BorderLeft = BorderStyle.Thin; cellStyle.BorderRight = BorderStyle.Thin; // 设置水平居中对齐 - cellStyle.Alignment = HorizontalAlignment.Center; + cellStyle.Alignment = HorizontalAlignment.Right; // 设置垂直居中对齐 cellStyle.VerticalAlignment = VerticalAlignment.Center; //设置数值格式保留两位小数 - cellStyle.DataFormat = workbook.CreateDataFormat().GetFormat("0.00"); + cellStyle.DataFormat = workbook.CreateDataFormat().GetFormat("#,##0.00"); + //设置字体和大小 + cellStyle.SetFont(font1); + + ICellStyle cellStyle3 = workbook.CreateCellStyle(); + + // 设置边框样式 + cellStyle3.BorderTop = BorderStyle.Thin; + cellStyle3.BorderBottom = BorderStyle.Thin; + cellStyle3.BorderLeft = BorderStyle.Thin; + cellStyle3.BorderRight = BorderStyle.Thin; + // 设置水平居中对齐 + cellStyle3.Alignment = HorizontalAlignment.Center; + // 设置垂直居中对齐 + cellStyle3.VerticalAlignment = VerticalAlignment.Center; + //设置字体和大小 + cellStyle3.SetFont(font1); // 创建一个单元格样式--------------------------------- ICellStyle cellStyle2 = workbook.CreateCellStyle(); @@ -121,6 +142,8 @@ namespace Pilot.Report.Exploitation.AccountsReceivable cellStyle2.BorderBottom = BorderStyle.Thin; cellStyle2.BorderLeft = BorderStyle.Thin; cellStyle2.BorderRight = BorderStyle.Thin; + //设置字体和大小 + cellStyle2.SetFont(font1); // 创建单元格样式--------------------------------------- ICellStyle style = workbook.CreateCellStyle(); @@ -134,7 +157,8 @@ namespace Pilot.Report.Exploitation.AccountsReceivable // 创建字体并设置为加粗 IFont font = workbook.CreateFont(); font.IsBold = true; // 设置字体加粗 - + font.FontName = "Times New Roman"; + font.FontHeightInPoints = 10; // 将字体应用到单元格样式 style.SetFont(font); @@ -144,7 +168,8 @@ namespace Pilot.Report.Exploitation.AccountsReceivable // 创建字体并设置为加粗 IFont font2 = workbook.CreateFont(); font2.IsBold = true; // 设置字体加粗 - + font2.FontName = "Times New Roman"; + font2.FontHeightInPoints = 10; // 将字体应用到单元格样式 style2.SetFont(font2); @@ -157,15 +182,17 @@ namespace Pilot.Report.Exploitation.AccountsReceivable style3.BorderLeft = BorderStyle.Thin; style3.BorderRight = BorderStyle.Thin; // 设置水平居中对齐 - style3.Alignment = HorizontalAlignment.Center; + style3.Alignment = HorizontalAlignment.Right; // 设置垂直居中对齐 style3.VerticalAlignment = VerticalAlignment.Center; // 创建字体并设置为加粗 IFont font3 = workbook.CreateFont(); font3.IsBold = true; // 设置字体加粗 + font3.FontName = "Times New Roman"; + font3.FontHeightInPoints = 10; // 将字体应用到单元格样式 style3.SetFont(font3); - style3.DataFormat = workbook.CreateDataFormat().GetFormat("0.00"); + style3.DataFormat = workbook.CreateDataFormat().GetFormat("#,##0.00"); // 创建一个单元格样式------------------------------- @@ -182,7 +209,23 @@ namespace Pilot.Report.Exploitation.AccountsReceivable style4.VerticalAlignment = VerticalAlignment.Center; // 将字体应用到单元格样式 style4.SetFont(font3); - style4.DataFormat = workbook.CreateDataFormat().GetFormat("0.00"); + style4.DataFormat = workbook.CreateDataFormat().GetFormat("#,##0.00"); + + + // 创建一个单元格样式------------------------------- + ICellStyle style5 = workbook.CreateCellStyle(); + + // 设置边框样式 + style5.BorderTop = BorderStyle.Thin; + style5.BorderBottom = BorderStyle.Thin; + style5.BorderLeft = BorderStyle.Thin; + style5.BorderRight = BorderStyle.Thin; + // 设置水平居中对齐 + style5.Alignment = HorizontalAlignment.Center; + // 设置垂直居中对齐 + style5.VerticalAlignment = VerticalAlignment.Center; + // 将字体应用到单元格样式 + style5.SetFont(font3); #endregion #region 获取金额汇总数据 @@ -219,7 +262,7 @@ namespace Pilot.Report.Exploitation.AccountsReceivable //将新创建或获取的单元格的值修改 cell22.SetCellValue(""); var YFHpriceSumZW = ToChineseNumber(YFHpriceSum, Context); - cell3.SetCellValue("贵公司截至 " + fDate + " 共欠我公司货款金额为:" + YFHpriceSum + "元(大写:" + YFHpriceSumZW + ")"); + cell3.SetCellValue("贵公司截至 " + (string.IsNullOrWhiteSpace(fDate) ? DateTime.Now.ToString("yyyy-MM-dd") : fDate) + " 共欠我公司货款金额为:" + YFHpriceSum.ToString("N") + "元(大写:" + YFHpriceSumZW + ")"); //将新创建或获取的单元格的值修改 cell.SetCellValue("尊敬的 " + fClient + " 客户您好,我公司已根据合同/订单的要求向贵公司交付相关产品并请验收确认,鉴于我公司对贵公司已通知发货部分的交付义务已完成,"); cell2.SetCellValue(fClient); @@ -244,7 +287,7 @@ namespace Pilot.Report.Exploitation.AccountsReceivable for (var i = 0; i < list.Count; i++) { - string date = string.IsNullOrWhiteSpace(list[i]["DATE"].ToString()) ? "" : list[i]["DATE"].ToString().Split(' ')[0]; + string date = string.IsNullOrWhiteSpace(list[i]["DATE"].ToString()) ? "" : Convert.ToDateTime(list[i]["DATE"].ToString().Split(' ')[0]).ToString("yyyy/M/d"); decimal OrderAmount = string.IsNullOrWhiteSpace(list[i]["OrderAmount"].ToString()) ? 0 : Math.Round(Convert.ToDecimal(list[i]["OrderAmount"]), 2); decimal ShipmentsAmount = string.IsNullOrWhiteSpace(list[i]["ShipmentsAmount"].ToString()) ? 0 : Math.Round(Convert.ToDecimal(list[i]["ShipmentsAmount"]), 2); decimal FBillAllAmount = string.IsNullOrWhiteSpace(list[i]["FBillAllAmount"].ToString()) ? 0 : Math.Round(Convert.ToDecimal(list[i]["FBillAllAmount"]), 2); @@ -261,7 +304,7 @@ namespace Pilot.Report.Exploitation.AccountsReceivable // j = 12; //} - ICell c1 = rowi.CreateCell(0); c1.SetCellValue(list[i]["Number"].ToString()); c1.CellStyle = cellStyle; + ICell c1 = rowi.CreateCell(0); c1.SetCellValue(list[i]["Number"].ToString()); c1.CellStyle = cellStyle3; ICell c2 = rowi.CreateCell(1); c2.SetCellValue(""+date+""); c2.CellStyle = cellStyle2; ICell c3 = rowi.CreateCell(2); c3.SetCellValue(list[i]["CONTRACTNUMBER"].ToString()); c3.CellStyle = cellStyle2; ICell c4 = rowi.CreateCell(3); c4.SetCellValue(list[i]["ProjectName"].ToString()); c4.CellStyle = cellStyle2; @@ -272,12 +315,12 @@ namespace Pilot.Report.Exploitation.AccountsReceivable ICell c9 = rowi.CreateCell(8); c9.SetCellValue(Convert.ToDouble(PaymentAmount )); c9.CellStyle = cellStyle; ICell c10 = rowi.CreateCell(9); c10.SetCellValue(Convert.ToDouble(ShippedDebt )); c10.CellStyle = cellStyle; ICell c11 = rowi.CreateCell(10); c11.SetCellValue(Convert.ToDouble(InvoicedDebt)); c11.CellStyle = cellStyle; - ICell c12 = rowi.CreateCell(11); c12.SetCellValue(list[i]["IsEnded"].ToString()); c12.CellStyle = cellStyle2; - ICell c13 = rowi.CreateCell(12); c13.SetCellValue(list[i]["Remark"].ToString()); c13.CellStyle = cellStyle2; + ICell c12 = rowi.CreateCell(11); c12.SetCellValue(list[i]["IsEnded"].ToString()); c12.CellStyle = cellStyle3; + //ICell c13 = rowi.CreateCell(12); c13.SetCellValue(list[i]["Remark"].ToString()); c13.CellStyle = cellStyle2; n++; if(list[i]["Number"].ToString() == "合计") { - c1.CellStyle = style3; + c1.CellStyle = style5; c2.CellStyle = style3; c3.CellStyle = style3; c4.CellStyle = style3; @@ -289,7 +332,7 @@ namespace Pilot.Report.Exploitation.AccountsReceivable c10.CellStyle = style3; c11.CellStyle = style3; c12.CellStyle = style3; - c13.CellStyle = style3; + //c13.CellStyle = style3; } } From b37f731bd2b693aee59c4f36ef0e5bf70596a596 Mon Sep 17 00:00:00 2001 From: liqionghai <1> Date: Thu, 28 Aug 2025 12:32:11 +0800 Subject: [PATCH 2/2] 1 --- .../AccountsReceivable/LiteVersionPlugIn.cs | 59 ++++++++++++++----- 1 file changed, 45 insertions(+), 14 deletions(-) diff --git a/Pilot.Report.Exploitation/AccountsReceivable/LiteVersionPlugIn.cs b/Pilot.Report.Exploitation/AccountsReceivable/LiteVersionPlugIn.cs index 66df55e..7bf787c 100644 --- a/Pilot.Report.Exploitation/AccountsReceivable/LiteVersionPlugIn.cs +++ b/Pilot.Report.Exploitation/AccountsReceivable/LiteVersionPlugIn.cs @@ -144,6 +144,10 @@ namespace Pilot.Report.Exploitation.AccountsReceivable cellStyle2.BorderRight = BorderStyle.Thin; //设置字体和大小 cellStyle2.SetFont(font1); + // 设置垂直居中对齐 + cellStyle2.VerticalAlignment = VerticalAlignment.Center; + //自动换行 + cellStyle2.WrapText = true; // 创建单元格样式--------------------------------------- ICellStyle style = workbook.CreateCellStyle(); @@ -226,6 +230,19 @@ namespace Pilot.Report.Exploitation.AccountsReceivable style5.VerticalAlignment = VerticalAlignment.Center; // 将字体应用到单元格样式 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 #region 获取金额汇总数据 @@ -345,9 +362,9 @@ namespace Pilot.Report.Exploitation.AccountsReceivable IRow rr1 = sheet2.GetRow(15); IRow rr2 = sheet2.GetRow(16); IRow rr3 = sheet2.GetRow(17); - ICell cc1 = rr1.GetCell(6); - ICell cc2 = rr2.GetCell(6); - ICell cc3 = rr3.GetCell(6); + ICell cc1 = rr1.GetCell(6 + 1); + ICell cc2 = rr2.GetCell(6 + 1); + ICell cc3 = rr3.GetCell(6 + 1); cc1.SetCellValue(Convert.ToDouble(YFHpriceSum)); cc2.SetCellValue(Convert.ToDouble(YFPpriceSum)); cc3.SetCellValue(Convert.ToDouble(priceSum)); @@ -382,11 +399,11 @@ namespace Pilot.Report.Exploitation.AccountsReceivable } ICell CR1 = r1.CreateCell(i); 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; } - else if(i == 6) + else if(i == 6 + 1) { CR1.SetCellValue(Convert.ToDouble(test1)); CR1.CellStyle = style4; @@ -407,11 +424,11 @@ namespace Pilot.Report.Exploitation.AccountsReceivable } ICell CR1 = r2.CreateCell(i); 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; } - else if (i == 6) + else if (i == 6 + 1) { CR1.SetCellValue(Convert.ToDouble(test1)); CR1.CellStyle = style4; @@ -432,11 +449,11 @@ namespace Pilot.Report.Exploitation.AccountsReceivable } ICell CR1 = r3.CreateCell(i); 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; } - else if (i == 6) + else if (i == 6 + 1) { CR1.SetCellValue(Convert.ToDouble(test1)); CR1.CellStyle = style4; @@ -474,6 +491,10 @@ namespace Pilot.Report.Exploitation.AccountsReceivable { CR1.CellStyle = style2; } + else + { + CR1.CellStyle = style6; + } } //第六行 @@ -490,6 +511,10 @@ namespace Pilot.Report.Exploitation.AccountsReceivable { CR1.CellStyle = style2; } + else + { + CR1.CellStyle = style6; + } } //第七行 @@ -506,6 +531,10 @@ namespace Pilot.Report.Exploitation.AccountsReceivable { CR1.CellStyle = style2; } + else + { + CR1.CellStyle = style6; + } } //合并单元格 @@ -514,12 +543,12 @@ namespace Pilot.Report.Exploitation.AccountsReceivable // 合并单元格的起始行、结束行、起始列和结束列 int firstRow = n + i; // 比如第一行 int lastRow = n + i; // 合并到第三行(0-based index) - int firstCol = 4; // 比如第一列 - int firstCol2 = 7; // 比如第一列 + int firstCol = 4 + 1; // 比如第一列 + int firstCol2 = 7 + 1; // 比如第一列 int firstCol3 = 0; // 比如第一列 - int lastCol = 5; // 合并到第三列(0-based index) - int lastCol2 = 9; // 合并到第三列(0-based index) - int lastCol3 = 3; // 合并到第三列(0-based index) + int lastCol = 5 + 1; // 合并到第三列(0-based index) + int lastCol2 = 9 + 1; // 合并到第三列(0-based index) + int lastCol3 = 3 + 1; // 合并到第三列(0-based index) // 创建CellRangeAddress对象 CellRangeAddress cellRangeAddress = new CellRangeAddress(firstRow, lastRow, firstCol, lastCol); CellRangeAddress cellRangeAddress2 = new CellRangeAddress(firstRow, lastRow, firstCol2, lastCol2); @@ -531,6 +560,8 @@ namespace Pilot.Report.Exploitation.AccountsReceivable } //移除第二个工作表 workbook.RemoveSheetAt(1); + //重命名工作表 + workbook.SetSheetName(0,string.Format("简易版{0}",DateTime.Now.ToString("yyyy-MM-dd"))); #endregion #region Excel代码2