iReport导出Excel报表时为什么不出数据,其他输出格式都能显示数据
privatevoidexcelAction(HttpServletRequestrequest,HttpServletResponseresponse)throwsEx...
private void excelAction(HttpServletRequest request, HttpServletResponse response) throws Exception
{
File jasperfile = new File(request.getSession().getServletContext().getRealPath("/jaspers/report4.jasper"));
JasperReport jasperReport = (JasperReport) JRLoader.loadObject(jasperfile);
File destFile = new File(jasperfile.getParent() + "\\report4.xls");
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, new HashMap<String, Object>(), conn);
exportExcel(jasperPrint, destFile);
response.sendRedirect("jaspers/report4.xls");
}
private void exportExcel(JasperPrint jasperPrint, File outfile) throws JRException, SQLException {
RXlsxExporter xlsExporter = new JRXlsxExporter();
xlsExporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
xlsExporter.setParameter(JRExporterParameter.OUTPUT_FILE, outfile);
xlsExporter.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS,Boolean.TRUE);
xlsExporter.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET,Boolean.FALSE);
xlsExporter.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_COLUMNS,Boolean.TRUE);
xlsExporter.setParameter(JRXlsExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.FALSE);
xlsExporter.setParameter(JRXlsExporterParameter.IS_FONT_SIZE_FIX_ENABLED,Boolean.TRUE);
xlsExporter.exportReport();
conn.close();
} 展开
{
File jasperfile = new File(request.getSession().getServletContext().getRealPath("/jaspers/report4.jasper"));
JasperReport jasperReport = (JasperReport) JRLoader.loadObject(jasperfile);
File destFile = new File(jasperfile.getParent() + "\\report4.xls");
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, new HashMap<String, Object>(), conn);
exportExcel(jasperPrint, destFile);
response.sendRedirect("jaspers/report4.xls");
}
private void exportExcel(JasperPrint jasperPrint, File outfile) throws JRException, SQLException {
RXlsxExporter xlsExporter = new JRXlsxExporter();
xlsExporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
xlsExporter.setParameter(JRExporterParameter.OUTPUT_FILE, outfile);
xlsExporter.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS,Boolean.TRUE);
xlsExporter.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET,Boolean.FALSE);
xlsExporter.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_COLUMNS,Boolean.TRUE);
xlsExporter.setParameter(JRXlsExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.FALSE);
xlsExporter.setParameter(JRXlsExporterParameter.IS_FONT_SIZE_FIX_ENABLED,Boolean.TRUE);
xlsExporter.exportReport();
conn.close();
} 展开
展开全部
用这个试试
System.out.println("导出excel.........");
response.setContentType("application/vnd.ms-excel");
String filename = null;
if(exportFileName != null && !exportFileName.equals("")){
filename = exportFileName + ".xls";
}else{
filename = DateTime.getSystemDateTimeString() + ".xls";
}
String fileName = new String(filename.getBytes("GBK"),
"ISO8859_1");
response.setHeader("Content-disposition",
"attachment; filename=" + fileName);
JasperReport rep = (JasperReport) JRLoader.loadObject(reportFile);
jasperPrint = JasperFillManager.fillReport(rep, parameters,
conn);
ServletOutputStream ouputStream = response.getOutputStream();
JRXlsExporter exporter = new JRXlsExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT,jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM,ouputStream);
exporter.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS,Boolean.TRUE);
exporter.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET,Boolean.FALSE);
exporter.setParameter(JRXlsExporterParameter.IS_WHITE_PAGE_BACKGROUND,Boolean.FALSE);
exporter.exportReport();
ouputStream.flush();
ouputStream.close();
System.out.println("导出excel.........");
response.setContentType("application/vnd.ms-excel");
String filename = null;
if(exportFileName != null && !exportFileName.equals("")){
filename = exportFileName + ".xls";
}else{
filename = DateTime.getSystemDateTimeString() + ".xls";
}
String fileName = new String(filename.getBytes("GBK"),
"ISO8859_1");
response.setHeader("Content-disposition",
"attachment; filename=" + fileName);
JasperReport rep = (JasperReport) JRLoader.loadObject(reportFile);
jasperPrint = JasperFillManager.fillReport(rep, parameters,
conn);
ServletOutputStream ouputStream = response.getOutputStream();
JRXlsExporter exporter = new JRXlsExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT,jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM,ouputStream);
exporter.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS,Boolean.TRUE);
exporter.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET,Boolean.FALSE);
exporter.setParameter(JRXlsExporterParameter.IS_WHITE_PAGE_BACKGROUND,Boolean.FALSE);
exporter.exportReport();
ouputStream.flush();
ouputStream.close();
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询