소스 검색

修改数值DataFormat

yingp 7 년 전
부모
커밋
9d1d41d78f
1개의 변경된 파일12개의 추가작업 그리고 2개의 파일을 삭제
  1. 12 2
      src/main/java/com/uas/report/jasperreports/engine/export/CustomJRXlsExporter.java

+ 12 - 2
src/main/java/com/uas/report/jasperreports/engine/export/CustomJRXlsExporter.java

@@ -93,8 +93,18 @@ public class CustomJRXlsExporter extends JRXlsExporter {
 			String textStr = styledText.getText();
 			TextValue textValue = getTextValue(textElement, textStr);
 			// 类型为String,但是实际值为数值,需设置为字符串类型,否则会提示转为数值型
-			if ((textValue instanceof StringTextValue && isNumber(textStr)) || textValue instanceof NumberTextValue) {
-				baseStyle.setDataFormat(dataFormat.getFormat("@"));
+			if ((textValue instanceof StringTextValue && isNumber(textStr))
+					|| textValue instanceof NumberTextValue) {
+				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);