Jasper reports 如何在JasperReports中导出到excel?

Jasper reports 如何在JasperReports中导出到excel?,jasper-reports,Jasper Reports,我需要以JasperReports格式导出到excel和csv格式。对于excel,我尝试使用JRXlsExporter类,但它没有导出。问题是“保存并取消”弹出窗口的文件类型未知 file type like "getReportDetail.do" 其中getReportDetail.do是struts配置xml的“action”元素中的“path”属性。我调用这个getReportDetail.do,方法是单击html按钮调用“action类”导出excel 我设置参数如下 repor

我需要以
JasperReports
格式导出到excel和csv格式。对于excel,我尝试使用
JRXlsExporter
类,但它没有导出。问题是“保存并取消”弹出窗口的文件类型未知

 file type like "getReportDetail.do"
其中
getReportDetail.do
是struts配置xml的“action”元素中的“path”属性。我调用这个
getReportDetail.do
,方法是单击html按钮调用“action类”导出excel

我设置参数如下

reportExporter.setParameter(JRXlsExporterParameter.JASPER\u PRINT,jasperPrint);
reportExporter.setParameter(JRXlsExporterParameter.OUTPUT_STREAM,reportStream);
reportExporter.setParameter(JRXlsExporterParameter.IS\u删除\u空的\u行之间的空间\u,Boolean.TRUE);
reportExporter.setParameter(JRXlsExporterParameter.IS_每工作表一页,布尔值.FALSE);
reportExporter.setParameter(JRXlsExporterParameter.IS_WHITE_PAGE_BACKGROUND,Boolean.FALSE);
reportExporter.setParameter(JRXlsExporterParameter.IS\u DETECT\u CELL\u TYPE,Boolean.TRUE);
其中,
reportStream
ByteArrayOutputStream()
的对象

reportExporter
JRXlsExporter
对象

contenttype
response.setContentType(“application/xls”)


知道为什么会这样吗?

尝试设置以下标题:

Content-Type: application/vnd.ms-excel
Content-Disposition: attachment; filename=report.xls

尝试设置以下标题:

Content-Type: application/vnd.ms-excel
Content-Disposition: attachment; filename=report.xls

这是我的代码,但要注意实现的版本。 注意:使用ireport导出excel,适用于ireport 6.0、java 7

 Map<String, Object> parametro = new HashMap<String, Object>();
                parametro.put("USUARIO", UConstante.NAME_MINISTERIO_USER);
                parametro.put("RUTA_LOGO", PuenteFile.getRutaFiles(FacesContext.getCurrentInstance(), PuenteFile.RUTA_IMG_LOGO));
                parametro.put("PATH_SYSTEM", rutaFileSystemHD);
                parametro.put("WHERE_DATA", WHERE_REGISTRO);
                parametro.put("WHERE_PROYECTO_USUARIO", WHERE_PROYECTO_USUARIO);
                parametro.put("WHERE_ZONA", WHERE_ZONA);
                parametro.put("NAME_APP", RutaFile.NAME_APP);
                parametro.put("ID_USUARIO", getUsuario().getId());
                parametro.put("ID_PROYECTO", beanProyecto.getId());
                parametro.put("SUBREPORT_DIR", SUBREPORT_DIR);

                System.out.println(">>>>>> PARAMETROS :" + parametro.toString());

              try {
                    JasperPrint jasperPrint = JasperFillManager.fillReport(path, parametro, PgConnector.getConexion());
                    JRXlsExporter xlsExporter = new JRXlsExporter();
                    xlsExporter.setExporterInput(new SimpleExporterInput(jasperPrint));
                    xlsExporter.setExporterOutput(new SimpleOutputStreamExporterOutput(PATH_REPORT_FILE + nameExcel);
                    SimpleXlsReportConfiguration xlsReportConfiguration = new SimpleXlsReportConfiguration();
                    SimpleXlsExporterConfiguration xlsExporterConfiguration = new SimpleXlsExporterConfiguration();
                    xlsReportConfiguration.setOnePagePerSheet(true);
                    xlsReportConfiguration.setRemoveEmptySpaceBetweenRows(false);
                    xlsReportConfiguration.setDetectCellType(true);
                    xlsReportConfiguration.setWhitePageBackground(false);
                    xlsExporter.setConfiguration(xlsReportConfiguration);
                    xlsExporter.exportReport();

                } catch (Exception ex) {
                    ex.printStackTrace();
                }

这是我的代码,但要注意实现的版本。 注意:使用ireport导出excel,适用于ireport 6.0、java 7

 Map<String, Object> parametro = new HashMap<String, Object>();
                parametro.put("USUARIO", UConstante.NAME_MINISTERIO_USER);
                parametro.put("RUTA_LOGO", PuenteFile.getRutaFiles(FacesContext.getCurrentInstance(), PuenteFile.RUTA_IMG_LOGO));
                parametro.put("PATH_SYSTEM", rutaFileSystemHD);
                parametro.put("WHERE_DATA", WHERE_REGISTRO);
                parametro.put("WHERE_PROYECTO_USUARIO", WHERE_PROYECTO_USUARIO);
                parametro.put("WHERE_ZONA", WHERE_ZONA);
                parametro.put("NAME_APP", RutaFile.NAME_APP);
                parametro.put("ID_USUARIO", getUsuario().getId());
                parametro.put("ID_PROYECTO", beanProyecto.getId());
                parametro.put("SUBREPORT_DIR", SUBREPORT_DIR);

                System.out.println(">>>>>> PARAMETROS :" + parametro.toString());

              try {
                    JasperPrint jasperPrint = JasperFillManager.fillReport(path, parametro, PgConnector.getConexion());
                    JRXlsExporter xlsExporter = new JRXlsExporter();
                    xlsExporter.setExporterInput(new SimpleExporterInput(jasperPrint));
                    xlsExporter.setExporterOutput(new SimpleOutputStreamExporterOutput(PATH_REPORT_FILE + nameExcel);
                    SimpleXlsReportConfiguration xlsReportConfiguration = new SimpleXlsReportConfiguration();
                    SimpleXlsExporterConfiguration xlsExporterConfiguration = new SimpleXlsExporterConfiguration();
                    xlsReportConfiguration.setOnePagePerSheet(true);
                    xlsReportConfiguration.setRemoveEmptySpaceBetweenRows(false);
                    xlsReportConfiguration.setDetectCellType(true);
                    xlsReportConfiguration.setWhitePageBackground(false);
                    xlsExporter.setConfiguration(xlsReportConfiguration);
                    xlsExporter.exportReport();

                } catch (Exception ex) {
                    ex.printStackTrace();
                }

请先尝试将文件保存到文件系统,以查看生成的报告是否有问题,或者之后是否有问题。请先尝试将文件保存到文件系统,以查看生成的报告是否有问题,或者之后是否有问题。