JXLS无法将excel输出到servlet以供用户下载

时间:2016-03-28 13:30:27

标签: excel servlets

您好我试图使用jxls库输出从模板xls生成的excel文件,但我找不到这样做的方法。

我的代码如下:

    ServletContext contexto = request.getServletContext();
    String path = contexto.getRealPath("/lib/xlsx/plantilla.xlsx");

    Conexion conexion = new Conexion();
    List<Conexion> conexiones = new ArrayList<Conexion>();

    ResultSet rs = CargarConsultas.ejecutarConsulta("CONS_GET_TABLA_CONEXION");
    try {
        while(rs.next()) {
        conexion.setIp(rs.getString("ori_ip"));
        conexion.setMac(rs.getString("ori_mac"));
        conexion.setUrl_destino(rs.getString("url_dest"));
        conexion.setSolicitud(rs.getString("time_stamp_solicitud"));
        conexion.setUser_id(rs.getString("user_id"));
        conexion.setSubida(rs.getString("icoming"));
        conexion.setBajada(rs.getString("outgoing"));
        conexion.setAutorizacion(rs.getString("time_stamp_autorizacion"));
        conexion.setRenovacion(rs.getString("time_stamp_renovacion"));
        conexion.setFin_sesion(rs.getString("time_stamp_fin_sesion"));
        conexion.setGw_adress(rs.getString("gw_address"));
        conexion.setGw_port(rs.getString("gw_port"));


        conexiones.add(conexion);


        }
    } catch (SQLException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }



    File salida = new File(path);
    InputStream is = new FileInputStream(salida);
    try (FileOutputStream os = new FileOutputStream("salida.xlsx")) {

        Context context = new Context();
        context.putVar("conexiones", conexiones);
        JxlsHelper.getInstance().processTemplate(is, os, context);

    } catch (Exception e) {

        e.printStackTrace();
    }

如果您知道如何输出它并且不将其保存到服务器磁盘,请让我知道。代码工作正常。非常感谢

0 个答案:

没有答案