From a08d3d7c4ad0d10b3741cf0bf1781c7994133177 Mon Sep 17 00:00:00 2001 From: liqionghai <1> Date: Fri, 22 Aug 2025 19:30:33 +0800 Subject: [PATCH] 1 --- .../AccountsReceivable/LiteVersionPlugIn.cs | 91 +++++++++++++------ 1 file changed, 65 insertions(+), 26 deletions(-) diff --git a/Pilot.Report.Exploitation/AccountsReceivable/LiteVersionPlugIn.cs b/Pilot.Report.Exploitation/AccountsReceivable/LiteVersionPlugIn.cs index d4d6cc1..53b9193 100644 --- a/Pilot.Report.Exploitation/AccountsReceivable/LiteVersionPlugIn.cs +++ b/Pilot.Report.Exploitation/AccountsReceivable/LiteVersionPlugIn.cs @@ -32,7 +32,18 @@ namespace Pilot.Report.Exploitation.AccountsReceivable // 判断 应收对账单【简易版】按钮 if (e.BarItemKey == "Test_Button_1") { - string FPath = "应收账款对账单【简易版】.xlsx"; + var reportModel = this.SysReportModel; + + //单据头 + var rptTitles = reportModel.ReportTitles; + string fClient = rptTitles.FirstOrDefault(a => a.TitleKey == "FClient").TitleValue.ToString(); + string fDate = rptTitles.FirstOrDefault(a => a.TitleKey == "FDate").TitleValue.ToString(); + string fProject = rptTitles.FirstOrDefault(a => a.TitleKey == "FProject").TitleValue.ToString(); + string FState = rptTitles.FirstOrDefault(a => a.TitleKey == "FState").TitleValue.ToString(); + string F_SFYJKH = rptTitles.FirstOrDefault(a => a.TitleKey == "F_SFYJKH").TitleValue.ToString(); + + //string FPath = "应收账款对账单【简易版】.xlsx"; + string FPath = string.Format("{0}-{1}-应收账款对账单.xlsx", DateTime.Now.ToString("yyyyMMdd"), fClient); // 在临时文件目录,生成一个完整的文件名: C:\Program Files\Kingdee\K3Cloud\WebSite\...\JD.xls string filePath = PathUtils.GetPhysicalPath(KeyConst.TEMPFILEPATH, Path.GetFileName(FPath)); @@ -46,15 +57,7 @@ namespace Pilot.Report.Exploitation.AccountsReceivable //显示 this.View.ShowForm(showParameter); - var reportModel = this.SysReportModel; - - //单据头 - var rptTitles = reportModel.ReportTitles; - string fClient = rptTitles.FirstOrDefault(a => a.TitleKey == "FClient").TitleValue.ToString(); - string fDate = rptTitles.FirstOrDefault(a => a.TitleKey == "FDate").TitleValue.ToString(); - string fProject = rptTitles.FirstOrDefault(a => a.TitleKey == "FProject").TitleValue.ToString(); - string FState = rptTitles.FirstOrDefault(a => a.TitleKey == "FState").TitleValue.ToString(); - string F_SFYJKH = rptTitles.FirstOrDefault(a => a.TitleKey == "F_SFYJKH").TitleValue.ToString(); + //单据体 var list = reportModel.DataSource.Rows; @@ -107,6 +110,8 @@ namespace Pilot.Report.Exploitation.AccountsReceivable cellStyle.Alignment = HorizontalAlignment.Center; // 设置垂直居中对齐 cellStyle.VerticalAlignment = VerticalAlignment.Center; + //设置数值格式保留两位小数 + cellStyle.DataFormat = workbook.CreateDataFormat().GetFormat("0.00"); // 创建一个单元格样式--------------------------------- ICellStyle cellStyle2 = workbook.CreateCellStyle(); @@ -160,7 +165,24 @@ namespace Pilot.Report.Exploitation.AccountsReceivable font3.IsBold = true; // 设置字体加粗 // 将字体应用到单元格样式 style3.SetFont(font3); + style3.DataFormat = workbook.CreateDataFormat().GetFormat("0.00"); + + // 创建一个单元格样式------------------------------- + ICellStyle style4 = workbook.CreateCellStyle(); + + // 设置边框样式 + style4.BorderTop = BorderStyle.Thin; + style4.BorderBottom = BorderStyle.Thin; + style4.BorderLeft = BorderStyle.Thin; + style4.BorderRight = BorderStyle.Thin; + // 设置水平居中对齐 + style4.Alignment = HorizontalAlignment.Left; + // 设置垂直居中对齐 + style4.VerticalAlignment = VerticalAlignment.Center; + // 将字体应用到单元格样式 + style4.SetFont(font3); + style4.DataFormat = workbook.CreateDataFormat().GetFormat("0.00"); #endregion #region 获取金额汇总数据 @@ -175,7 +197,8 @@ namespace Pilot.Report.Exploitation.AccountsReceivable { YFHpriceSum = Math.Round(Convert.ToDecimal(list[i]["ShippedDebt"]), 2); YFPpriceSum = Math.Round(Convert.ToDecimal(list[i]["InvoicedDebt"]), 2); - priceSum = Math.Round(Convert.ToDecimal(list[i]["ShippedDebt"]) + Convert.ToDecimal(list[i]["InvoicedDebt"]), 2); + //priceSum = Math.Round(Convert.ToDecimal(list[i]["ShippedDebt"]) + Convert.ToDecimal(list[i]["InvoicedDebt"]), 2); + priceSum = Math.Round(Convert.ToDecimal(list[i]["OwedTickets"]), 2); } } @@ -242,14 +265,14 @@ namespace Pilot.Report.Exploitation.AccountsReceivable 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; - ICell c5 = rowi.CreateCell(4); c5.SetCellValue(""+ OrderAmount + ""); c5.CellStyle = cellStyle; - ICell c6 = rowi.CreateCell(5); c6.SetCellValue("" + ShipmentsAmount + ""); c6.CellStyle = cellStyle; - ICell c7 = rowi.CreateCell(6); c7.SetCellValue("" + FBillAllAmount + ""); c7.CellStyle = cellStyle; - ICell c8 = rowi.CreateCell(7); c8.SetCellValue("" + OrdeFALLAMOUNTFORrAmount + ""); c8.CellStyle = cellStyle; - ICell c9 = rowi.CreateCell(8); c9.SetCellValue("" + PaymentAmount + ""); c9.CellStyle = cellStyle; - ICell c10 = rowi.CreateCell(9); c10.SetCellValue("" + ShippedDebt + ""); c10.CellStyle = cellStyle; - ICell c11 = rowi.CreateCell(10); c11.SetCellValue("" + InvoicedDebt + ""); c11.CellStyle = cellStyle; - ICell c12 = rowi.CreateCell(11); c12.SetCellValue(list[i]["IsEnded"].ToString()); c12.CellStyle = cellStyle; + ICell c5 = rowi.CreateCell(4); c5.SetCellValue(Convert.ToDouble(OrderAmount)); c5.CellStyle = cellStyle; + ICell c6 = rowi.CreateCell(5); c6.SetCellValue(Convert.ToDouble(ShipmentsAmount )); c6.CellStyle = cellStyle; + ICell c7 = rowi.CreateCell(6); c7.SetCellValue(Convert.ToDouble(FBillAllAmount )); c7.CellStyle = cellStyle; + ICell c8 = rowi.CreateCell(7); c8.SetCellValue(Convert.ToDouble(OrdeFALLAMOUNTFORrAmount )); c8.CellStyle = cellStyle; + 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; n++; if(list[i]["Number"].ToString() == "合计") @@ -282,9 +305,9 @@ namespace Pilot.Report.Exploitation.AccountsReceivable ICell cc1 = rr1.GetCell(6); ICell cc2 = rr2.GetCell(6); ICell cc3 = rr3.GetCell(6); - cc1.SetCellValue("" + YFHpriceSum + ""); - cc2.SetCellValue("" + YFPpriceSum + ""); - cc3.SetCellValue("" + priceSum + ""); + cc1.SetCellValue(Convert.ToDouble(YFHpriceSum)); + cc2.SetCellValue(Convert.ToDouble(YFPpriceSum)); + cc3.SetCellValue(Convert.ToDouble(priceSum)); #endregion @@ -316,10 +339,15 @@ namespace Pilot.Report.Exploitation.AccountsReceivable } ICell CR1 = r1.CreateCell(i); CR1.SetCellValue(test1); - if (i == 4 || i == 5 || i == 6 || i == 7 || i == 8 || i == 9) + if (i == 4 || i == 5 || i == 7 || i == 8 || i == 9) { CR1.CellStyle = style; } + else if(i == 6) + { + CR1.SetCellValue(Convert.ToDouble(test1)); + CR1.CellStyle = style4; + } else { CR1.CellStyle = style2; @@ -336,10 +364,15 @@ namespace Pilot.Report.Exploitation.AccountsReceivable } ICell CR1 = r2.CreateCell(i); CR1.SetCellValue(test1); - if (i == 4 || i == 5 || i == 6 || i == 7 || i == 8 || i == 9) + if (i == 4 || i == 5 || i == 7 || i == 8 || i == 9) { CR1.CellStyle = style; } + else if (i == 6) + { + CR1.SetCellValue(Convert.ToDouble(test1)); + CR1.CellStyle = style4; + } else { CR1.CellStyle = style2; @@ -356,10 +389,15 @@ namespace Pilot.Report.Exploitation.AccountsReceivable } ICell CR1 = r3.CreateCell(i); CR1.SetCellValue(test1); - if (i == 4 || i == 5 || i == 6 || i == 7 || i == 8 || i == 9) + if (i == 4 || i == 5 || i == 7 || i == 8 || i == 9) { CR1.CellStyle = style; } + else if (i == 6) + { + CR1.SetCellValue(Convert.ToDouble(test1)); + CR1.CellStyle = style4; + } else { CR1.CellStyle = style2; @@ -448,7 +486,8 @@ namespace Pilot.Report.Exploitation.AccountsReceivable sheet.AddMergedRegion(cellRangeAddress2); sheet.AddMergedRegion(cellRangeAddress3); } - + //移除第二个工作表 + workbook.RemoveSheetAt(1); #endregion #region Excel代码2