This commit is contained in:
liqionghai 2025-08-28 00:31:42 +08:00
parent 81a2414103
commit 95379dc97a

View File

@ -104,17 +104,24 @@ 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 cellStyle2 = workbook.CreateCellStyle();
@ -127,6 +134,47 @@ namespace Pilot.Report.Exploitation.AccountsReceivable
//垂直居中
cellStyle2.VerticalAlignment = VerticalAlignment.Center;
//设置字体和大小
cellStyle2.SetFont(font1);
// 创建一个单元格样式---------------------------------
ICellStyle cellStyle3 = workbook.CreateCellStyle();
// 设置边框样式
cellStyle3.BorderTop = BorderStyle.Thin;
cellStyle3.BorderBottom = BorderStyle.Thin;
cellStyle3.BorderLeft = BorderStyle.Thin;
cellStyle3.BorderRight = BorderStyle.Thin;
//垂直居中
cellStyle3.VerticalAlignment = VerticalAlignment.Center;
// 设置水平右对齐
cellStyle3.Alignment = HorizontalAlignment.Center;
//设置字体和大小
cellStyle3.SetFont(font1);
// 创建一个单元格样式-------------------------------
ICellStyle cellStyle4 = workbook.CreateCellStyle();
// 设置边框样式
cellStyle4.BorderTop = BorderStyle.Thin;
cellStyle4.BorderBottom = BorderStyle.Thin;
cellStyle4.BorderLeft = BorderStyle.Thin;
cellStyle4.BorderRight = BorderStyle.Thin;
// 设置水平居中对齐
cellStyle4.Alignment = HorizontalAlignment.Right;
// 设置垂直居中对齐
cellStyle4.VerticalAlignment = VerticalAlignment.Center;
//设置数值格式保留两位小数
cellStyle4.DataFormat = workbook.CreateDataFormat().GetFormat("#,##0.00");
// 创建字体并设置为加粗
IFont font4 = workbook.CreateFont();
font4.FontName = "Times New Roman";
font4.FontHeightInPoints = 10;
font4.IsBold = true; // 设置字体加粗
// 将字体应用到单元格样式
cellStyle4.SetFont(font4);
// 创建单元格样式---------------------------------------
ICellStyle style = workbook.CreateCellStyle();
@ -149,6 +197,8 @@ namespace Pilot.Report.Exploitation.AccountsReceivable
// 创建字体并设置为加粗
IFont font2 = workbook.CreateFont();
font2.FontName = "Times New Roman";
font2.FontHeightInPoints = 10;
font2.IsBold = true; // 设置字体加粗
// 将字体应用到单元格样式
@ -168,6 +218,8 @@ namespace Pilot.Report.Exploitation.AccountsReceivable
style3.VerticalAlignment = VerticalAlignment.Center;
// 创建字体并设置为加粗
IFont font3 = workbook.CreateFont();
font3.FontName = "Times New Roman";
font3.FontHeightInPoints = 10;
font3.IsBold = true; // 设置字体加粗
// 将字体应用到单元格样式
style3.SetFont(font3);
@ -186,7 +238,7 @@ 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");
#endregion
#region
@ -223,7 +275,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);
@ -257,10 +309,10 @@ namespace Pilot.Report.Exploitation.AccountsReceivable
continue;
}
string date = string.IsNullOrWhiteSpace(list[i]["DATE"].ToString()) ? "" : list[i]["DATE"].ToString().Split(' ')[0];
string ShipmentsDate = string.IsNullOrWhiteSpace(list[i]["ShipmentsDate"].ToString()) ? "" : list[i]["ShipmentsDate"].ToString().Split(' ')[0];
string date = string.IsNullOrWhiteSpace(list[i]["DATE"].ToString()) ? "" : Convert.ToDateTime(list[i]["DATE"].ToString().Split(' ')[0]).ToString("yyyy/M/d");
string ShipmentsDate = string.IsNullOrWhiteSpace(list[i]["ShipmentsDate"].ToString()) ? "" : string.Join(",",list[i]["ShipmentsDate"].ToString().Split(' ')[0].Split(',').Select(p=>Convert.ToDateTime(p).ToString("yyyy/M/d")).ToList());
string PaymentDate = string.IsNullOrWhiteSpace(list[i]["PaymentDate"].ToString()) ? "" : list[i]["PaymentDate"].ToString().Split(' ')[0];
string BillingDate = string.IsNullOrWhiteSpace(list[i]["ZPBillingDate"].ToString()) ? "" : list[i]["ZPBillingDate"].ToString().Split(' ')[0];
string BillingDate = string.IsNullOrWhiteSpace(list[i]["ZPBillingDate"].ToString()) ? "" : string.Join(",", list[i]["ZPBillingDate"].ToString().Split(' ')[0].Split(',').Select(p => Convert.ToDateTime(p).ToString("yyyy/M/d")).ToList());
string ReturnDate = string.IsNullOrWhiteSpace(list[i]["ReturnDate"].ToString()) ? "" : list[i]["ReturnDate"].ToString().Split(' ')[0];
//BillingDate += string.IsNullOrWhiteSpace(list[i]["PPBillingDate"].ToString()) ? "" : (string.IsNullOrWhiteSpace(BillingDate) ?"":",")+list[i]["PPBillingDate"].ToString().Split(' ')[0];
@ -281,24 +333,24 @@ namespace Pilot.Report.Exploitation.AccountsReceivable
{
c1.SetCellValue(list[i]["OUTPUTNUMBER"].ToString());
}
c1.CellStyle = cellStyle;
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;
ICell c5 = rowi.CreateCell(4); c5.SetCellValue(list[i]["SizeModel"].ToString()); c5.CellStyle = cellStyle2;
ICell c6 = rowi.CreateCell(5); c6.SetCellValue(""); c6.CellStyle = cellStyle; //数量
ICell c6 = rowi.CreateCell(5); c6.SetCellValue(""); c6.CellStyle = cellStyle3; //数量
if(!string.IsNullOrWhiteSpace(list[i]["FQty"].ToString()))
{
int FQty = Convert.ToInt32(list[i]["FQty"]);
c6.SetCellValue(Convert.ToDouble(FQty)); c6.CellStyle = cellStyle; //数量
c6.SetCellValue(Convert.ToDouble(FQty)); c6.CellStyle = cellStyle3; //数量
}
ICell c7 = rowi.CreateCell(6); c7.SetCellValue(""); c7.CellStyle = cellStyle;
ICell c7 = rowi.CreateCell(6); c7.SetCellValue(""); c7.CellStyle = cellStyle3;
if(!string.IsNullOrWhiteSpace(list[i]["FTaxPrice"].ToString()))
{
decimal FTaxPrice = Math.Round(Convert.ToDecimal(list[i]["FTaxPrice"]), 2);
c7.SetCellValue(Convert.ToDouble(FTaxPrice )); c7.CellStyle = cellStyle;
c7.SetCellValue(Convert.ToDouble(FTaxPrice )); c7.CellStyle = cellStyle3;
}
ICell c8 = rowi.CreateCell(7); c8.SetCellValue(""); c8.CellStyle = cellStyle;
@ -316,11 +368,11 @@ namespace Pilot.Report.Exploitation.AccountsReceivable
}
ICell c11 = rowi.CreateCell(10); c11.SetCellValue(""); c11.CellStyle = cellStyle;
ICell c11 = rowi.CreateCell(10); c11.SetCellValue(""); c11.CellStyle = cellStyle3;
if (!string.IsNullOrWhiteSpace(list[i]["ShipmentsNum"].ToString()))
{
int ShipmentsNum = Convert.ToInt32(list[i]["ShipmentsNum"]);
c11.SetCellValue(Convert.ToDouble(ShipmentsNum)); c11.CellStyle = cellStyle;
c11.SetCellValue(Convert.ToDouble(ShipmentsNum)); c11.CellStyle = cellStyle3;
}
ICell c12 = rowi.CreateCell(11); c12.SetCellValue(""); c12.CellStyle = cellStyle;
@ -330,21 +382,21 @@ namespace Pilot.Report.Exploitation.AccountsReceivable
c12.SetCellValue(Convert.ToDouble(ShipmentsAmount)); c12.CellStyle = cellStyle;
}
ICell c14 = rowi.CreateCell(13); c14.SetCellValue(""); c14.CellStyle = cellStyle;
if (!string.IsNullOrWhiteSpace(list[i]["ReturnNum"].ToString()))
{
int ReturnNum = Convert.ToInt32(list[i]["ReturnNum"]);
c14.SetCellValue(Convert.ToDouble(ReturnNum)); c14.CellStyle = cellStyle;
}
//ICell c14 = rowi.CreateCell(13); c14.SetCellValue(""); c14.CellStyle = cellStyle3;
//if (!string.IsNullOrWhiteSpace(list[i]["ReturnNum"].ToString()))
//{
// int ReturnNum = Convert.ToInt32(list[i]["ReturnNum"]);
// c14.SetCellValue(Convert.ToDouble(ReturnNum)); c14.CellStyle = cellStyle3;
//}
ICell c15 = rowi.CreateCell(14); c15.SetCellValue(""); c15.CellStyle = cellStyle;
ICell c15 = rowi.CreateCell(14 - 2); c15.SetCellValue(""); c15.CellStyle = cellStyle;
if (!string.IsNullOrWhiteSpace(list[i]["ReturnAmount"].ToString()))
{
decimal ReturnAmount = Math.Round(Convert.ToDecimal(list[i]["ReturnAmount"]), 2);
c15.SetCellValue(Convert.ToDouble(ReturnAmount)); c15.CellStyle = cellStyle;
}
ICell c19 = rowi.CreateCell(18); c19.SetCellValue(""); c19.CellStyle = cellStyle;
ICell c19 = rowi.CreateCell(18 - 3); c19.SetCellValue(""); c19.CellStyle = cellStyle;
if (!string.IsNullOrWhiteSpace(list[i]["PaymentAmount"].ToString()))
{
@ -352,21 +404,21 @@ namespace Pilot.Report.Exploitation.AccountsReceivable
c19.SetCellValue(Convert.ToDouble(PaymentAmount)); c19.CellStyle = cellStyle;
}
ICell c20 = rowi.CreateCell(19); c20.SetCellValue(""); c20.CellStyle = cellStyle;
ICell c20 = rowi.CreateCell(19 - 3); c20.SetCellValue(""); c20.CellStyle = cellStyle;
if (!string.IsNullOrWhiteSpace(list[i]["ShippedDebt"].ToString()))
{
decimal ShippedDebt = Math.Round(Convert.ToDecimal(list[i]["ShippedDebt"]), 2);
c20.SetCellValue(Convert.ToDouble(ShippedDebt)); c20.CellStyle = cellStyle;
}
ICell c21 = rowi.CreateCell(20); c21.SetCellValue(""); c21.CellStyle = cellStyle;
ICell c21 = rowi.CreateCell(20 - 3); c21.SetCellValue(""); c21.CellStyle = cellStyle;
if (!string.IsNullOrWhiteSpace(list[i]["InvoicedDebt"].ToString()))
{
decimal InvoicedDebt = Math.Round(Convert.ToDecimal(list[i]["InvoicedDebt"]), 2);
c21.SetCellValue(Convert.ToDouble(InvoicedDebt)); c21.CellStyle = cellStyle;
}
ICell c17 = rowi.CreateCell(16); c17.SetCellValue(""); c17.CellStyle = cellStyle;
ICell c17 = rowi.CreateCell(16 - 2); c17.SetCellValue(""); c17.CellStyle = cellStyle;
if (!string.IsNullOrWhiteSpace(list[i]["BillingAmount"].ToString()))
{
@ -375,11 +427,11 @@ namespace Pilot.Report.Exploitation.AccountsReceivable
}
ICell c10 = rowi.CreateCell(9); c10.SetCellValue(ShipmentsDate); c10.CellStyle = cellStyle2;//发货日期
ICell c13 = rowi.CreateCell(12); c13.SetCellValue(ReturnDate); c13.CellStyle = cellStyle2;//退货日期
ICell c16 = rowi.CreateCell(15); c16.SetCellValue(BillingDate); c16.CellStyle = cellStyle2; //开票日期
ICell c18 = rowi.CreateCell(17); c18.SetCellValue(PaymentDate); c18.CellStyle = cellStyle2;//回款日期
ICell c22 = rowi.CreateCell(21); c22.SetCellValue(list[i]["IsEnded"].ToString()); c22.CellStyle = cellStyle2;
ICell c23 = rowi.CreateCell(22); c23.SetCellValue(list[i]["Remark"].ToString()); c23.CellStyle = cellStyle2;
//ICell c13 = rowi.CreateCell(12); c13.SetCellValue(ReturnDate); c13.CellStyle = cellStyle2;//退货日期
ICell c16 = rowi.CreateCell(15 - 2); c16.SetCellValue(BillingDate); c16.CellStyle = cellStyle2; //开票日期
//ICell c18 = rowi.CreateCell(17); c18.SetCellValue(PaymentDate); c18.CellStyle = cellStyle2;//回款日期
ICell c22 = rowi.CreateCell(21 - 3); c22.SetCellValue(list[i]["IsEnded"].ToString()); c22.CellStyle = cellStyle2;
//ICell c23 = rowi.CreateCell(22 - 3); c23.SetCellValue(list[i]["Remark"].ToString()); c23.CellStyle = cellStyle2;
n++;
//根据订单号分组合并单元格
@ -398,17 +450,17 @@ namespace Pilot.Report.Exploitation.AccountsReceivable
CellRangeAddress cellRangeAddress9 = new CellRangeAddress(GroupIndex, j + i - k, 9, 9);
CellRangeAddress cellRangeAddress11 = new CellRangeAddress(GroupIndex, j + i - k, 11, 11);
CellRangeAddress cellRangeAddress12 = new CellRangeAddress(GroupIndex, j + i - k, 12, 12);
CellRangeAddress cellRangeAddress14 = new CellRangeAddress(GroupIndex, j + i - k, 14, 14);
//CellRangeAddress cellRangeAddress12 = new CellRangeAddress(GroupIndex, j + i - k, 12, 12);
CellRangeAddress cellRangeAddress14 = new CellRangeAddress(GroupIndex, j + i - k, 14-2, 14-2);
CellRangeAddress cellRangeAddress15 = new CellRangeAddress(GroupIndex, j + i - k, 15, 15);
CellRangeAddress cellRangeAddress16 = new CellRangeAddress(GroupIndex, j + i - k, 16, 16);
CellRangeAddress cellRangeAddress17 = new CellRangeAddress(GroupIndex, j + i - k, 17, 17);
CellRangeAddress cellRangeAddress18 = new CellRangeAddress(GroupIndex, j + i - k, 18, 18);
CellRangeAddress cellRangeAddress19 = new CellRangeAddress(GroupIndex, j + i - k, 19, 19);
CellRangeAddress cellRangeAddress20 = new CellRangeAddress(GroupIndex, j + i - k, 20, 20);
CellRangeAddress cellRangeAddress21 = new CellRangeAddress(GroupIndex, j + i - k, 21, 21);
CellRangeAddress cellRangeAddress22 = new CellRangeAddress(GroupIndex, j + i - k, 22, 22);
CellRangeAddress cellRangeAddress15 = new CellRangeAddress(GroupIndex, j + i - k, 15 - 2, 15 - 2);
CellRangeAddress cellRangeAddress16 = new CellRangeAddress(GroupIndex, j + i - k, 16 - 2, 16 - 2);
//CellRangeAddress cellRangeAddress17 = new CellRangeAddress(GroupIndex, j + i - k, 17, 17);
CellRangeAddress cellRangeAddress18 = new CellRangeAddress(GroupIndex, j + i - k, 18-3, 18 - 3);
CellRangeAddress cellRangeAddress19 = new CellRangeAddress(GroupIndex, j + i - k, 19 - 3, 19 - 3);
CellRangeAddress cellRangeAddress20 = new CellRangeAddress(GroupIndex, j + i - k, 20 - 3, 20 - 3);
CellRangeAddress cellRangeAddress21 = new CellRangeAddress(GroupIndex, j + i - k, 21 - 3, 21 - 3);
CellRangeAddress cellRangeAddress22 = new CellRangeAddress(GroupIndex, j + i - k, 22 - 3, 22 - 3);
// 检查并移除重叠的合并区域
RemoveOverlappingMergedRegions(sheet, cellRangeAddress0);
@ -420,12 +472,12 @@ namespace Pilot.Report.Exploitation.AccountsReceivable
RemoveOverlappingMergedRegions(sheet, cellRangeAddress9);
RemoveOverlappingMergedRegions(sheet, cellRangeAddress11);
RemoveOverlappingMergedRegions(sheet, cellRangeAddress12);
//RemoveOverlappingMergedRegions(sheet, cellRangeAddress12);
RemoveOverlappingMergedRegions(sheet, cellRangeAddress14);
RemoveOverlappingMergedRegions(sheet, cellRangeAddress15);
RemoveOverlappingMergedRegions(sheet, cellRangeAddress16);
RemoveOverlappingMergedRegions(sheet, cellRangeAddress17);
//RemoveOverlappingMergedRegions(sheet, cellRangeAddress17);
RemoveOverlappingMergedRegions(sheet, cellRangeAddress18);
RemoveOverlappingMergedRegions(sheet, cellRangeAddress19);
RemoveOverlappingMergedRegions(sheet, cellRangeAddress20);
@ -442,12 +494,12 @@ namespace Pilot.Report.Exploitation.AccountsReceivable
sheet.AddMergedRegion(cellRangeAddress9);
sheet.AddMergedRegion(cellRangeAddress11);
sheet.AddMergedRegion(cellRangeAddress12);
//sheet.AddMergedRegion(cellRangeAddress12);
sheet.AddMergedRegion(cellRangeAddress14);
sheet.AddMergedRegion(cellRangeAddress15);
sheet.AddMergedRegion(cellRangeAddress16);
sheet.AddMergedRegion(cellRangeAddress17);
//sheet.AddMergedRegion(cellRangeAddress17);
sheet.AddMergedRegion(cellRangeAddress18);
sheet.AddMergedRegion(cellRangeAddress19);
sheet.AddMergedRegion(cellRangeAddress20);
@ -472,22 +524,22 @@ namespace Pilot.Report.Exploitation.AccountsReceivable
c5.CellStyle = style3;
c6.CellStyle = style3;
c7.CellStyle = style3;
c8.CellStyle = style3;
c9.CellStyle = style3;
c8.CellStyle = cellStyle4;
c9.CellStyle = cellStyle4;
c10.CellStyle = style3;
c11.CellStyle = style3;
c12.CellStyle = style3;
c13.CellStyle = style3;
c14.CellStyle = style3;
c15.CellStyle = style3;
c12.CellStyle = cellStyle4;
//c13.CellStyle = style3;
//c14.CellStyle = style3;
c15.CellStyle = cellStyle4;
c16.CellStyle = style3;
c17.CellStyle = style3;
c18.CellStyle = style3;
c19.CellStyle = style3;
c20.CellStyle = style3;
c21.CellStyle = style3;
c17.CellStyle = cellStyle4;
//c18.CellStyle = style3;
c19.CellStyle = cellStyle4;
c20.CellStyle = cellStyle4;
c21.CellStyle = cellStyle4;
c22.CellStyle = style3;
c23.CellStyle = style3;
//c23.CellStyle = style3;
}
}