在Excel ExtJS中导出多个记录

时间:2017-03-21 12:37:00

标签: java spring servlets model-view-controller extjs

我正在尝试将一个或多个记录从面板导出到Excel模板。到目前为止,我只能导出一个选定的记录,但我想改进这一部分。我已经尝试过但我找不到它。

我的代码ExtJS:

var prevFnExcel = function(grid, store, selModel){
        var parameters = store.data.keys.toString();
        var url = ctx + '/facturas.do?op=exportarExcel&idsFacturas=' + parameters;

        Ext.DomHelper.append(document.body, {
            tag: 'iframe',
            id:'informeIframe',
            frameBorder: 0,
            width: 0,
            height: 0,
            css: 'display:none;visibility:hidden;height:0px;',                       
            src: url
      });
     return false;
};

当我使用Spring时,我使用mvc.My Java类已实现:

    /*
     * (non-Javadoc)
     * @see pack.senectus.facturas.service.FacturasService#exportarExcel(javax.servlet.http.HttpServletResponse, java.io.InputStream, java.lang.Integer)
     */
    @Override
    public void exportarExcel(HttpServletResponse response, InputStream reporte, List<Integer> idsFacturas) throws ClassNotFoundException, Exception{

        List<DatosFactura> listaDatosFactura = new ArrayList<DatosFactura>();

        for (Integer id : idsFacturas) {
            DatosFactura datosFactura = new DatosFactura();
            Sene1FacturaTeleasistencia factura = (Sene1FacturaTeleasistencia) sene1FacturaTeleasistenciaDAO.getById(id);
            datosFactura.setSene1FacturaTeleasistencia(factura);
            listaDatosFactura.add(datosFactura);
        }

        String titulo = "export_facturas.xls";
        JasperUtils.generarExcelJasperReport(reporte, listaDatosFactura, null, response, titulo);

    }   

控制器是:

public ModelAndView exportarExcel(HttpServletRequest request, HttpServletResponse response) throws ClassNotFoundException, Exception{
        String dev = "";
        String ids = ServletRequestUtils.getStringParameter(request, "idsFacturas", "");
        String[] idsFacturas = ids.split(",");
        try{
            InputStream reporte = request.getSession(true).getServletContext().getResourceAsStream("/WEB-INF/reportes/facturaExcel.jrxml");
            facturaTeleasistenciaService.exportarExcel(response, reporte, Arrays.asList(ArrayUtils.toObject(Stream.of(idsFacturas).mapToInt(Integer::parseInt).toArray())));
        } catch (BusinessException e) {

            dev = Utils.successJsonWithId(Boolean.FALSE, e.getMessage(), 1);
        }
        return createJSONMaV(dev);

    }

1 个答案:

答案 0 :(得分:0)

对于一般知识后的思考,我留下解决方案以防万一。

var prevFnPDF = function (grid, store, selModel) {
var recordSelected = selModel.selections.map;
var obj = new Array ();
for (r in recordSelected) {
obj.push (r);
}
var url = ctx + '/facturas.do?op=exportarPdf&idsFacturas=' + obj.toString ();