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");
}
-
+ ///