From 7540f407937eac25d13362866405c4b36e04fe41 Mon Sep 17 00:00:00 2001
From: zhizhijie <zhizhijie@users.noreply.gitee.com>
Date: 星期日, 20 九月 2026 09:08:34 +0800
Subject: [PATCH] refactor(汇总表): 数值全精度写入 + 单元格格式统一两位小数显示
---
traffic-audit-server/src/main/java/com/trafficaudit/reportexport/service/ReportExportService.java | 140 +++++++++++++++++++++++++---------------------
1 files changed, 75 insertions(+), 65 deletions(-)
diff --git a/traffic-audit-server/src/main/java/com/trafficaudit/reportexport/service/ReportExportService.java b/traffic-audit-server/src/main/java/com/trafficaudit/reportexport/service/ReportExportService.java
index 6673e20..b83bd0b 100644
--- a/traffic-audit-server/src/main/java/com/trafficaudit/reportexport/service/ReportExportService.java
+++ b/traffic-audit-server/src/main/java/com/trafficaudit/reportexport/service/ReportExportService.java
@@ -840,36 +840,36 @@
for (Double v : h2032FreightCum.values()) {
if (v != null) provAbove += v;
}
- Double provAboveWan = round(provAbove / 10000.0, 4);
+ Double provAboveWan = provAbove / 10000.0;
Double provTotal = freightCum(ftMap.get("婀栧寳鐪�"), month);
- Double provBelow = provTotal == null ? null : round(provTotal - provAboveWan, 4);
+ Double provBelow = provTotal == null ? null : provTotal - provAboveWan;
Double provTotalYoy = freightCumYoy(ftMap.get("婀栧寳鐪�"), month);
double provAboveLast = 0.0;
for (Double v : h2032FreightCumLast.values()) {
if (v != null) provAboveLast += v;
}
- Double provAboveYoy = provAboveLast == 0.0 ? null : round((provAbove - provAboveLast) / provAboveLast, 4);
+ Double provAboveYoy = provAboveLast == 0.0 ? null : (provAbove - provAboveLast) / provAboveLast;
Double provTotalLast = lastFreightCum(ftMap.get("婀栧寳鐪�"), month);
- Double provBelowLast = provTotalLast == null ? null : round(provTotalLast - provAboveLast / 10000.0, 4);
+ Double provBelowLast = provTotalLast == null ? null : provTotalLast - provAboveLast / 10000.0;
Double provBelowYoy = provBelowLast == null || provBelowLast == 0.0 ? null
- : round((provBelow - provBelowLast) / provBelowLast, 4);
+ : (provBelow - provBelowLast) / provBelowLast;
for (String city : RegionUtil.cityList()) {
Double a = h2032FreightCum.get(city);
- double aWan = a == null ? 0.0 : round(a / 10000.0, 4);
+ double aWan = a == null ? 0.0 : a / 10000.0;
Double t = freightCum(ftMap.get(city), month);
above.put(city, aWan);
total.put(city, t);
- below.put(city, t == null ? null : round(t - aWan, 4));
+ below.put(city, t == null ? null : t - aWan);
aboveYoy.put(city, h2032FreightYoy.get(city));
// 瑙勪笅鍚屾瘮 = (瑙勪笅浠婂勾 - 瑙勪笅鍘诲勾) / 瑙勪笅鍘诲勾锛涜涓嬪幓骞� = 妯℃澘鍘诲勾鍚堣 - H2032鍘诲勾瑙勪笂
Double tLast = lastFreightCum(ftMap.get(city), month);
Double aLast = h2032FreightCumLast.get(city);
- double aLastWan = aLast == null ? 0.0 : round(aLast / 10000.0, 4);
- Double belowLast = tLast == null ? null : round(tLast - aLastWan, 4);
+ double aLastWan = aLast == null ? 0.0 : aLast / 10000.0;
+ Double belowLast = tLast == null ? null : tLast - aLastWan;
Double b = below.get(city);
belowYoy.put(city, belowLast == null || belowLast == 0.0 || b == null
- ? null : round((b - belowLast) / belowLast, 4));
+ ? null : (b - belowLast) / belowLast);
totalYoy.put(city, freightCumYoy(ftMap.get(city), month));
}
@@ -894,20 +894,20 @@
if (maLast != null) provMonthAboveLast += maLast;
monthAbove.put(city, ma);
monthTotal.put(city, mt);
- monthBelow.put(city, mt == null ? null : round(mt - (ma == null ? 0.0 : ma), 4));
+ monthBelow.put(city, mt == null ? null : mt - (ma == null ? 0.0 : ma));
monthAboveYoy.put(city, growthYoy(ma, maLast));
Double mb = monthBelow.get(city);
- Double mbLast = mtLast == null ? null : round(mtLast - (maLast == null ? 0.0 : maLast), 4);
+ Double mbLast = mtLast == null ? null : mtLast - (maLast == null ? 0.0 : maLast);
monthBelowYoy.put(city, growthYoy(mb, mbLast));
monthTotalYoy.put(city, freightYoy(ftMap.get(city), month));
}
- Double provMonthAboveWan = provMonthAbove == 0.0 ? null : round(provMonthAbove, 4);
+ Double provMonthAboveWan = provMonthAbove == 0.0 ? null : provMonthAbove;
Double provMonthTotal = freightMonth(ftMap.get("婀栧寳鐪�"), month);
- Double provMonthBelow = provMonthTotal == null ? null : round(provMonthTotal - provMonthAbove, 4);
+ Double provMonthBelow = provMonthTotal == null ? null : provMonthTotal - provMonthAbove;
Double provMonthAboveYoy = growthYoy(provMonthAbove == 0.0 ? null : provMonthAbove, provMonthAboveLast);
Double provMonthTotalLast = lastFreightMonth(ftMap.get("婀栧寳鐪�"), month);
Double provMonthBelowLast = provMonthTotalLast == null ? null
- : round(provMonthTotalLast - provMonthAboveLast, 4);
+ : provMonthTotalLast - provMonthAboveLast;
Double provMonthBelowYoy = growthYoy(provMonthBelow, provMonthBelowLast);
Double provMonthTotalYoy = freightYoy(ftMap.get("婀栧寳鐪�"), month);
@@ -1244,7 +1244,7 @@
private Double monthFreightWan(Map<String, Map<Integer, Double>> byCityMonth, String city, int month) {
Map<Integer, Double> byMonth = byCityMonth == null ? null : byCityMonth.get(city);
Double v = byMonth == null ? null : byMonth.get(month);
- return v == null ? null : round(v / 10000.0, 4);
+ return v == null ? null : v / 10000.0;
}
/** 鍚屾瘮 = (鏈湡-鍩烘湡)/鍩烘湡锛涗换涓�鏈熺己澶辨垨鍩烘湡涓� 0 杩斿洖 null */
@@ -1346,12 +1346,12 @@
}
}
- /** 鍛ㄨ浆閲忔帓鍚� Q/R 鍗犳瘮锛氭ā鏉夸负缂撳瓨鍊硷紝鎸夋柊鏁版嵁閲嶇畻锛堣涓婂崰姣� 1 浣嶅皬鏁帮級 */
+ /** 鍛ㄨ浆閲忔帓鍚� Q/R 鍗犳瘮锛氭ā鏉夸负缂撳瓨鍊硷紝鎸夋柊鏁版嵁閲嶇畻锛堝叏绮惧害鍐欏叆锛屼袱浣嶅皬鏁板睍绀轰氦缁欏崟鍏冩牸鏍煎紡锛� */
private void setFreightShare(Row row, Double above, Double total) {
if (total != null && total > 0 && above != null) {
- double share = round(above * 10.0 / total, 1);
+ double share = above * 10.0 / total;
setFreightCell(row, 16, share);
- setFreightCell(row, 17, round(10.0 - share, 1));
+ setFreightCell(row, 17, 10.0 - share);
} else {
setFreightCell(row, 16, (Double) null);
setFreightCell(row, 17, (Double) null);
@@ -1561,9 +1561,9 @@
setNumeric(row, 15, isProvince ? null : yoyRankOfMap(totalYoy, city));
if (t != null && t > 0 && a != null) {
- double share = round(a * 10.0 / t, 1);
+ double share = a * 10.0 / t;
setNumeric(row, 16, share);
- setNumeric(row, 17, round(10.0 - share, 1));
+ setNumeric(row, 17, 10.0 - share);
}
return rowIdx + 1;
}
@@ -1604,9 +1604,9 @@
setNumeric(row, 15, isProvince || cum == null ? null : yoyRankOfTurnover(cumMap, city, 2));
if (total != null && total > 0 && above != null) {
- double share = round(above * 10.0 / total, 1);
+ double share = above * 10.0 / total;
setNumeric(row, 16, share);
- setNumeric(row, 17, round(10.0 - share, 1));
+ setNumeric(row, 17, 10.0 - share);
}
return rowIdx + 1;
}
@@ -1626,7 +1626,7 @@
Double v = byMonth == null ? null : byMonth.get(month);
if (v != null) sum += v;
}
- return round(sum / 10000.0, 4);
+ return sum / 10000.0;
}
Double total = freightMonth(ft, month);
Double above = getProvinceMonthValue(provinceMonthMap, ft, month, "freight", "above", h2032Freight);
@@ -1657,7 +1657,7 @@
for (Double v : h2032FreightCum.values()) {
if (v != null) sum += v;
}
- return round(sum / 10000.0, 4);
+ return sum / 10000.0;
}
Double total = freightCum(ft, monthCount);
Double above = getProvinceCumValue(provinceCum, ft, "freight", "above", h2032FreightCum, monthCount);
@@ -1687,7 +1687,7 @@
if ("above".equals(scale)) {
Map<Integer, Double> byMonth = h2032Freight.get(city);
Double v = byMonth == null ? null : byMonth.get(month);
- return v == null ? 0.0 : round(v / 10000.0, 4);
+ return v == null ? 0.0 : v / 10000.0;
}
Double total = freightMonth(ft, month);
Double above = getCityMonthValue(monthData, ft, city, month, "freight", "above", h2032Freight);
@@ -1716,7 +1716,7 @@
if ("total".equals(scale)) return freightCum(ft, monthCount);
if ("above".equals(scale)) {
Double v = h2032FreightCum.get(city);
- return v == null ? 0.0 : round(v / 10000.0, 4);
+ return v == null ? 0.0 : v / 10000.0;
}
Double total = freightCum(ft, monthCount);
Double above = getCityCumValue(cum, ft, "freight", "above", h2032FreightCum, city, monthCount);
@@ -1953,20 +1953,20 @@
double v = passengerMonthVal(data, indi, currentYear, m, region, metricIdx);
if (!keepFormula) {
if (c == null) c = row.createCell(col);
- if (v == 0.0) c.setBlank(); else c.setCellValue(round(v, 4));
+ if (v == 0.0) c.setBlank(); else c.setCellValue(v);
}
// 鍚屾瘮鍒楋細搴撳唴鍘诲勾鍚屾湀鍚屾瘮锛堟ā鏉� #REF! 鍏紡鏇挎崲涓烘暟鍊硷紝鍏紡琛屼篃瑕嗗啓锛�
double lv = passengerMonthVal(data, indi, currentYear - 1, m, region, metricIdx);
Cell yc = row.getCell(col + 1);
if (yc == null) yc = row.createCell(col + 1);
- if (v == 0.0 || lv == 0.0) yc.setBlank(); else yc.setCellValue(round((v - lv) / lv, 4));
+ if (v == 0.0 || lv == 0.0) yc.setBlank(); else yc.setCellValue((v - lv) / lv);
}
// 绱鍚屾瘮鍒楋紙妯℃澘 #REF! 鈫� 搴撳唴鍘诲勾 1..N 鏈堢疮璁″悓姣旀暟鍊硷級
int cumCol = extended ? 26 : 14;
Double cumYoy = passengerCumYoy(data, indi, currentYear, fillMonths, region, metricIdx);
Cell yc2 = row.getCell(cumCol + 1);
if (yc2 == null) yc2 = row.createCell(cumCol + 1);
- if (cumYoy == null) yc2.setBlank(); else yc2.setCellValue(round(cumYoy, 4));
+ if (cumYoy == null) yc2.setBlank(); else yc2.setCellValue(cumYoy);
}
recalc(wb);
return toBytes(wb);
@@ -2047,7 +2047,7 @@
private Double yoy(Double cur, Double base) {
if (cur == null || base == null || base == 0.0) return null;
- return round((cur - base) / base, 4);
+ return (cur - base) / base;
}
/** 鎸囨爣鍙栧�硷紙宸叉崲绠椾负涓囦汉/涓囦汉鍏噷/鍏噷锛涙棤鏁版嵁杩斿洖 null锛� */
@@ -2286,7 +2286,7 @@
if (v == 0.0) return; // 搴撳唴鏃犳簮锛氫繚鐣欐瘝鐗�/瀹氱鍘熷�硷紝缂烘暟鎹笉瑕嗙洊
// POI setCellValue(double) 瀵瑰叕寮忓崟鍏冩牸鍙洿鏂扮紦瀛樹笉绉婚櫎鍏紡锛屽繀椤诲厛 setBlank 鍐嶅啓鍊�
c.setBlank();
- c.setCellValue(round(v, 4));
+ c.setCellValue(v);
}
/** 鏄惧紡鍐欏叆 0锛圥OI setCellValue(0.0) 浼氳浆 blank锛岄渶鎿嶄綔搴曞眰 XML锛� */
@@ -2582,12 +2582,12 @@
int monthCount = (y == currentYear) ? maxMonth : 12;
for (int m = 1; m <= monthCount; m++) {
Double cur = midMetricValue(aggOf(data, y, m, region), i, volume);
- setNumeric(row, col++, cur == null ? null : round(cur, 4));
+ setNumeric(row, col++, cur);
Double base = midMetricValue(aggOf(data, y - 1, m, region), i, volume);
setNumeric(row, col++, yoy(cur, base));
}
Double cum = midCumOf(data, y, region, monthCount, i, volume);
- setNumeric(row, col++, cum == null ? null : round(cum, 4));
+ setNumeric(row, col++, cum);
Double cumBase = midCumOf(data, y - 1, region, monthCount, i, volume);
setNumeric(row, col++, yoy(cum, cumBase));
}
@@ -2670,18 +2670,18 @@
double turn = midCumClass(mid, currentYear, city, maxMonth, 0, false);
double lastPass = midCumClass(mid, currentYear - 1, city, maxMonth, 0, true);
double lastTurn = midCumClass(mid, currentYear - 1, city, maxMonth, 0, false);
- setValOrBlank(sheet, r0, 1, pass == 0 ? null : round(pass, 4));
+ setValOrBlank(sheet, r0, 1, pass == 0 ? null : pass);
setValOrBlank(sheet, r0, 3, midCumYoy(mid, currentYear, city, maxMonth, 0, true));
- setValOrBlank(sheet, r0, 5, turn == 0 ? null : round(turn, 4));
+ setValOrBlank(sheet, r0, 5, turn == 0 ? null : turn);
setValOrBlank(sheet, r0, 7, midCumYoy(mid, currentYear, city, maxMonth, 0, false));
// 鍙冲潡褰撴湀锛歀/P 鍊笺�丯/R 褰撴湀鍚屾瘮锛圡/O/Q/S 鎺掑悕鍏紡淇濈暀锛�
double mPass = midClassVal(mid, currentYear, maxMonth, city, 0, true);
double mTurn = midClassVal(mid, currentYear, maxMonth, city, 0, false);
double mLastPass = midClassVal(mid, currentYear - 1, maxMonth, city, 0, true);
double mLastTurn = midClassVal(mid, currentYear - 1, maxMonth, city, 0, false);
- setValOrBlank(sheet, r0, 11, mPass == 0 ? null : round(mPass, 4));
+ setValOrBlank(sheet, r0, 11, mPass == 0 ? null : mPass);
setValOrBlank(sheet, r0, 13, mPass == 0 ? null : midMonthYoy(mid, currentYear, maxMonth, city, 0, true));
- setValOrBlank(sheet, r0, 15, mTurn == 0 ? null : round(mTurn, 4));
+ setValOrBlank(sheet, r0, 15, mTurn == 0 ? null : mTurn);
setValOrBlank(sheet, r0, 17, mTurn == 0 ? null : midMonthYoy(mid, currentYear, maxMonth, city, 0, false));
}
recalc(wb);
@@ -2701,7 +2701,7 @@
private Double yoyOf(double cur, double base) {
if (base == 0.0) return null;
- return round((cur - base) / base, 4);
+ return (cur - base) / base;
}
/** 涓彛寰勫垎绫荤疮璁★紙1..monthCount 鏈堟眰鍜岋級 */
@@ -2743,9 +2743,9 @@
double turn = midCumClass(mid, currentYear, "婀栧寳鐪�", maxMonth, dims[i], false);
double lastPass = midCumClass(mid, currentYear - 1, "婀栧寳鐪�", maxMonth, dims[i], true);
double lastTurn = midCumClass(mid, currentYear - 1, "婀栧寳鐪�", maxMonth, dims[i], false);
- setValOrBlank(sheet, r0, 1, pass == 0 ? null : round(pass, 4));
+ setValOrBlank(sheet, r0, 1, pass == 0 ? null : pass);
setValOrBlank(sheet, r0, 2, midCumYoy(mid, currentYear, "婀栧寳鐪�", maxMonth, dims[i], true));
- setValOrBlank(sheet, r0, 5, turn == 0 ? null : round(turn, 4));
+ setValOrBlank(sheet, r0, 5, turn == 0 ? null : turn);
setValOrBlank(sheet, r0, 6, midCumYoy(mid, currentYear, "婀栧寳鐪�", maxMonth, dims[i], false));
}
// 涓嬪崐鍧楋紙褰撴湀锛夛細鏍囬琛�9銆佹暟鎹11-15锛�0-based 8銆�10-14锛�
@@ -2759,9 +2759,9 @@
double turn = midClassVal(mid, currentYear, maxMonth, "婀栧寳鐪�", dims[i], false);
double lastPass = midClassVal(mid, currentYear - 1, maxMonth, "婀栧寳鐪�", dims[i], true);
double lastTurn = midClassVal(mid, currentYear - 1, maxMonth, "婀栧寳鐪�", dims[i], false);
- setValOrBlank(sheet, r0, 1, pass == 0 ? null : round(pass, 4));
+ setValOrBlank(sheet, r0, 1, pass == 0 ? null : pass);
setValOrBlank(sheet, r0, 2, pass == 0 ? null : midMonthYoy(mid, currentYear, maxMonth, "婀栧寳鐪�", dims[i], true));
- setValOrBlank(sheet, r0, 5, turn == 0 ? null : round(turn, 4));
+ setValOrBlank(sheet, r0, 5, turn == 0 ? null : turn);
setValOrBlank(sheet, r0, 6, turn == 0 ? null : midMonthYoy(mid, currentYear, maxMonth, "婀栧寳鐪�", dims[i], false));
}
// 涓嬪崐鍧楀崰姣斿叕寮忕敱鏍蜂緥鎸囧悜涓婂崐鍧楋紙B$3/F$3锛夛紝鏀瑰啓涓烘湰鍧楁�昏锛圔$11/F$11锛夛紝琛�12-15
@@ -3179,7 +3179,7 @@
Cell c = row.getCell(colIdx);
if (c != null && c.getCellType() == org.apache.poi.ss.usermodel.CellType.FORMULA) return;
if (c == null) c = row.createCell(colIdx);
- if (v == 0) c.setBlank(); else c.setCellValue(round(v, 2));
+ if (v == 0) c.setBlank(); else c.setCellValue(v);
}
/** 鏄惧紡鍐欏叆 0锛坰etDataCell 瀵� 0 缃┖锛涙眹鎬昏〃缃戠害杞﹁闇�瑕佹樉绀� 0锛� */
@@ -4643,8 +4643,8 @@
if (r.getAvgDistanceCity() != null && r.getAvgDistanceCity() > 0) a[5] = r.getAvgDistanceCity();
}
for (double[] a : map.values()) {
- if (a[4] <= 0 && a[0] > 0) a[4] = round(a[1] / a[0], 2);
- if (a[5] <= 0 && a[2] > 0) a[5] = round(a[3] / a[2], 2);
+ if (a[4] <= 0 && a[0] > 0) a[4] = a[1] / a[0];
+ if (a[5] <= 0 && a[2] > 0) a[5] = a[3] / a[2];
}
return map;
}
@@ -4960,19 +4960,19 @@
Row row = sheet.getRow(rowIdx);
if (row == null) row = sheet.createRow(rowIdx);
if (a > 0) {
- // 2026骞� 1..N 鏈堬細搴撳唴鏈夊�煎垯濉紙2浣嶅皬鏁帮級锛屾棤鍊兼竻绌烘ā鏉挎牱渚�
+ // 2026骞� 1..N 鏈堬細搴撳唴鏈夊�煎垯濉紙鍏ㄧ簿搴﹀啓鍏ワ紝涓や綅灏忔暟鐢卞崟鍏冩牸鏍煎紡灞曠ず锛夛紝鏃犲�兼竻绌烘ā鏉挎牱渚�
for (int m = 1; m <= month; m++) {
double v = cityVal(monthCity, area, m, k);
Cell c = row.getCell(2 + (m - 1) * 2);
if (c == null) c = row.createCell(2 + (m - 1) * 2);
- if (v == 0) c.setBlank(); else c.setCellValue(round(v, 2));
+ if (v == 0) c.setBlank(); else c.setCellValue(v);
}
// 2025骞� 1..12 鏈堬細搴撳唴鏈夊幓骞存暟鎹垯濉紝鍚﹀垯娓呯┖妯℃澘鏍蜂緥
for (int m = 1; m <= 12; m++) {
double v = cityVal(lastYearMonthCity, area, m, k);
Cell c = row.getCell(19 + (m - 1) * 2);
if (c == null) c = row.createCell(19 + (m - 1) * 2);
- if (v == 0) c.setBlank(); else c.setCellValue(round(v, 2));
+ if (v == 0) c.setBlank(); else c.setCellValue(v);
}
}
rowIdx++;
@@ -5465,7 +5465,7 @@
hssfNum(row, 8, agg.startCum == 0 ? null : agg.startCum);
hssfNum(row, 9, agg.yearPlan == 0 ? null : agg.yearPlan);
hssfNum(row, 22, agg.yearCum == 0 ? null : agg.yearCum);
- if (agg.yearPlan > 0) hssfNum(row, 23, round(agg.yearCum / agg.yearPlan, 4));
+ if (agg.yearPlan > 0) hssfNum(row, 23, agg.yearCum / agg.yearPlan);
}
@@ -5797,7 +5797,7 @@
putNum(row, 2, s[3] == 0 ? null : s[3]);
putNum(row, 3, s[4] == 0 ? null : s[4]);
double b = numOf(row.getCell(1));
- putNum(row, 4, b > 0 ? round(s[3] / b * 100, 4) : null);
+ putNum(row, 4, b > 0 ? s[3] / b * 100 : null);
cT += s[3];
dT += s[4];
}
@@ -5806,7 +5806,7 @@
putNum(tot, 2, cT == 0 ? null : cT);
putNum(tot, 3, dT == 0 ? null : dT);
double b = numOf(tot.getCell(1));
- putNum(tot, 4, b > 0 ? round(cT / b * 100, 4) : null);
+ putNum(tot, 4, b > 0 ? cT / b * 100 : null);
}
}
try {
@@ -6027,7 +6027,7 @@
for (InvestmentMonthly m : monthlies) provinceYearPlan += nz(m.getYearPlan());
HSSFRow rowOther = s1.getRow(9);
for (int c = 1; c <= 5; c++) hssfNum(rowOther, c, null);
- hssfNum(rowOther, 5, provinceYearPlan == 0 ? null : round(provinceYearPlan / 10000, 2));
+ hssfNum(rowOther, 5, provinceYearPlan == 0 ? null : provinceYearPlan / 10000);
// ---- sheet2 瑙勪笂椤圭洰琛細琛ㄥご骞翠唤 + 鍚堣 + 椤圭洰琛� ----
HSSFSheet s2 = wb.getSheetAt(1);
hssfText(s2.getRow(0), 0, year + "骞翠氦閫氬缓璁鹃」鐩偍澶囨儏鍐碉紙瑙勬ā浠ヤ笂椤圭洰锛�");
@@ -6259,6 +6259,8 @@
private double nz(Double v) {
return v == null ? 0.0 : v;
}
+ /** 鏁板�兼牸寮忛噷 3 浣嶅強浠ヤ笂鐨勫皬鏁伴儴鍒嗭紙濡� 0.0000 / 0.000_ 锛� */
+ private static final java.util.regex.Pattern DEC_MORE_THAN_TWO = java.util.regex.Pattern.compile("\\.0{3,}");
/** 鐢熸垚琛ㄦ暟鍊煎垪缁熶竴鏍峰紡锛氫繚鐣欏叏绮惧害鏁板�硷紝鏄剧ず涓や綅灏忔暟锛涙暣鏁板�间笌 %/鏃ユ湡/绉戝璁℃暟绛夋棦鏈夋牱寮忎笉鏀瑰彉 */
private void applyTwoDecimalFormat(org.apache.poi.ss.usermodel.Workbook wb) {
if (wb == null) return;
@@ -6275,24 +6277,32 @@
CellType ct = cell.getCellType();
if (ct != CellType.NUMERIC && ct != CellType.FORMULA) continue;
if (org.apache.poi.ss.usermodel.DateUtil.isCellDateFormatted(cell)) continue;
- boolean integral = false;
- if (ct == CellType.NUMERIC) {
- integral = Math.rint(cell.getNumericCellValue()) == cell.getNumericCellValue();
- } else if (cell.getCachedFormulaResultType() == CellType.NUMERIC) {
- integral = Math.rint(cell.getNumericCellValue()) == cell.getNumericCellValue();
- }
- if (integral) continue; // 鏁存暟涓嶆樉绀� .00锛堝惈鍏紡缁撴灉涓烘暣鏁扮殑鏍硷級
org.apache.poi.ss.usermodel.CellStyle cs = cell.getCellStyle();
if (cs == null) continue;
String f = cs.getDataFormatString();
if (f == null) f = "";
- if (f.contains("%") || f.contains("E") || f.contains("0.00")) continue;
- boolean plain = f.isEmpty() || "General".equals(f) || "general".equals(f)
- || "0".equals(f) || "#,##0".equals(f) || "0.0".equals(f) || "#,##0.0".equals(f);
- if (!plain) continue;
+ if (f.contains("%") || f.contains("E") || f.contains("@")) continue;
+ String normalized = null;
+ if (DEC_MORE_THAN_TWO.matcher(f).find()) {
+ // 姣嶇増涓埆鏍煎甫 3~4 浣嶅皬鏁版牸寮忥紙濡� 0.000_ 銆�0.0000_);[Red]\(0.0000\)锛夛細鏁板�间粛鍏ㄧ簿搴︼紝
+ // 灞曠ず缁熶竴鏀舵暃鍒颁袱浣嶃�傝繖绫绘牸鏈氨鎸夋暟鍊兼牸寮忓睍绀猴紝鏁呬笉鍙椼�屾暣鏁颁笉鏄剧ず .00銆嶄繚鎶ゅ奖鍝嶃��
+ normalized = DEC_MORE_THAN_TWO.matcher(f).replaceAll(".00");
+ } else {
+ boolean integral = false;
+ if (ct == CellType.NUMERIC) {
+ integral = Math.rint(cell.getNumericCellValue()) == cell.getNumericCellValue();
+ } else if (cell.getCachedFormulaResultType() == CellType.NUMERIC) {
+ integral = Math.rint(cell.getNumericCellValue()) == cell.getNumericCellValue();
+ }
+ if (integral) continue; // 鏁存暟涓嶆樉绀� .00锛堝惈鍏紡缁撴灉涓烘暣鏁扮殑鏍硷級
+ if (f.contains("0.00")) continue;
+ boolean plain = f.isEmpty() || "General".equals(f) || "general".equals(f)
+ || "0".equals(f) || "#,##0".equals(f) || "0.0".equals(f) || "#,##0.0".equals(f);
+ if (!plain) continue;
+ }
org.apache.poi.ss.usermodel.CellStyle ns = wb.createCellStyle();
ns.cloneStyleFrom(cs);
- ns.setDataFormat(fmtTwo);
+ ns.setDataFormat(normalized == null ? fmtTwo : df.getFormat(normalized));
cell.setCellStyle(ns);
} catch (Exception ignore) {
// 涓埆鍗曞厓鏍兼牸寮忓紓甯镐笉闃诲瀵煎嚭
--
Gitblit v1.9.1