Jsp利用jxl匯出資料至Excel並下載 @ Ken™ KM :: 隨意窩 Xuite日誌
  • 關鍵字
  • [此功能已終止服務]
    1. 沒有新回應!





  • Powered by Xuite
    200809301512Jsp利用jxl匯出資料至Excel並下載

    <%@ page contentType="application/unknown;charset=big5" %>
    <%@ page language="java" %>
    <%@ page import="java.sql.*" %>
    <%@ page import="javax.sql.*" %>
    <%@ include file="/opendb_jndi.jsp"%>
    <%@ page import="java.util.*"%>
    <%@ page import="java.io.*"%>
    <%@ page import="jxl.*"%>
    <%@ page import="jxl.write.*"%>
     
    <%
     String strFileName = "test.xls";
     response.reset();
     response.setHeader("Content-disposition","attachment; filename=" + strFileName);
     OutputStream os = response.getOutputStream();
     jxl.write.WritableWorkbook wwb = jxl.Workbook.createWorkbook(os);
     jxl.write.WritableSheet ws = wwb.createSheet("EDI",0);
     jxl.write.Number label_num;
     jxl.write.Label label_str;
     jxl.write.WritableCellFormat floatFormat;
     int numrow = 0;

     //明細
     sql="Select * From YouTable ";
     rs = smt.executeQuery(sql);

     while(rs.next())
     {
      label_num = new jxl.write.Number(0,numrow,strColumnName);
      ws.addCell(label_num);
           
      numrow++;

     }
     
     wwb.write();
     wwb.close();
     os.flush();
     os.close();
     con.close();
    %>

    沒有上一則|日誌首頁|沒有下一則
    回應