- 浏览: 575205 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (174)
- JBPM (3)
- WWF (0)
- JavaScript (11)
- J2EE (40)
- OperationSystem (11)
- 数据库 (12)
- CSS (1)
- Ajax (2)
- J2SE (30)
- Tools (10)
- 服务器中间件 (3)
- 异常 (0)
- Flex (5)
- jQuery (11)
- html (9)
- Ejb (1)
- HTML5 Shiv–让该死的IE系列支持HTML5吧 (1)
- Spring (9)
- Quartz (3)
- log4j (1)
- maven (1)
- cpdetector (1)
- JSON (1)
- log4jdbc (1)
- asm (8)
- FusionCharts (1)
- jqplot (1)
- highcharts (1)
- excanvas (1)
- html5 (1)
- jpcap介绍 (1)
- weblogic (3)
- URLURLClassLoader (0)
- URLClassLoader (1)
- ant (2)
- ivy (2)
- nexus (1)
- IT (0)
- LoadRunner (1)
- SCSS (1)
- ruby (1)
- webstorm (1)
- typescript (1)
- Jboss7 (1)
- wildfly (1)
- oracle (5)
- esb (0)
- dubbo (2)
- zookeeper (3)
- eclipse (1)
- Android (2)
- Studio (1)
- Google (1)
- 微信 (1)
- 企业号 (1)
- Linux (13)
- Oracle12c (1)
- Hadoop (1)
- InletexEMC (1)
- Windows (1)
- Netty (3)
- Marshalling (2)
- Protobuf (1)
- gcc (1)
- Git (1)
- GitLab (1)
- shell (2)
- java (3)
- Spring4 (1)
- hibernate4 (1)
- postgresql (1)
- ApacheServer (2)
- Tomcat (2)
- ApacheHttpServer (2)
- realvnc (1)
- redhat (7)
- vncviewer (1)
- LVS (4)
- LVS-DR (1)
- RedHat6.5 (5)
- LVS-NAT (1)
- LVS-IPTUNNEL (2)
- LVS-TUN (1)
- keepalived (2)
- yum (1)
- iso (1)
- VMware (1)
- redhat5 (1)
- ha (1)
- nginx (2)
- proguard (1)
- Mat (1)
- DTFJ (1)
- axis2 (1)
- web service (1)
- centos (1)
- random (1)
- urandom (1)
- apache (1)
- IBM (1)
- cve (1)
- 漏洞 (1)
- JDBC (1)
- DataSource (1)
- jdk (1)
- tuxedo (2)
- wtc (1)
最新评论
-
skying007:
好资料,谢谢分享给啊
FusionCharts在服务器端导出图片(J2EE版) -
cgnnzg:
大神好 可以发一份源码给我学习么 多谢了 978241085 ...
springmvc+dubbo+zookeeper -
jifengjianhao:
求源码:854606899@qq.com
springmvc+dubbo+zookeeper -
wdloyeu:
shihuan8@163.com邮箱网盘在哪,没找到。能给份源 ...
Java Socket长连接示例代码 -
huangshangyuanji:
求代码:45613032@qq.com
springmvc+dubbo+zookeeper
Java代码
1.<%@ page contentType="text/html; charset=gbk" %>
2.<%@ taglib uri="/struts-tags" prefix="s"%>
3.<html>
4.<a href="excel.action">下载文件</a>
5.</html>
<%@ page contentType="text/html; charset=gbk" %>
<%@ taglib uri="/struts-tags" prefix="s"%>
<html>
<a href="excel.action">下载文件</a>
</html>
struts.xml文件
文件内容:
Xml代码
1.<?xml version="1.0" encoding="UTF-8" ?>
2.<!DOCTYPE struts PUBLIC
3. "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
4. "http://struts.apache.org/dtds/struts-2.0.dtd">
5.
6.<struts>
7.
8. <package name="default" extends="struts-default">
9. <action name="excel" class="ExcelDownloadAction">
10. <result name="success" type="stream">
11. <param name="contentType">application/vnd.ms-excel</param>
12. <param name="contentDisposition">attachment;filename="AllUsers.xls"</param>
13. <param name="inputName">excelFile</param>
14. </result>
15. </action>
16. </package>
17.</struts>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="default" extends="struts-default">
<action name="excel" class="ExcelDownloadAction">
<result name="success" type="stream">
<param name="contentType">application/vnd.ms-excel</param>
<param name="contentDisposition">attachment;filename="AllUsers.xls"</param>
<param name="inputName">excelFile</param>
</result>
</action>
</package>
</struts>
Java代码
1.import java.io.ByteArrayInputStream;
2.import java.io.ByteArrayOutputStream;
3.import java.io.IOException;
4.import java.io.InputStream;
5.
6.import org.apache.poi.hssf.usermodel.HSSFCell;
7.import org.apache.poi.hssf.usermodel.HSSFRow;
8.import org.apache.poi.hssf.usermodel.HSSFSheet;
9.import org.apache.poi.hssf.usermodel.HSSFWorkbook;
10.
11.import com.opensymphony.xwork2.ActionSupport;
12.
13.@SuppressWarnings("serial")
14.public class ExcelDownloadAction extends ActionSupport {
15.
16. public InputStream getExcelFile() {
17. HSSFWorkbook workbook = new HSSFWorkbook();
18. HSSFSheet sheet = workbook.createSheet("sheet1");
19. {
20. // 创建表头
21. HSSFRow row = sheet.createRow(0);
22. HSSFCell cell = row.createCell((short) 0);
23. cell.setCellValue("id");
24. cell = row.createCell((short) 1);
25. cell.setEncoding(HSSFWorkbook.ENCODING_UTF_16);
26. cell.setCellValue("姓");
27. cell = row.createCell((short) 2);
28. cell.setEncoding(HSSFWorkbook.ENCODING_UTF_16);
29. cell.setCellValue("名");
30. cell = row.createCell((short) 3);
31. cell.setEncoding(HSSFWorkbook.ENCODING_UTF_16);
32. cell.setCellValue("年龄");
33.
34. // 创建数据
35. // 第一行
36. row = sheet.createRow(1);
37. cell = row.createCell((short) 0);
38. cell.setCellValue("1");
39. cell = row.createCell((short) 1);
40. cell.setEncoding(HSSFWorkbook.ENCODING_UTF_16);
41. cell.setCellValue("张");
42. cell = row.createCell((short) 2);
43. cell.setEncoding(HSSFWorkbook.ENCODING_UTF_16);
44. cell.setCellValue("四");
45. cell = row.createCell((short) 3);
46. cell.setCellValue("23");
47.
48. // 第二行
49. row = sheet.createRow(2);
50. cell = row.createCell((short) 0);
51. cell.setCellValue("2");
52. cell = row.createCell((short) 1);
53. cell.setEncoding(HSSFWorkbook.ENCODING_UTF_16);
54. cell.setCellValue("李");
55. cell = row.createCell((short) 2);
56. cell.setEncoding(HSSFWorkbook.ENCODING_UTF_16);
57. cell.setCellValue("六");
58. cell = row.createCell((short) 3);
59. cell.setCellValue("30");
60. }
61.
62. ByteArrayOutputStream baos = new ByteArrayOutputStream();
63. try {
64. workbook.write(baos);
65. } catch (IOException e) {
66. // TODO Auto-generated catch block
67. e.printStackTrace();
68. }
69. byte[] ba = baos.toByteArray();
70. ByteArrayInputStream bais = new ByteArrayInputStream(ba);
71. return bais;
72.
73. }
74.
75. @Override
76. public String execute() throws Exception {
77. // TODO Auto-generated method stub
78. return super.execute();
79. }
80.
81.}
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import com.opensymphony.xwork2.ActionSupport;
@SuppressWarnings("serial")
public class ExcelDownloadAction extends ActionSupport {
public InputStream getExcelFile() {
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet("sheet1");
{
// 创建表头
HSSFRow row = sheet.createRow(0);
HSSFCell cell = row.createCell((short) 0);
cell.setCellValue("id");
cell = row.createCell((short) 1);
cell.setEncoding(HSSFWorkbook.ENCODING_UTF_16);
cell.setCellValue("姓");
cell = row.createCell((short) 2);
cell.setEncoding(HSSFWorkbook.ENCODING_UTF_16);
cell.setCellValue("名");
cell = row.createCell((short) 3);
cell.setEncoding(HSSFWorkbook.ENCODING_UTF_16);
cell.setCellValue("年龄");
// 创建数据
// 第一行
row = sheet.createRow(1);
cell = row.createCell((short) 0);
cell.setCellValue("1");
cell = row.createCell((short) 1);
cell.setEncoding(HSSFWorkbook.ENCODING_UTF_16);
cell.setCellValue("张");
cell = row.createCell((short) 2);
cell.setEncoding(HSSFWorkbook.ENCODING_UTF_16);
cell.setCellValue("四");
cell = row.createCell((short) 3);
cell.setCellValue("23");
// 第二行
row = sheet.createRow(2);
cell = row.createCell((short) 0);
cell.setCellValue("2");
cell = row.createCell((short) 1);
cell.setEncoding(HSSFWorkbook.ENCODING_UTF_16);
cell.setCellValue("李");
cell = row.createCell((short) 2);
cell.setEncoding(HSSFWorkbook.ENCODING_UTF_16);
cell.setCellValue("六");
cell = row.createCell((short) 3);
cell.setCellValue("30");
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
workbook.write(baos);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
byte[] ba = baos.toByteArray();
ByteArrayInputStream bais = new ByteArrayInputStream(ba);
return bais;
}
@Override
public String execute() throws Exception {
// TODO Auto-generated method stub
return super.execute();
}
}
本文出自:http://kin111.blog.51cto.com/738881/167727
1.<%@ page contentType="text/html; charset=gbk" %>
2.<%@ taglib uri="/struts-tags" prefix="s"%>
3.<html>
4.<a href="excel.action">下载文件</a>
5.</html>
<%@ page contentType="text/html; charset=gbk" %>
<%@ taglib uri="/struts-tags" prefix="s"%>
<html>
<a href="excel.action">下载文件</a>
</html>
struts.xml文件
文件内容:
Xml代码
1.<?xml version="1.0" encoding="UTF-8" ?>
2.<!DOCTYPE struts PUBLIC
3. "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
4. "http://struts.apache.org/dtds/struts-2.0.dtd">
5.
6.<struts>
7.
8. <package name="default" extends="struts-default">
9. <action name="excel" class="ExcelDownloadAction">
10. <result name="success" type="stream">
11. <param name="contentType">application/vnd.ms-excel</param>
12. <param name="contentDisposition">attachment;filename="AllUsers.xls"</param>
13. <param name="inputName">excelFile</param>
14. </result>
15. </action>
16. </package>
17.</struts>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="default" extends="struts-default">
<action name="excel" class="ExcelDownloadAction">
<result name="success" type="stream">
<param name="contentType">application/vnd.ms-excel</param>
<param name="contentDisposition">attachment;filename="AllUsers.xls"</param>
<param name="inputName">excelFile</param>
</result>
</action>
</package>
</struts>
Java代码
1.import java.io.ByteArrayInputStream;
2.import java.io.ByteArrayOutputStream;
3.import java.io.IOException;
4.import java.io.InputStream;
5.
6.import org.apache.poi.hssf.usermodel.HSSFCell;
7.import org.apache.poi.hssf.usermodel.HSSFRow;
8.import org.apache.poi.hssf.usermodel.HSSFSheet;
9.import org.apache.poi.hssf.usermodel.HSSFWorkbook;
10.
11.import com.opensymphony.xwork2.ActionSupport;
12.
13.@SuppressWarnings("serial")
14.public class ExcelDownloadAction extends ActionSupport {
15.
16. public InputStream getExcelFile() {
17. HSSFWorkbook workbook = new HSSFWorkbook();
18. HSSFSheet sheet = workbook.createSheet("sheet1");
19. {
20. // 创建表头
21. HSSFRow row = sheet.createRow(0);
22. HSSFCell cell = row.createCell((short) 0);
23. cell.setCellValue("id");
24. cell = row.createCell((short) 1);
25. cell.setEncoding(HSSFWorkbook.ENCODING_UTF_16);
26. cell.setCellValue("姓");
27. cell = row.createCell((short) 2);
28. cell.setEncoding(HSSFWorkbook.ENCODING_UTF_16);
29. cell.setCellValue("名");
30. cell = row.createCell((short) 3);
31. cell.setEncoding(HSSFWorkbook.ENCODING_UTF_16);
32. cell.setCellValue("年龄");
33.
34. // 创建数据
35. // 第一行
36. row = sheet.createRow(1);
37. cell = row.createCell((short) 0);
38. cell.setCellValue("1");
39. cell = row.createCell((short) 1);
40. cell.setEncoding(HSSFWorkbook.ENCODING_UTF_16);
41. cell.setCellValue("张");
42. cell = row.createCell((short) 2);
43. cell.setEncoding(HSSFWorkbook.ENCODING_UTF_16);
44. cell.setCellValue("四");
45. cell = row.createCell((short) 3);
46. cell.setCellValue("23");
47.
48. // 第二行
49. row = sheet.createRow(2);
50. cell = row.createCell((short) 0);
51. cell.setCellValue("2");
52. cell = row.createCell((short) 1);
53. cell.setEncoding(HSSFWorkbook.ENCODING_UTF_16);
54. cell.setCellValue("李");
55. cell = row.createCell((short) 2);
56. cell.setEncoding(HSSFWorkbook.ENCODING_UTF_16);
57. cell.setCellValue("六");
58. cell = row.createCell((short) 3);
59. cell.setCellValue("30");
60. }
61.
62. ByteArrayOutputStream baos = new ByteArrayOutputStream();
63. try {
64. workbook.write(baos);
65. } catch (IOException e) {
66. // TODO Auto-generated catch block
67. e.printStackTrace();
68. }
69. byte[] ba = baos.toByteArray();
70. ByteArrayInputStream bais = new ByteArrayInputStream(ba);
71. return bais;
72.
73. }
74.
75. @Override
76. public String execute() throws Exception {
77. // TODO Auto-generated method stub
78. return super.execute();
79. }
80.
81.}
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import com.opensymphony.xwork2.ActionSupport;
@SuppressWarnings("serial")
public class ExcelDownloadAction extends ActionSupport {
public InputStream getExcelFile() {
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet("sheet1");
{
// 创建表头
HSSFRow row = sheet.createRow(0);
HSSFCell cell = row.createCell((short) 0);
cell.setCellValue("id");
cell = row.createCell((short) 1);
cell.setEncoding(HSSFWorkbook.ENCODING_UTF_16);
cell.setCellValue("姓");
cell = row.createCell((short) 2);
cell.setEncoding(HSSFWorkbook.ENCODING_UTF_16);
cell.setCellValue("名");
cell = row.createCell((short) 3);
cell.setEncoding(HSSFWorkbook.ENCODING_UTF_16);
cell.setCellValue("年龄");
// 创建数据
// 第一行
row = sheet.createRow(1);
cell = row.createCell((short) 0);
cell.setCellValue("1");
cell = row.createCell((short) 1);
cell.setEncoding(HSSFWorkbook.ENCODING_UTF_16);
cell.setCellValue("张");
cell = row.createCell((short) 2);
cell.setEncoding(HSSFWorkbook.ENCODING_UTF_16);
cell.setCellValue("四");
cell = row.createCell((short) 3);
cell.setCellValue("23");
// 第二行
row = sheet.createRow(2);
cell = row.createCell((short) 0);
cell.setCellValue("2");
cell = row.createCell((short) 1);
cell.setEncoding(HSSFWorkbook.ENCODING_UTF_16);
cell.setCellValue("李");
cell = row.createCell((short) 2);
cell.setEncoding(HSSFWorkbook.ENCODING_UTF_16);
cell.setCellValue("六");
cell = row.createCell((short) 3);
cell.setCellValue("30");
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
workbook.write(baos);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
byte[] ba = baos.toByteArray();
ByteArrayInputStream bais = new ByteArrayInputStream(ba);
return bais;
}
@Override
public String execute() throws Exception {
// TODO Auto-generated method stub
return super.execute();
}
}
本文出自:http://kin111.blog.51cto.com/738881/167727
发表评论
-
Spring4Mvc整合Hibernate4框架示例
2016-02-05 11:52 1363今天用NetBeans8.1搭建了一套Spring4MVC+H ... -
Spring4配置properties文件的一点儿细节
2016-02-04 15:40 2763http://repo.spring.io/release/o ... -
JavaWeb发送信息到微信公众平台的企业号
2015-11-01 22:42 3766首先到微信公众平台申请微信企业号: https://qy.we ... -
springmvc+dubbo+zookeeper
2015-09-22 11:34 11933笔者这里使用的是apache- ... -
OracleAS10g安装配置与部署
2015-07-01 20:59 669先到Oracle官方下载OracleAS10的安装包,截图如下 ... -
java和spring使用weblogic数据源配置
2014-10-13 11:29 2953需要weblogic.jar和jrmpclient.jar ... -
一套基本的SpringMvc工程所需要的最基本jar包(pom.xml)
2014-08-19 16:38 1885附件里是pom.xml文件。 -
html的form表单提交得不到参数问题
2014-07-25 16:13 1812今天同事问我他的form表单按submit方式提交,在Java ... -
Spring3Mvc导出PDF的3种形式+导出excel的两种形式(exportAnimal.do)
2014-07-19 22:55 1092附件里SpringMvc导出PDF和Excel的示例代码。 ... -
Java利用中国网建SMS短信通平台发送手机短信
2014-04-26 21:55 2209JAVA发送手机短信,流传有几种方法: (1)使用webser ... -
在Java中发送电子邮件
2014-04-26 18:42 9571要先申请一个网易的126邮箱和一个新浪的com邮箱。 以下程 ... -
cpdetector_1.0.10_binary下载
2014-03-26 20:53 997附件里是cpdetector_1.0.10_binary.ra ... -
在Java代码中用Axis2调用DotNet语言的WebService程序
2014-02-19 15:19 2530package com.shihuan.ymail.com ... -
SpringMvc多语言配置
2014-01-14 16:01 14381applicationContext.xml文件中加入如下代码 ... -
log4j多级别多输出文件的配置
2013-07-22 21:28 1535以下代码需要log4j-1.2.17.jar的支持。 B ... -
mysql和Oracle在对clob和blob字段的处理
2012-08-25 18:50 30855一、MySQL与Oracle数据库如何处理Clob,Bl ... -
Spring3Mvc+Hibernate整合Axis2发布WebService并配置Quartz调度
2012-08-05 12:54 2186附件里是笔者的源代码,相关的jar包在笔者的abcdef的16 ... -
Lucene案例
2012-06-10 15:15 2577IndexerMmseg4j.java代码如下: import ... -
Mina入门程序
2012-06-02 15:05 1119附件里是Mina的入门程序。 http://mina.apa ... -
让Hibernate的执行语句看见完整参数
2012-04-29 10:09 1017http://www.ibm.com/developerwor ...
相关推荐
NULL 博文链接:https://fengyunxiao.iteye.com/blog/469943
struts2中利用poi导出excel的简单例子
struts2+poi实现excel文件的导出,虽然有很多jxl库实现的方案,而本方案是使用struts2 mvc, apache poi库实现excel的导入导出,文档很详细
利用struts2和poi把数据导出到excel
自己做的一个完整导出功能,struts2+poi导出excel 经过自己严格测试通过的。
Web开发技术,excel导出的详解,对POI导出EXCEL代码实现的详细解释
将assets中.xml中的doc文件中,就会生成word文档和excel文档
利用纯struts2.0+poi插件 实现导出excel
struts2+poi实现excel表格导出
struts2 poi 导入xls xlsx绝对兼容,直接导入myeclipse 使用
使用poi在excel中生成各种常见的图像,比如饼状图(普通饼状图、三D图,环状体、折线图、柱状图、等~~)
struts2、poi.jar、jxl.jar
Struts2 poi 实现从数据库中导出excel表
Java POI 生成Word文档,支持图片插入,关键是修改XML部分,本人已测试通过。
本人文章《使用poi根据模版生成word文档并转换成PDF文件》所需要用到的文件
struts2+poi 实现Excel导出,带jar包,适合初学者
在struts中利用poi组件导出excel
项目内有个excel 拿出来 在index页面点击选择导入直接运行
POI和JFreeChart框架实现生成Excel文件(生成 统计图)