From 53827fd32bde3fa1ffaa1eb8c30b72566b2f1c72 Mon Sep 17 00:00:00 2001 From: dk96 Date: Fri, 3 Jan 2025 17:51:26 +0800 Subject: [PATCH] update formula 1 --- Controllers/ApiController.cs | 27 ++++++++++++++++++++++++--- Modals/GlobalClass.cs | 14 ++++++++++++++ 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/Controllers/ApiController.cs b/Controllers/ApiController.cs index 26814151..8ca3db31 100644 --- a/Controllers/ApiController.cs +++ b/Controllers/ApiController.cs @@ -22,6 +22,7 @@ using System.Web; using NPOI.SS.Util; using NPOI.XSSF.Streaming; using System.IO; +using System.Linq; namespace QuotationMaker.Controllers { @@ -382,7 +383,7 @@ namespace QuotationMaker.Controllers greyStyle2.FillForegroundColor = 0; ((XSSFColor)greyStyle2.FillForegroundColorColor).SetRgb(new byte[] { r, g, b }); greyStyle2.FillPattern = FillPattern.SolidForeground; - + row.Cells[0].CellStyle = greyStyle1; row.Cells[1].CellStyle = greyStyle2; @@ -392,6 +393,10 @@ namespace QuotationMaker.Controllers int acTotal = 0; int subItemNum = 0; + + int rangeSubStart = editIndex + 1; + int rangeSubEnd = editIndex + 1; + int[] acRowIndArr = new int[0]; //合併子項目row foreach (quotationSubItem objSub in objMain.quotationSubItems) { @@ -406,7 +411,17 @@ namespace QuotationMaker.Controllers descript = descript + " (此項不加AC)"; } + + + editIndex++; + rangeSubEnd = editIndex; + + if (objSub.quotationSubItem_hasAC == "Y" && objMain.quotationMainItem_ac > 0) + { + acRowIndArr.ToList().Append(editIndex); + } + row = (XSSFRow)sheet.GetRow(editIndex); row.Height = -1; row.Cells[0].SetCellValue(subItemNumberTxt); @@ -485,9 +500,13 @@ namespace QuotationMaker.Controllers row = (XSSFRow)sheet.GetRow(editIndex); //row.Cells[6].SetCellValue("NTD " + (objMain.quotationMainItem_subTotal - acTotal).ToString("###,###")); - row.Cells[6].SetCellType(CellType.Numeric); - row.Cells[6].SetCellValue((objMain.quotationMainItem_subTotal - acTotal)); + // 20250103 先刪除測試公式 row.Cells[6].SetCellType(CellType.Numeric); + // 20250103 先刪除測試公式 row.Cells[6].SetCellValue((objMain.quotationMainItem_subTotal - acTotal)); + row.Cells[6].SetCellType(CellType.Formula); + string tmpForm1 = "SUM(G" + (rangeSubStart + 1).ToString() + ":G" + (rangeSubEnd + 1).ToString() + ")"; + row.Cells[6].SetCellFormula(tmpForm1); row.Cells[6].CellStyle = copyTempCellStyleRight; + row.Cells[6].SetCellType(CellType.Formula); rowCount++; @@ -678,6 +697,8 @@ namespace QuotationMaker.Controllers //row = (XSSFRow)sheet.GetRow(saRowIndex + 2); //row.Height = 8000; + XSSFFormulaEvaluator.EvaluateAllFormulaCells(workbook); + MemoryStream ms = new MemoryStream(); workbook.Write(ms); ms.Flush(); diff --git a/Modals/GlobalClass.cs b/Modals/GlobalClass.cs index 42a06b85..fa486ff5 100644 --- a/Modals/GlobalClass.cs +++ b/Modals/GlobalClass.cs @@ -13,6 +13,20 @@ public static class GlobalClass return Uri.IsWellFormedUriString(url, UriKind.Absolute); } + public static string indexToEng(int Number) + { + string allChar = "A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z"; + string[] allCharArray = allChar.Split(','); + + if (Number > 25) + { + return ""; + } + else + { + return allCharArray[Number]; + } + } public static string GetIP(this HttpContext context) {