欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

jsp操作Execl分析

程序员文章站 2022-03-03 09:27:11
<%@ page contenttype="text/html; charset=gb2312" language="java" import="java.sql.*"&nb...

<%@ 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.*"%>
<(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);