a我考网

 找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 100|回复: 0

[基础知识] 使用java生成excel功能实现

[复制链接]
发表于 2012-8-4 12:37:27 | 显示全部楼层 |阅读模式
1.jsp页面
1 C" d  W8 D; u. T) F- G+ r发送请求地址:s9p67_createExcel.do
8 o% m# d& l" h  w3 v* [public String createExcel() {
8 s+ A: N, T7 [/ I; G  try {( P& m8 F# l+ D$ f& N- e$ E4 {
   HttpServletResponse response = ServletActionContext.getResponse();2 q$ @1 ?1 B4 J" u
   OutputStream os = response.getOutputStream();; V. c1 ]7 n7 ~' O; P* c  c' L8 J
   response.reset();
# O8 K. q" g' L& x   response.setContentType("application/msexcel;charset=gbk");  //设置响应格式
2 X9 s8 s9 y8 x* _//设置响应头,即报表头
% X1 C" y0 E9 G  G! ~   response.setHeader("Content-disposition", "attachment;filename=" + new String("业务受理量统计报表".getBytes(), "iso-8859-1") + ".xls");; A4 ?. I6 Y2 a8 x
   HSSFWorkbook hwb = new HSSFWorkbook();* O* Y9 U1 m3 J" O
   HSSFSheet sheet = hwb.createSheet("new Sheet");
0 I* h0 n9 d1 W: |& T/ g   hwb.setSheetName(0, "业务受理量统计");( l$ e- Z6 J5 x: b( L0 F* L' ]! y
   HSSFRow row = sheet.createRow((short) 0);
4 c6 P/ \, s+ P, p2 @+ b   sheet.createFreezePane(0, 1);//设置第一行显示内容2 N# U% T! O" d9 u) [5 L+ k2 g( G
   createCell(hwb, row, (short) 0, "业务类型");* e0 Y' z+ w$ m) F$ q
   createCell(hwb, row, (short) 1, "操作名称");
* f) J) f6 A& m5 n# _+ U9 z- Z   createCell(hwb, row, (short) 2, "数量");3 u% h8 d4 i% P
   createCell(hwb, row, (short) 3, "收取金额");. w6 w% P* M% M7 e% b0 i
   createCell(hwb, row, (short) 4, "工号");) D1 V  D" e& w) n
//busBeans列表,为要显示的数据
& O3 P$ i5 h5 l
$ Q. v( s6 K- w) ]  Yfor (int i = 1; i
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Woexam.Com ( 湘ICP备18023104号 )

GMT+8, 2024-5-6 03:21 , Processed in 0.240378 second(s), 21 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表