From 6b26797c00068b276bfa4a749eb3601d4455a6d1 Mon Sep 17 00:00:00 2001 From: yamelsenih Date: Tue, 30 Jul 2024 23:18:03 -0400 Subject: [PATCH] Fixed error with: ``` class java.lang.Integer cannot be cast to class java.lang.String (java.lang.Integer and java.lang.String are in module java.base of loader 'bootstrap') ``` --- .../report_engine/export/XlsxExporter.java | 32 +++++++++++++------ 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/spin/report_engine/export/XlsxExporter.java b/src/main/java/org/spin/report_engine/export/XlsxExporter.java index 0730a6f..8ccc2b5 100644 --- a/src/main/java/org/spin/report_engine/export/XlsxExporter.java +++ b/src/main/java/org/spin/report_engine/export/XlsxExporter.java @@ -17,6 +17,7 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; +import java.math.BigDecimal; import java.sql.Timestamp; import java.text.DecimalFormat; import java.text.NumberFormat; @@ -185,27 +186,38 @@ public String export(ReportInfo reportInfo) { org.spin.report_engine.data.Row rowValue = rows.get(rowNumber); org.spin.report_engine.data.Cell cell = rowValue.getCell(columnInfo.getPrintFormatItemId()); int displayType = columnInfo.getDisplayTypeId(); - Object obj = cell.getValue(); - if(obj != null) { + Object valueasObject = cell.getValue(); + if(valueasObject != null) { if (DisplayType.isDate(displayType)) { - Timestamp value = (Timestamp)obj; + Timestamp value = (Timestamp)valueasObject; sheetCell.setCellValue(value); } else if (DisplayType.isNumeric(displayType)) { double value = 0; - if (obj instanceof Number) { - value = ((Number)obj).doubleValue(); + if (valueasObject instanceof Number) { + value = ((Number) valueasObject).doubleValue(); } sheetCell.setCellValue(value); } else if (DisplayType.YesNo == displayType) { String value = Util.stripDiacritics(cell.getDisplayValue()); sheetCell.setCellValue(sheet.getWorkbook().getCreationHelper().createRichTextString(value)); } else { - String value = cell.getDisplayValue(); - if(Util.isEmpty(value)) { - value = (String) obj; + String displayValue = cell.getDisplayValue(); + if(Util.isEmpty(displayValue)) { + if(valueasObject instanceof BigDecimal) { + sheetCell.setCellValue(((BigDecimal) valueasObject).doubleValue()); + } else if (valueasObject instanceof Integer) { + sheetCell.setCellValue((Integer) valueasObject); + } else if (valueasObject instanceof String) { + displayValue = (String) valueasObject; + displayValue = Util.stripDiacritics(displayValue); + sheetCell.setCellValue(sheet.getWorkbook().getCreationHelper().createRichTextString(displayValue)); + } else if (valueasObject instanceof Boolean) { + sheetCell.setCellValue((Boolean) valueasObject); + } else if(valueasObject instanceof Timestamp) { + Timestamp value = (Timestamp) valueasObject; + sheetCell.setCellValue(value); + } } - value = Util.stripDiacritics(value); - sheetCell.setCellValue(sheet.getWorkbook().getCreationHelper().createRichTextString(value)); } } //