package test;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.ArrayList;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableCellFormat;
import jxl.write.WritableFont;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
public class ToExcel extends HttpServlet {
/**
* Constructor of the object.
*/
public ToExcel() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setHeader("Content-disposition", "attachment; filename=file.xls");//设定输出文件头
response.setContentType("application/vnd.ms-excel");//定义输出类型
String classes = request.getParameter("classes");
classes = classes == null || classes.equals("") ? null
: new String(classes.getBytes("ISO8859_1"), "gb2312");
//QueryImp query = new QueryImp();
QueryProce query=new QueryProce();
try {
query.setStudentClass();
} catch (SQLException e1) {
e1.printStackTrace();
}
try {
// 判断classes的值,以不同的值调用不同的方法
if (classes.equals("null")) {//注意这里的比较方式,其他方式是错误的。
query.setInfo();
} else {
query.setInfo(classes);
}
} catch (Exception e) {
e.printStackTrace();
}
ArrayList data = new ArrayList();
data = query.getData();
ArrayList colData = new ArrayList();
colData = query.getColData();
try{
OutputStream os=response.getOutputStream();
//OutputStream os = response.getOutputStream();
WritableFont wf = new WritableFont(WritableFont.ARIAL,12,WritableFont.NO_BOLD,false);
WritableCellFormat wcfF = new WritableCellFormat(wf);
WritableWorkbook wwb = Workbook.createWorkbook(os);
WritableSheet ws = wwb.createSheet("my first excel", 0);
// Label labelC = new Label(0,0,"姓名",wcfF);
for(int i=0;i<colData.size();i++){
Label labelc=new Label(i,0,(String) colData.get(i),wcfF);
ws.addCell(labelc);
}
for(int i=1;i<=data.size();i++){
ArrayList list = new ArrayList();
list=(ArrayList) data.get(i-1);
for(int j=0;j<list.size();j++){
Label label=new Label(j,i,(String) list.get(j),wcfF);
ws.addCell(label);
}
}
wwb.write();
wwb.close();
os.close();
}
catch(Exception e){
//e.printStackTrace();
}
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request,response);
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occure
*/
public void init() throws ServletException {
// Put your code here
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
ajaxtable.rar (90个子文件)
ajaxtable
dbconfig.xml 483B
src
test
ToExcel.java 4KB
QueryProce.java 3KB
Jdbc.java 2KB
QueryServlet.java 4KB
.project 1KB
WebRoot
css
tree.css 453B
images
radio1.gif 201B
9.swf 1KB
left_img.jpg 1KB
folder.gif 572B
lonbi.png 3KB
check_off.gif 76B
nav_line.gif 151B
blank.gif 54B
nav.jpg 345B
lonbi.jpg 6KB
lonbi.gif 1KB
minus.gif 197B
radio.gif 197B
sheet.gif 75B
right_img1.jpg 708B
logo.jpg 16KB
right_img3.gif 484B
Thumbs.db 13KB
check_on.gif 98B
right_img2.jpg 328B
right_img3-02.gif 235B
top_border.jpg 529B
plus.gif 200B
right_img4.jpg 328B
019.swf 2KB
loading.gif 2KB
META-INF
MANIFEST.MF 39B
WEB-INF
web.xml 2KB
classes
test
Test.class 2KB
QueryImp.class 4KB
PageInfo.class 3KB
storeObject.dat 0B
Jdbc.class 3KB
QueryServlet.class 4KB
Html.class 886B
JdbcOdbc.class 2KB
ObjectSaver.class 2KB
JudgeVar.class 536B
AjxcFenye.class 3KB
FenYeTest.class 2KB
ToExcel.class 4KB
Customer.class 3KB
QueryProce.class 3KB
tree
TreeViewRead.class 2KB
TreeElementInterfaces.class 273B
TreeElementImp.class 4KB
DBManage.class 3KB
TreeServlet.class 2KB
excise
myFirstAbstract.class 529B
myFirstInterface.class 185B
lib
images
radio1.gif 201B
9.swf 1KB
left_img.jpg 1KB
folder.gif 572B
lonbi.png 3KB
check_off.gif 76B
nav_line.gif 151B
blank.gif 54B
nav.jpg 345B
lonbi.jpg 6KB
lonbi.gif 1KB
minus.gif 197B
radio.gif 197B
sheet.gif 75B
right_img1.jpg 708B
logo.jpg 16KB
right_img3.gif 484B
Thumbs.db 13KB
check_on.gif 98B
right_img2.jpg 328B
right_img3-02.gif 235B
top_border.jpg 529B
plus.gif 200B
right_img4.jpg 328B
019.swf 2KB
loading.gif 2KB
classes12.jar 1.14MB
jxl.jar 664KB
ajaxquery.jsp 4KB
.classpath 478B
数据库导出学生表
students.dmp 4KB
.myumldata 66B
.mymetadata 288B
.myeclipse
共 90 条
- 1
youjunbin_2006
- 粉丝: 10
- 资源: 14
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页