diff --git a/Controllers/ApiController.cs b/Controllers/ApiController.cs index a1774874..bf304e72 100644 --- a/Controllers/ApiController.cs +++ b/Controllers/ApiController.cs @@ -207,6 +207,7 @@ namespace QuotationMaker.Controllers row = (XSSFRow)sheet.GetRow(16); row.Cells[0].SetCellValue(row.Cells[0].StringCellValue.Replace("{quotation_sa}", services_aggrement)); + //付款方式與發票 string quotation_grandTotal = ChtNumConverter.ToChtNum((long)objDetail.quotation_grandTotal); @@ -287,6 +288,9 @@ namespace QuotationMaker.Controllers //優惠總價為置 int specTotalIndex = 12; + //服務協議位置 + int saIndex = 16; + //主項目編號 int itemNumber = 0; //開始產生項目價格列 @@ -306,6 +310,7 @@ namespace QuotationMaker.Controllers sutTotalAcIndex++; specTotalIndex++; saRowIndex++; + saIndex++; foreach (quotationSubItem objSub in objMain.quotationSubItems) { CopyRow((XSSFWorkbook)workbook, (XSSFSheet)sheet, editRowIndex, editRowIndex + 1); @@ -316,12 +321,13 @@ namespace QuotationMaker.Controllers sutTotalAcIndex++; specTotalIndex ++; saRowIndex++; + saIndex++; rowCount++; } //項目編號合併並填入編號 - sheet.AddMergedRegion(new NPOI.SS.Util.CellRangeAddress(editIndex, editIndex + rowCount, 0, 0)); + //sheet.AddMergedRegion(new NPOI.SS.Util.CellRangeAddress(editIndex, editIndex + rowCount, 0, 0)); sheet.AddMergedRegion(new NPOI.SS.Util.CellRangeAddress(editIndex, editIndex, 1, 6)); row = (XSSFRow)sheet.GetRow(editIndex); @@ -330,9 +336,14 @@ namespace QuotationMaker.Controllers int acTotal = 0; + int subItemNum = 0; //合併子項目row foreach (quotationSubItem objSub in objMain.quotationSubItems) { + subItemNum++; + + string subItemNumberTxt = itemNumber.ToString() + "-" + subItemNum.ToString(); + string descript = objSub.quotationSubItem_descript; if (objSub.quotationSubItem_hasAC == "N" && objMain.quotationMainItem_ac > 0) @@ -343,6 +354,7 @@ namespace QuotationMaker.Controllers editIndex++; row = (XSSFRow)sheet.GetRow(editIndex); row.Height = -1; + row.Cells[0].SetCellValue(subItemNumberTxt); row.Cells[1].SetCellValue(objSub.quotationSubItem_name); row.Cells[2].SetCellValue(descript); @@ -411,6 +423,7 @@ namespace QuotationMaker.Controllers sutTotalAcIndex+=3; specTotalIndex+=3; saRowIndex += 3; + saIndex +=3; //複製小計欄 CopyRow((XSSFWorkbook)workbook, (XSSFSheet)sheet, subTotalIndex, editIndex); @@ -425,6 +438,7 @@ namespace QuotationMaker.Controllers editIndex++; editRowIndex++; + //複製AC欄 CopyRow((XSSFWorkbook)workbook, (XSSFSheet)sheet, acIndex, editIndex); @@ -439,6 +453,14 @@ namespace QuotationMaker.Controllers editIndex++; editRowIndex++; + + if (objMain.quotationMainItem_ac <= 0) { + row.ZeroHeight = true; + } + + + + //複製此項目總金額欄 CopyRow((XSSFWorkbook)workbook, (XSSFSheet)sheet, sutTotalAcIndex, editIndex); row = (XSSFRow)sheet.GetRow(editIndex); @@ -496,14 +518,101 @@ namespace QuotationMaker.Controllers saRowIndex--; } - row = (XSSFRow)sheet.GetRow(saRowIndex); - row.Height = 8190; - row = (XSSFRow)sheet.GetRow(saRowIndex + 1); - row.Height = 8190; + //自适应高度,9代表从第10行开始,表头部分不会多行;endRow是结束的行,也就是有数据内容的行数,毕竟没内容的单元格,也没必要自适应行高 + for (int i = saRowIndex; i < saRowIndex + 3; i++) + { + if (sheet.GetRow(i) == null) + { + continue; + } + IRow ICurRow = sheet.GetRow(i); + int OldHg = ICurRow.Height;//当前行高 + int newHg = ICurRow.Height;//新行高,默认与当前行高一致 - row = (XSSFRow)sheet.GetRow(saRowIndex + 2); - row.Height = 8000; + for (int j = 0; j < 1; j++) { + if (ICurRow.GetCell(j) == null) + { + continue; + } + ICell CurCell = ICurRow.GetCell(j); + + double cellWidth = 0; + + for (int k = 0; k < 7; k++) { + cellWidth += sheet.GetColumnWidth(k); + } + + int cellStringLength = GetCellStringLength(CurCell.StringCellValue); + + if (cellStringLength > cellWidth) { + double newHg1 = (double)(OldHg * (cellStringLength / cellWidth + 1)); + + double lastHg = newHg1; + + if (lastHg > 8190) { + row = (XSSFRow)sheet.GetRow(saRowIndex); + row.Height = 8190; + + lastHg = lastHg - 8190; + } + + if (lastHg > 8190) + { + + + row = (XSSFRow)sheet.GetRow(saRowIndex + 1); + + row.Height = 8190; + + lastHg = lastHg - 8190; + } + else { + row = (XSSFRow)sheet.GetRow(saRowIndex + 1); + + row.Height = (short)lastHg; + + lastHg = lastHg - 8190; + } + + if (lastHg > 0) { + + + row = (XSSFRow)sheet.GetRow(saRowIndex + 2); + + if (lastHg > 8190) + { + + row.Height = 8190; + } + else + { + row.Height = (short)lastHg; + } + } + + } + + + + } + + + } + + + //sheet.AutoSizeRow(saRowIndex); + //sheet.AutoSizeRow(saRowIndex + 1); + //sheet.AutoSizeRow(saRowIndex + 2); + + //row = (XSSFRow)sheet.GetRow(saRowIndex); + //row.Height = 8190; + + //row = (XSSFRow)sheet.GetRow(saRowIndex + 1); + //row.Height = 8190; + + //row = (XSSFRow)sheet.GetRow(saRowIndex + 2); + //row.Height = 8000; MemoryStream ms = new MemoryStream(); workbook.Write(ms); @@ -531,8 +640,38 @@ namespace QuotationMaker.Controllers return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); } - + /// + /// 计算单元格内容长度 + /// 用 ASCII 码范围判断字符是不是汉字 + /// + /// 待判断字符或字符串 + /// 宽度 + public int GetCellStringLength(string text) + { + //汉字 453、数字和字母 239 + //这里的汉字与字母的宽度值,要根据Excel的字体大小计算 + //例如你单元格宽度1000,能放10个汉字,那汉字宽度就是1000/10=100 + //同理计算字母宽度 + int result = 0; + foreach (char t in text) + { + if (t == 10) + { + //忽略字符串中的换行符\n + continue; + } + else if (t > 127) + { + result += 660; + } + else + { + result += 370; + } + } + return result; + } /// diff --git a/Modals/GlobalClass.cs b/Modals/GlobalClass.cs index cd4c3068..42a06b85 100644 --- a/Modals/GlobalClass.cs +++ b/Modals/GlobalClass.cs @@ -222,6 +222,10 @@ public static class GlobalClass } } + + + + /// /// 日期转换为中文大写 /// @@ -236,6 +240,9 @@ public class UpperConvert //把数字转换为大写 public string numtoUpper(int num) { + + + String str = num.ToString(); string rstr = ""; int n; @@ -259,6 +266,33 @@ public class UpperConvert } return rstr; } + + public string yeartoUpper(int number) + { + string[] chineseNumber = { "零", "一", "二", "三", "四", "五", "六", "七", "八", "九" }; + string[] unit = { "", "十", "百", "千", "萬", "十萬", "百萬", "千萬", "億", "十億", "百億", "千億", "兆", "十兆", "百兆", "千兆" }; + StringBuilder ret = new StringBuilder(); + string inputNumber = number.ToString(); + int idx = inputNumber.Length; + bool needAppendZero = false; + foreach (char c in inputNumber) + { + idx--; + if (c > '0') + { + if (needAppendZero) + { + ret.Append(chineseNumber[0]); + needAppendZero = false; + } + ret.Append(chineseNumber[(int)(c - '0')] + unit[idx]); + } + else + needAppendZero = true; + } + return ret.Length == 0 ? chineseNumber[0] : ret.ToString(); + } + //月转化为大写 public string monthtoUpper(int month) { @@ -298,10 +332,10 @@ public class UpperConvert //日期转换为大写 public string dateToUpper(System.DateTime date) { - int year = date.Year; + int year = date.Year - 1911; int month = date.Month; int day = date.Day; - return numtoUpper(year) + "年" + monthtoUpper(month) + "月" + daytoUpper(day) + "日"; + return yeartoUpper(year) + "年" + monthtoUpper(month) + "月" + daytoUpper(day) + "日"; } } diff --git a/Views/Home/ProjectList.cshtml b/Views/Home/ProjectList.cshtml index 3f89f8a9..7cedc0b1 100644 --- a/Views/Home/ProjectList.cshtml +++ b/Views/Home/ProjectList.cshtml @@ -182,7 +182,7 @@
- +
diff --git a/wwwroot/logo/bremen_temp.xlsx b/wwwroot/logo/bremen_temp.xlsx index 74fa13eb..d2277619 100644 Binary files a/wwwroot/logo/bremen_temp.xlsx and b/wwwroot/logo/bremen_temp.xlsx differ diff --git a/wwwroot/logo/journeys_temp.xlsx b/wwwroot/logo/journeys_temp.xlsx index 923eea48..585f633f 100644 Binary files a/wwwroot/logo/journeys_temp.xlsx and b/wwwroot/logo/journeys_temp.xlsx differ