我正在使用 JasperReports 并尝试向 Excel 报告。
当我试图让报告出类拔萃时,我看到一个可怕的报告,细胞不在正确的位置,有很多分裂细胞。
我认为问题出在List的字段中,具有以下属性:
Position Type: Fix Relative to Top
Stretch Type: Relative to band height
字段邻居具有以下属性:
Position Type: Fix Relative to Top
Stretch Type: Relative to Tallest object
我得到以下外观:
这是对的,但是当我收到 Excel 报告时,我得到以下信息:
我不知道如何解决它。
这是以 Excel 格式生成报告的代码。
public boolean exportarAExcel(){
ServletOutputStream servletOutputStream = null;
try {
ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
ServletContext servletContext = (ServletContext) externalContext.getContext();
String reportPath = servletContext.getRealPath("/rpt/" +this.nombreReporteJasper);
JasperPrint jasperPrint= JasperFillManager.fillReport(reportPath,this.parametros,
new JRBeanCollectionDataSource( this.dataSource ));
HttpServletResponse httpServletResponse =
(HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();
httpServletResponse.setContentType("application/xlsx");
httpServletResponse.addHeader("Content-disposition", "attachment; filename=\""+this.nombreSalida+".xlsx\"");
servletOutputStream = httpServletResponse.getOutputStream();
JRXlsxExporter excelExporter=new JRXlsxExporter();
excelExporter.setParameter(JRXlsExporterParameter.JASPER_PRINT, jasperPrint);
excelExporter.setParameter(JRXlsExporterParameter.OUTPUT_STREAM, servletOutputStream);
excelExporter.setParameter(JRXlsExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.TRUE);
excelExporter.setParameter(JRXlsExporterParameter.IS_IGNORE_GRAPHICS, Boolean.TRUE);
excelExporter.setParameter(JRXlsExporterParameter.IS_COLLAPSE_ROW_SPAN, Boolean.TRUE);
excelExporter.setParameter(JRXlsExporterParameter.IS_DETECT_CELL_TYPE, Boolean.TRUE);
excelExporter.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.FALSE);
excelExporter.setParameter(JRXlsExporterParameter.IS_FONT_SIZE_FIX_ENABLED, Boolean.TRUE);
excelExporter.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE);
excelExporter.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_COLUMNS, Boolean.TRUE);
excelExporter.exportReport();
servletOutputStream.flush();
servletOutputStream.close();
FacesContext.getCurrentInstance().responseComplete();
return true;
} catch (JRException ex) {
Logger.getLogger(Exporter.class.getName()).log(Level.SEVERE, null, ex);
return false;
} catch (IOException ex) {
Logger.getLogger(Exporter.class.getName()).log(Level.SEVERE, null, ex);
}
return false;
}
任何人都可以帮助我吗?
答案 0 :(得分:1)
尝试将IS_COLLAPSE_ROW_SPAN
设置为false,当您有通过多行合并的单元格时,可能会导致一些问题,并尝试将其添加到报告或代码
<property name="net.sf.jasperreports.export.xls.ignore.cell.border" value="false"/>
<property name="net.sf.jasperreports.export.xls.image.border.fix.enabled" value="false"/>
同时尝试将此设置为false
IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS
IS_REMOVE_EMPTY_SPACE_BETWEEN_COLUMNS
如果你想隐藏网格线,请使用它(即使你当前的导出也会看起来更好)
<property name="net.sf.jasperreports.export.xls.show.gridlines" value="false"/>