Browse Source

Excel公式处理

18870042648 2 years ago
parent
commit
f3ed5d9255

+ 0 - 1
zjnytwo_cd/zjnytwo_cd/classes/.gitignore

@@ -1,2 +1 @@
-/nc/
 /nccloud/

+ 8 - 1
zjnytwo_cd/zjnytwo_cd/src/client/nccloud/zjnytwo_cd/zjnytwo_cd/tool/Excel.java

@@ -17,6 +17,7 @@ import org.apache.poi.hssf.usermodel.HSSFDateUtil;
 import org.apache.poi.ss.usermodel.*;
 import org.apache.poi.xssf.usermodel.XSSFCell;
 import org.apache.poi.xssf.usermodel.XSSFCellStyle;
+import org.apache.poi.xssf.usermodel.XSSFFormulaEvaluator;
 import org.apache.poi.xssf.usermodel.XSSFRow;
 import org.apache.poi.xssf.usermodel.XSSFSheet;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
@@ -196,7 +197,13 @@ public class Excel {
 
 		// 2. 公式 CELL_TYPE_FORMULA
 		if (cell.getCellType() == CellType.FORMULA) {
-			return cell.getStringCellValue();
+			FormulaEvaluator formulaEvaluator = new XSSFFormulaEvaluator((XSSFWorkbook) book);
+			CellValue evaluate = formulaEvaluator.evaluate(cell);
+			String format = evaluate.formatAsString();
+			if (format.contains("E")) {
+				format = new BigDecimal(format+"").toString();
+			}
+			return format;
 		}
 
 		// 4. 布尔值 CELL_TYPE_BOOLEAN