1
0
Fork 0

fix float in excel

master
嘉祥 詹 2024-09-18 15:16:02 +08:00
parent 33cd0cda3a
commit 3336c4ced7
2 changed files with 71 additions and 10 deletions

View File

@ -137,15 +137,28 @@ namespace QuotationMaker.Controllers
// Copy style from old cell and apply to new cell // Copy style from old cell and apply to new cell
XSSFCellStyle copyTempCellStyle = (XSSFCellStyle)workbook.CreateCellStyle(); XSSFCellStyle copyTempCellStyle = (XSSFCellStyle)workbook.CreateCellStyle();
// Copy style from old cell and apply to new cell
XSSFCellStyle copyTempCellFloatStyle = (XSSFCellStyle)workbook.CreateCellStyle();
//估價單總價項目 //估價單總價項目
row = (XSSFRow)sheet.GetRow(11); row = (XSSFRow)sheet.GetRow(11);
copyTempCellStyle.CloneStyleFrom(row.Cells[6].CellStyle); copyTempCellStyle.CloneStyleFrom(row.Cells[6].CellStyle);
copyTempCellFloatStyle.CloneStyleFrom(row.Cells[6].CellStyle);
copyTempCellStyle.DataFormat = workbook.CreateDataFormat().GetFormat("\"NTD \"#,##0"); copyTempCellStyle.DataFormat = workbook.CreateDataFormat().GetFormat("\"NTD \"#,##0");
copyTempCellFloatStyle.DataFormat = workbook.CreateDataFormat().GetFormat("\"NTD \"#,##0.#");
row.Cells[6].SetCellType(CellType.Numeric); row.Cells[6].SetCellType(CellType.Numeric);
row.Cells[6].SetCellValue(objDetail.quotation_noTaxTotal); row.Cells[6].SetCellValue(objDetail.quotation_noTaxTotal);
if (objDetail.quotation_noTaxTotal.ToString().IndexOf('.') >= 0)
{
row.Cells[6].CellStyle = copyTempCellFloatStyle;
}
else {
row.Cells[6].CellStyle = copyTempCellStyle; row.Cells[6].CellStyle = copyTempCellStyle;
}
row = (XSSFRow)sheet.GetRow(12); row = (XSSFRow)sheet.GetRow(12);
@ -154,6 +167,9 @@ namespace QuotationMaker.Controllers
if (objDetail.quotation_specTotal > 0) { if (objDetail.quotation_specTotal > 0) {
row.Cells[6].SetCellType(CellType.Numeric); row.Cells[6].SetCellType(CellType.Numeric);
row.Cells[6].SetCellValue(objDetail.quotation_specTotal); row.Cells[6].SetCellValue(objDetail.quotation_specTotal);
row.Cells[6].CellStyle = copyTempCellStyle; row.Cells[6].CellStyle = copyTempCellStyle;
} else { } else {
row.Cells[6].SetCellValue(""); row.Cells[6].SetCellValue("");
@ -166,7 +182,17 @@ namespace QuotationMaker.Controllers
//row.Cells[6].SetCellValue(row.Cells[6].StringCellValue.Replace("{quotation_tax}", objDetail.quotation_tax.ToString("###,###"))); //row.Cells[6].SetCellValue(row.Cells[6].StringCellValue.Replace("{quotation_tax}", objDetail.quotation_tax.ToString("###,###")));
row.Cells[6].SetCellType(CellType.Numeric); row.Cells[6].SetCellType(CellType.Numeric);
row.Cells[6].SetCellValue(objDetail.quotation_tax); row.Cells[6].SetCellValue(objDetail.quotation_tax);
if (objDetail.quotation_tax.ToString().IndexOf('.') >= 0)
{
row.Cells[6].CellStyle = copyTempCellFloatStyle;
}
else
{
row.Cells[6].CellStyle = copyTempCellStyle; row.Cells[6].CellStyle = copyTempCellStyle;
}
//row.Cells[6].CellStyle = copyTempCellStyle;
row = (XSSFRow)sheet.GetRow(14); row = (XSSFRow)sheet.GetRow(14);
//row.Cells[6].SetCellValue(row.Cells[6].StringCellValue.Replace("{quotation_grandTotal}", objDetail.quotation_grandTotal.ToString("###,###"))); //row.Cells[6].SetCellValue(row.Cells[6].StringCellValue.Replace("{quotation_grandTotal}", objDetail.quotation_grandTotal.ToString("###,###")));
@ -322,18 +348,48 @@ namespace QuotationMaker.Controllers
row.Cells[3].SetCellType(CellType.Numeric); row.Cells[3].SetCellType(CellType.Numeric);
row.Cells[3].SetCellValue(objSub.quotationSubItem_price); row.Cells[3].SetCellValue(objSub.quotationSubItem_price);
if (objSub.quotationSubItem_price.ToString().IndexOf('.') >= 0)
{
row.Cells[3].CellStyle = copyTempCellFloatStyle;
}
else
{
row.Cells[3].CellStyle = copyTempCellStyle; row.Cells[3].CellStyle = copyTempCellStyle;
}
//row.Cells[3].CellStyle = copyTempCellStyle;
row.Cells[4].SetCellType(CellType.Numeric); row.Cells[4].SetCellType(CellType.Numeric);
row.Cells[4].SetCellValue(objSub.quotationSubItem_number); row.Cells[4].SetCellValue(objSub.quotationSubItem_number);
if (objSub.quotationSubItem_number.ToString().IndexOf('.') >= 0)
{
row.Cells[4].CellStyle = copyTempCellFloatStyle;
}
else
{
row.Cells[4].CellStyle = copyTempCellStyle; row.Cells[4].CellStyle = copyTempCellStyle;
}
//row.Cells[4].CellStyle = copyTempCellStyle;
row.Cells[5].SetCellValue(objSub.quotationSubItem_unitType); row.Cells[5].SetCellValue(objSub.quotationSubItem_unitType);
row.Cells[6].SetCellType(CellType.Numeric); row.Cells[6].SetCellType(CellType.Numeric);
row.Cells[6].SetCellValue(objSub.quotationSubItem_subTotal); row.Cells[6].SetCellValue(objSub.quotationSubItem_subTotal);
if (objSub.quotationSubItem_subTotal.ToString().IndexOf('.') >= 0)
{
row.Cells[6].CellStyle = copyTempCellFloatStyle;
}
else
{
row.Cells[6].CellStyle = copyTempCellStyle; row.Cells[6].CellStyle = copyTempCellStyle;
}
//row.Cells[6].CellStyle = copyTempCellStyle;
//row.Cells[3].SetCellValue("NTD " + objSub.quotationSubItem_price.ToString("###,###")); //row.Cells[3].SetCellValue("NTD " + objSub.quotationSubItem_price.ToString("###,###"));
//row.Cells[4].SetCellValue(objSub.quotationSubItem_number.ToString("###,###")); //row.Cells[4].SetCellValue(objSub.quotationSubItem_number.ToString("###,###"));

View File

@ -295,11 +295,16 @@ function checkUrl(url) {
} }
//數字處理為有千分位 //數字處理為有千分位
function AppendComma(n) { function AppendComma(number) {
var parts = number.toString().split(".");
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
return parts.join(".");
}
function AppendComma2(n) {
if (!/^((-*\d+)|(0))$/.test(n)) { if (!/^((-*\d+)|(0))$/.test(n)) {
var newValue = /^((-*\d+)|(0))$/.exec(n); var newValue = /^((-*\d+)|(0))$/.exec(n);
if (newValue != null) { if (newValue != null) {
if (parseInt(newValue, 10)) { if (parseFloat(newValue, 10)) {
n = newValue; n = newValue;
} }
else { else {
@ -310,11 +315,11 @@ function AppendComma(n) {
n = '0'; n = '0';
} }
} }
if (parseInt(n, 10) == 0) { if (parseFloat(n, 10) == 0) {
n = '0'; n = '0';
} }
else { else {
n = parseInt(n, 10).toString(); n = parseFloat(n, 10).toString();
} }
n += ''; n += '';