jsp操作Execl分析
2003-12-28 12:23
447 查看
<%@ 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.companyname,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="../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>
<%@ 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.companyname,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="../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>
相关文章推荐
- jsp操作Execl分析
- JSP针对XML文件操作技巧实例分析
- JSP针对XML文件操作技巧实例分析
- Java 操作Excel 分析 导出Execl
- JSP中操作数据库的常用SQL标签用法总结
- 野指针和内存操作分析
- 心得11--jsp自定义标签案例分析
- IEP项目对Word文件的操作分析
- 这么详细的分类 JSP源代码网站你见过没有? JSP中的每一个方法,每一个操作,每一个函数,每一个类.每一个属性,每一个事件都有相应的范例代码
- jsp、css中引入外部资源相对路径问题分析
- jsp操作数据库,并将结果分页显示
- OpenCV图像像素操作及效率分析
- mysql分表场景分析与简单分表操作
- 小白学数据分析----->SPSS探索分析实践操作[不同生命周期玩家的充值探索分析]
- JSP第十三次课:JSP项目开发高级操作(链接数据库通用化、md5加密、验证码)
- C/C++中对链表操作的理解&&实例分析
- JSP数据库操作例程 - 存储过程 - JDBC-ODBC - SQL Server - 1.1版本
- jsp 数组操作
- JSP数据库操作例程 - 存储过程
- Babel插件源码分析与babel.transform和babylon.parse操作AST实现效果