import java.io.File;
import java.io.IOException;
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.WritableSheet;
import jxl.write.WritableWorkbook;
public class Download extends HttpServlet {
/**
* Constructor of the object.
*/
public Download() {
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 {
this.doPost(request, response);
}
/**
* 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 {
response.setContentType("text/html");
try {
//构建Workbook对象, 只读Workbook对象
// Method 1:创建可写入的Excel工作薄
/*File(String pathname)
通过给定路径名字符串转换成抽象路径名来创建一个新 File 实例。*/
WritableWorkbook wwb = Workbook.createWorkbook(new File(
"D:\\download.xls"));
// Method 2:将WritableWorkbook直接写入到输出流
/*
* OutputStream os = new FileOutputStream(targetfile);
* jxl.write.WritableWorkbook wwb = Workbook.createWorkbook(os);
*/
// 创建Excel工作表
WritableSheet ws = wwb.createSheet("Test Sheet 1", 0);
// 1.添加Label对象
Label labelC = new Label(0, 0, "This is a Label cell");
ws.addCell(labelC);
// 添加带有字型Formatting的对象
/*
* jxl.write.WritableFont wf = new
* jxl.write.WritableFont(WritableFont.TIMES, 18, WritableFont.BOLD,
* true); jxl.write.WritableCellFormat wcfF = new
* jxl.write.WritableCellFormat(wf); jxl.write.Label labelCF = new
* jxl.write.Label(1, 0, "This is a Label Cell", wcfF);
* ws.addCell(labelCF);
*/
// 添加带有字体颜色Formatting的对象
/*
* jxl.write.WritableFont wfc = new
* jxl.write.WritableFont(WritableFont.ARIAL, 10,
* WritableFont.NO_BOLD, false, UnderlineStyle.NO_UNDERLINE,
* jxl.format.Colour.RED); jxl.write.WritableCellFormat wcfFC = new
* jxl.write.WritableCellFormat(wfc); jxl.write.Label labelCFC = new
* jxl.write.Label(1, 0, "This is a Label Cell", wcfFC);
* ws.addCell(labelCF);
*/
// 2.添加Number对象
/*
* jxl.write.Number labelN = new jxl.write.Number(0, 1, 3.1415926);
* ws.addCell(labelN);
*/
// 添加带有formatting的Number对象
/*
* jxl.write.NumberFormat nf = new jxl.write.NumberFormat("#.##");
* jxl.write.WritableCellFormat wcfN = new
* jxl.write.WritableCellFormat(nf); jxl.write.Number labelNF = new
* jxl.write.Number(1, 1, 3.1415926, wcfN); ws.addCell(labelNF);
*/
// 3.添加Boolean对象
/*
* jxl.write.Boolean labelB = new jxl.write.Boolean(0, 2, false);
* ws.addCell(labelB);
*/
// 4.添加DateTime对象
/*
* jxl.write.DateTime labelDT = new jxl.write.DateTime(0, 3, new
* java.util.Date()); ws.addCell(labelDT);
*/
// 添加带有formatting的DateFormat对象
/*
* jxl.write.DateFormat df = new jxl.write.DateFormat("dd MM yyyy
* hh:mm:ss"); jxl.write.WritableCellFormat wcfDF = new
* jxl.write.WritableCellFormat(df); jxl.write.DateTime labelDTF =
* new jxl.write.DateTime(1, 3, new java.util.Date(), wcfDF);
* ws.addCell(labelDTF);
*/
// 写入Exel工作表
wwb.write();
// 关闭Excel工作薄对象
wwb.close();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException
* if an error occure
*/
public void init() throws ServletException {
// Put your code here
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
jsp关于excel的上传下载
共52个文件
tld:30个
jar:6个
project:2个
5星 · 超过95%的资源 需积分: 9 139 下载量 50 浏览量
2009-05-08
18:12:11
上传
评论
收藏 1.93MB RAR 举报
温馨提示
jsp关于excel的上传下载jsp关于excel的上传下载jsp关于excel的上传下载
资源推荐
资源详情
资源评论
收起资源包目录
demo.rar (52个子文件)
demo
Upload1
.project 1KB
.mymetadata 294B
WebRoot
WEB-INF
fmt-1_0.tld 12KB
fmt.tld 19KB
sql-1_0-rt.tld 5KB
fmt-1_0-rt.tld 11KB
permittedTaglibs.tld 1KB
web.xml 523B
scriptfree.tld 2KB
c-1_0-rt.tld 11KB
c-1_0.tld 11KB
x-1_0-rt.tld 7KB
x.tld 12KB
sql.tld 8KB
lib
jstl.jar 20KB
jxl.jar 669KB
standard.jar 384KB
classes
upload.class 2KB
sql-1_0.tld 6KB
c.tld 16KB
fn.tld 7KB
x-1_0.tld 7KB
index.jsp 262B
META-INF
MANIFEST.MF 39B
.myeclipse
src
upload.java 2KB
.classpath 544B
Download
.project 1KB
.mymetadata 297B
WebRoot
WEB-INF
fmt-1_0.tld 12KB
fmt.tld 19KB
sql-1_0-rt.tld 5KB
fmt-1_0-rt.tld 11KB
permittedTaglibs.tld 1KB
web.xml 531B
scriptfree.tld 2KB
c-1_0-rt.tld 11KB
c-1_0.tld 11KB
x-1_0-rt.tld 7KB
x.tld 12KB
sql.tld 8KB
lib
jstl.jar 20KB
jxl.jar 669KB
standard.jar 384KB
classes
Download.class 2KB
sql-1_0.tld 6KB
c.tld 16KB
fn.tld 7KB
x-1_0.tld 7KB
index.jsp 218B
META-INF
MANIFEST.MF 39B
.myeclipse
src
Download.java 5KB
.classpath 544B
共 52 条
- 1
资源评论
- songlili20122012-09-06挺不错的东西,方便学习收藏了
gulingbin
- 粉丝: 0
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功