jsp操作Execl分析

來源:互聯網
上載者:User
js <%@ 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: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);
sheet.addCell(n);sheet.addCell(p);sheet.addCell(c);
sheet.addCell(a);sheet.addCell(m);sheet.addCell(s);sheet.addCell(t);sheet.addCell(t1);
sheet.addCell(t2);
i++;
apti="";
}

//out.print(rs.get(0,2));
//第二個表
// WritableSheet sheet1=workbook.createSheet("資質資訊",1);
//companytype


workbook.write();
workbook.close();
// }
// }//while end
}
catch (Exception e)
{
e.printStackTrace();
}

%>

<html>
<head>
<title>操作Excel表</title>

</head>

<body>
<table width="653" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td> </td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td height="46"><div align="center"><a href="公司資訊.xls">

<img src=http://www.163design.net/j/f/".images/ziguang.gif" width="32" height="32" border="0">下載公司資訊</a></div></td>
</tr>
<tr>
<td><br>
</td>
</tr>
<tr>
<td> </td>
</tr>
</table>
</body>
</html>




相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.