通过JSF导出Word文档 - Primefaces?

时间:2014-02-05 20:43:50

标签: apache-poi doc

我已设法导出带有POI的Excel报表,但我想用Word可以指导导出中的参数。

我的代码java:

public void generarExcel() {
    try{
        LOGGER.info("Entro a Generar Excel de los Sistemas Asociados");
        Reporteador reporteador = new Reporteador();
        ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext();
        String ruta = servletContext.getRealPath("/");
        reporteador.generaExcelSistema("ReporteSistemas", ruta, sists);
    } catch (Exception e) {
        LOGGER.debug(Constante.EXECPCION_ENCONTRADA + e.toString(), e);
    }
}

------------------

public void generaExcelSistema(String nombre, String ruta, List<Sistema> sists) {
    try{
        HSSFWorkbook wb = new HSSFWorkbook();               
        HSSFSheet sheet = wb.createSheet("Sistema");    
        sheet.addMergedRegion(new CellRangeAddress(6,6,3,5));   
        sheet.setColumnWidth(1, 1500);
        sheet.setColumnWidth(2, 4000);
        sheet.setColumnWidth(3, 9000);
        sheet.setColumnWidth(4, 6000);
        sheet.setColumnWidth(5, 6000);
        sheet.setColumnWidth(6, 4500);
        sheet.setColumnWidth(7, 3000);
        cabeceraReportExcel(wb, sheet, ruta);           
        encabezadoColumnaSistema(wb, sheet, sists);      

        FacesContext facesContext = FacesContext.getCurrentInstance();
        ExternalContext externalContext = facesContext.getExternalContext();
        externalContext.setResponseContentType("application/vnd.ms-excel");
        externalContext.setResponseHeader("Content-Disposition", "attachment; filename=\""+nombre+".xls\"");
        wb.write(externalContext.getResponseOutputStream());
        facesContext.responseComplete();
    } catch(Exception e){
        LOGGER.debug(Constante.EXECPCION_ENCONTRADA + e.toString(), e);
    }
}

我希望你能指导我使用HWPFDocument类。

0 个答案:

没有答案