程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> JSP編程 >> 關於JSP >> jsp操作Execl分析

jsp操作Execl分析

編輯:關於JSP

<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*"  %>
<%@ page import="jxl.*"%>
<%@ page import="jxl.write.*"%>
<%@ page import="java.io.*"%>
<%@ page import="java.util.*"%>
<jsp(SUN企業級應用的首選):useBean id="conn" class="db.DbConnection" scope="page"/>
<%
String sql=(String)session.getValue("sql");
//String apti=(String)session.getValue("apti");
//select companyapti.companyid,companyapti.companytype,companyapti.c

ompanyname,companyinfo.province,companyinfo.city, companyinfo.address,
//companyinfo.connectman,companyinfo.mobile,companyinfo.tel,companyinfo.telephone
%>
<%
try{
   
    WritableWorkbook  workbook = Workbook.createWorkbook(new File(request.getRealPath("/")+"/mis/"+"/企業信息.xls"));
    //創建Excel工作表
    WritableSheet sheet=workbook.createSheet("企業信息",0);
 //jxl.write.WritableSheet ws = wwb.createSheet("Test Sheet 1", 0);

    //設置字體和格式
 
 //writer data
 //while (rs.next()) {  //while start
   // for(int i=1;i<=23;i++){
   // username=rs.getString(1).equals("0")?"":rs.getString(1).trim();
  
   // username="yzhxy2002";
   // Label l=new Label(0, 0, username );
   // sheet.addCell(l);
 //jxl.write.Label labelC = new jxl.write.Label(1, 0, "This is a Label cell");
    //sheet.addCell(labelC);
 Label n=null,p=null,c=null,a=null,m=null,s=null,t=null,t1=null,t2=null;
    String companyid="", apti="",aptiname="",companyname="",companytype="",province="",

city="",address="",connectman="",mobile="",tel="",telephone="";
 ResultSet rs=null;
  
 //out.print(sql);
    rs=conn.executeQuery(sql);
 int i=0;
 while(rs.next()){
 //查詢資質
 StringTokenizer fenxi=new StringTokenizer(rs.getString("companytype"),"-");
 while(fenxi.hasMoreTokens()){
      companytype=fenxi.nextToken().toString();
   String sql0="select * from aptitype where typeid="+companytype+"";
   ResultSet rs0=conn.executeQuery(sql0);
   if(rs0.next()){
     aptiname=new String(rs0.getString("typename").getBytes("iso8859-1") );
    }
   apti=aptiname+"-"+apti;  
     }//while
 //
 
 n=new Label(0,i,new String(rs.getString("companyname").getBytes("iso8859-1")));
 p=new Label(1,i,new String(rs.getString("province").getBytes("iso8859-1")));
 c=new Label(2,i,new String(rs.getString("city").getBytes("iso8859-1")));
 a=new Label(3,i,new String(rs.getString("address").getBytes("iso8859-1")));
 m=new Label(4,i,new String(rs.getString("connectman").getBytes("iso8859-1")));
 s=new Label(5,i,rs.getString("mobile"));
 t=new Label(6,i,rs.getString("tel"));
 t1=new Label(7,i,rs.getString("telephone"));
 t2=new Label(8,i,apti);

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved