Procházet zdrojové kódy

修改数值DataFormat

guq před 7 roky
rodič
revize
d66dfad31f

+ 10 - 1
report/src/main/java/com/uas/report/jasperreports/engine/export/CustomJRXlsExporter.java

@@ -94,7 +94,16 @@ public class CustomJRXlsExporter extends JRXlsExporter {
 			TextValue textValue = getTextValue(textElement, textStr);
 			// 类型为String,但是实际值为数值,需设置为字符串类型,否则会提示转为数值型
 			if ((textValue instanceof StringTextValue && isNumber(textStr)) || textValue instanceof NumberTextValue) {
-				baseStyle.setDataFormat(dataFormat.getFormat("@"));
+				if (textValue instanceof NumberTextValue && null != textElement.getPattern()) {
+					String anchorName = getConvertedPattern(textElement, ((NumberTextValue) textValue).getPattern());
+					if (null != anchorName) {
+						baseStyle.setDataFormat(dataFormat.getFormat(anchorName));
+					} else {
+						baseStyle.setDataFormat(dataFormat.getFormat("@"));
+					}
+				} else {
+					baseStyle.setDataFormat(dataFormat.getFormat("@"));
+				}
 			}
 			super.createTextCell(textElement, gridCell, colIndex, rowIndex, styledText, baseStyle, forecolor);