forked from dk96/QuotationMaker
fixed table and excel
parent
c0e9cf4748
commit
5f49b51dd1
|
|
@ -208,6 +208,7 @@ namespace QuotationMaker.Controllers
|
||||||
row.Cells[0].SetCellValue(row.Cells[0].StringCellValue.Replace("{quotation_sa}", services_aggrement));
|
row.Cells[0].SetCellValue(row.Cells[0].StringCellValue.Replace("{quotation_sa}", services_aggrement));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//付款方式與發票
|
//付款方式與發票
|
||||||
string quotation_grandTotal = ChtNumConverter.ToChtNum((long)objDetail.quotation_grandTotal);
|
string quotation_grandTotal = ChtNumConverter.ToChtNum((long)objDetail.quotation_grandTotal);
|
||||||
string quotation_grandTotalStr = "本專案費用總計新台幣"+ quotation_grandTotal + "圓整 (即NTD" + objDetail.quotation_grandTotal.ToString("###,###") + "含稅)";
|
string quotation_grandTotalStr = "本專案費用總計新台幣"+ quotation_grandTotal + "圓整 (即NTD" + objDetail.quotation_grandTotal.ToString("###,###") + "含稅)";
|
||||||
|
|
@ -287,6 +288,9 @@ namespace QuotationMaker.Controllers
|
||||||
//優惠總價為置
|
//優惠總價為置
|
||||||
int specTotalIndex = 12;
|
int specTotalIndex = 12;
|
||||||
|
|
||||||
|
//服務協議位置
|
||||||
|
int saIndex = 16;
|
||||||
|
|
||||||
//主項目編號
|
//主項目編號
|
||||||
int itemNumber = 0;
|
int itemNumber = 0;
|
||||||
//開始產生項目價格列
|
//開始產生項目價格列
|
||||||
|
|
@ -306,6 +310,7 @@ namespace QuotationMaker.Controllers
|
||||||
sutTotalAcIndex++;
|
sutTotalAcIndex++;
|
||||||
specTotalIndex++;
|
specTotalIndex++;
|
||||||
saRowIndex++;
|
saRowIndex++;
|
||||||
|
saIndex++;
|
||||||
|
|
||||||
foreach (quotationSubItem objSub in objMain.quotationSubItems) {
|
foreach (quotationSubItem objSub in objMain.quotationSubItems) {
|
||||||
CopyRow((XSSFWorkbook)workbook, (XSSFSheet)sheet, editRowIndex, editRowIndex + 1);
|
CopyRow((XSSFWorkbook)workbook, (XSSFSheet)sheet, editRowIndex, editRowIndex + 1);
|
||||||
|
|
@ -316,12 +321,13 @@ namespace QuotationMaker.Controllers
|
||||||
sutTotalAcIndex++;
|
sutTotalAcIndex++;
|
||||||
specTotalIndex ++;
|
specTotalIndex ++;
|
||||||
saRowIndex++;
|
saRowIndex++;
|
||||||
|
saIndex++;
|
||||||
|
|
||||||
rowCount++;
|
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));
|
sheet.AddMergedRegion(new NPOI.SS.Util.CellRangeAddress(editIndex, editIndex, 1, 6));
|
||||||
|
|
||||||
row = (XSSFRow)sheet.GetRow(editIndex);
|
row = (XSSFRow)sheet.GetRow(editIndex);
|
||||||
|
|
@ -330,9 +336,14 @@ namespace QuotationMaker.Controllers
|
||||||
|
|
||||||
int acTotal = 0;
|
int acTotal = 0;
|
||||||
|
|
||||||
|
int subItemNum = 0;
|
||||||
//合併子項目row
|
//合併子項目row
|
||||||
foreach (quotationSubItem objSub in objMain.quotationSubItems)
|
foreach (quotationSubItem objSub in objMain.quotationSubItems)
|
||||||
{
|
{
|
||||||
|
subItemNum++;
|
||||||
|
|
||||||
|
string subItemNumberTxt = itemNumber.ToString() + "-" + subItemNum.ToString();
|
||||||
|
|
||||||
string descript = objSub.quotationSubItem_descript;
|
string descript = objSub.quotationSubItem_descript;
|
||||||
|
|
||||||
if (objSub.quotationSubItem_hasAC == "N" && objMain.quotationMainItem_ac > 0)
|
if (objSub.quotationSubItem_hasAC == "N" && objMain.quotationMainItem_ac > 0)
|
||||||
|
|
@ -343,6 +354,7 @@ namespace QuotationMaker.Controllers
|
||||||
editIndex++;
|
editIndex++;
|
||||||
row = (XSSFRow)sheet.GetRow(editIndex);
|
row = (XSSFRow)sheet.GetRow(editIndex);
|
||||||
row.Height = -1;
|
row.Height = -1;
|
||||||
|
row.Cells[0].SetCellValue(subItemNumberTxt);
|
||||||
row.Cells[1].SetCellValue(objSub.quotationSubItem_name);
|
row.Cells[1].SetCellValue(objSub.quotationSubItem_name);
|
||||||
row.Cells[2].SetCellValue(descript);
|
row.Cells[2].SetCellValue(descript);
|
||||||
|
|
||||||
|
|
@ -411,6 +423,7 @@ namespace QuotationMaker.Controllers
|
||||||
sutTotalAcIndex+=3;
|
sutTotalAcIndex+=3;
|
||||||
specTotalIndex+=3;
|
specTotalIndex+=3;
|
||||||
saRowIndex += 3;
|
saRowIndex += 3;
|
||||||
|
saIndex +=3;
|
||||||
|
|
||||||
//複製小計欄
|
//複製小計欄
|
||||||
CopyRow((XSSFWorkbook)workbook, (XSSFSheet)sheet, subTotalIndex, editIndex);
|
CopyRow((XSSFWorkbook)workbook, (XSSFSheet)sheet, subTotalIndex, editIndex);
|
||||||
|
|
@ -425,6 +438,7 @@ namespace QuotationMaker.Controllers
|
||||||
|
|
||||||
editIndex++;
|
editIndex++;
|
||||||
editRowIndex++;
|
editRowIndex++;
|
||||||
|
|
||||||
//複製AC欄
|
//複製AC欄
|
||||||
CopyRow((XSSFWorkbook)workbook, (XSSFSheet)sheet, acIndex, editIndex);
|
CopyRow((XSSFWorkbook)workbook, (XSSFSheet)sheet, acIndex, editIndex);
|
||||||
|
|
||||||
|
|
@ -439,6 +453,14 @@ namespace QuotationMaker.Controllers
|
||||||
|
|
||||||
editIndex++;
|
editIndex++;
|
||||||
editRowIndex++;
|
editRowIndex++;
|
||||||
|
|
||||||
|
if (objMain.quotationMainItem_ac <= 0) {
|
||||||
|
row.ZeroHeight = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//複製此項目總金額欄
|
//複製此項目總金額欄
|
||||||
CopyRow((XSSFWorkbook)workbook, (XSSFSheet)sheet, sutTotalAcIndex, editIndex);
|
CopyRow((XSSFWorkbook)workbook, (XSSFSheet)sheet, sutTotalAcIndex, editIndex);
|
||||||
row = (XSSFRow)sheet.GetRow(editIndex);
|
row = (XSSFRow)sheet.GetRow(editIndex);
|
||||||
|
|
@ -496,14 +518,101 @@ namespace QuotationMaker.Controllers
|
||||||
saRowIndex--;
|
saRowIndex--;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//自适应高度,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;//新行高,默认与当前行高一致
|
||||||
|
|
||||||
|
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 = (XSSFRow)sheet.GetRow(saRowIndex);
|
||||||
row.Height = 8190;
|
row.Height = 8190;
|
||||||
|
|
||||||
|
lastHg = lastHg - 8190;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lastHg > 8190)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
row = (XSSFRow)sheet.GetRow(saRowIndex + 1);
|
row = (XSSFRow)sheet.GetRow(saRowIndex + 1);
|
||||||
|
|
||||||
row.Height = 8190;
|
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);
|
row = (XSSFRow)sheet.GetRow(saRowIndex + 2);
|
||||||
row.Height = 8000;
|
|
||||||
|
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();
|
MemoryStream ms = new MemoryStream();
|
||||||
workbook.Write(ms);
|
workbook.Write(ms);
|
||||||
|
|
@ -532,7 +641,37 @@ namespace QuotationMaker.Controllers
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 计算单元格内容长度
|
||||||
|
/// 用 ASCII 码范围判断字符是不是汉字
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="text">待判断字符或字符串</param>
|
||||||
|
/// <returns>宽度</returns>
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
///
|
///
|
||||||
|
|
|
||||||
|
|
@ -222,6 +222,10 @@ public static class GlobalClass
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 日期转换为中文大写
|
/// 日期转换为中文大写
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -236,6 +240,9 @@ public class UpperConvert
|
||||||
//把数字转换为大写
|
//把数字转换为大写
|
||||||
public string numtoUpper(int num)
|
public string numtoUpper(int num)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
String str = num.ToString();
|
String str = num.ToString();
|
||||||
string rstr = "";
|
string rstr = "";
|
||||||
int n;
|
int n;
|
||||||
|
|
@ -259,6 +266,33 @@ public class UpperConvert
|
||||||
}
|
}
|
||||||
return rstr;
|
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)
|
public string monthtoUpper(int month)
|
||||||
{
|
{
|
||||||
|
|
@ -298,10 +332,10 @@ public class UpperConvert
|
||||||
//日期转换为大写
|
//日期转换为大写
|
||||||
public string dateToUpper(System.DateTime date)
|
public string dateToUpper(System.DateTime date)
|
||||||
{
|
{
|
||||||
int year = date.Year;
|
int year = date.Year - 1911;
|
||||||
int month = date.Month;
|
int month = date.Month;
|
||||||
int day = date.Day;
|
int day = date.Day;
|
||||||
return numtoUpper(year) + "年" + monthtoUpper(month) + "月" + daytoUpper(day) + "日";
|
return yeartoUpper(year) + "年" + monthtoUpper(month) + "月" + daytoUpper(day) + "日";
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -182,7 +182,7 @@
|
||||||
|
|
||||||
<div class="col-md-12" id="project_name_div">
|
<div class="col-md-12" id="project_name_div">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="project_name">專案名稱</label> <input type="text" id="project_name" class="form-control">
|
<label for="project_name">專案名稱</label> <input type="text" id="project_name" maxlength="60" class="form-control">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-12" id="prm_project_serial">
|
<div class="col-md-12" id="prm_project_serial">
|
||||||
|
|
|
||||||
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue