Hello! There is a SpringMVC project, there is data that, when clicked on a button, is downloaded into an Excel file.

Data can be both a number and text, so the previous programmer saved all the data as text. But as a result, in Excel, the cell with numbers has a green triangle with the hint "The number in this cell is formatted as text, or there is an apostrophe in front of it."

The data for the output is filled as follows:

for (Integer i = startDayOfMonth; i <= endDayOfMonth; i++) { titleText = new JRDesignTextField(); titleText.setX(x); titleText.setY(y); titleText.setWidth(dayColumnWidth); titleText.setHeight(25); titleText.setStyle(orangeCellStyle); expression = new JRDesignExpression(); expression.setText(i.toString()); titleText.setExpression(expression); band.addElement(titleText); x += titleText.getWidth(); maxDayList.add(i); } 

What needs to be done so that the numbers appear as numbers, or that this green triangle do not appear?

enter image description here

  • Perhaps not to do setText but for example setFloat ... or what is there? - JVic

1 answer 1

Found a solution:

In code

 JasperDesign jasperDesign = createListFactDesign(); JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign); JRDataSource jrDataSource = prepareDataSource(); Map<String, Object> params = new HashMap<String, Object>(); JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, jrDataSource); try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) { switch (this.listFactReportParameters.getReportFormat()) { case EXCEL: JRXlsExporter xlsExporter = new JRXlsExporter(); xlsExporter.setExporterInput(new SimpleExporterInput(jasperPrint)); xlsExporter.setExporterOutput(new SimpleOutputStreamExporterOutput(baos)); SimpleXlsReportConfiguration configuration = new SimpleXlsReportConfiguration(); configuration.setOnePagePerSheet(false); configuration.setDetectCellType(true); xlsExporter.setConfiguration(configuration); xlsExporter.exportReport(); 

Added this line configuration.setDetectCellType(true);