首页 > 数据库技术 > 详细

将读到的excel导出数据库

时间:2016-03-28 16:45:36      阅读:140      评论:0      收藏:0      [点我收藏+]

第一种  直接在代码中导出 无配置

import org.apache.struts2.ServletActionContext;

InputStream is = new FileInputStream(filePath + "DocumentExcel\\ziping.xls");
HSSFWorkbook workbook = new HSSFWorkbook(is);

HttpServletResponse response = ServletActionContext.getResponse();
response.reset();
response.setContentType("application/x-msdownload");
response.setHeader("Content-Disposition",
"attachment; filename=" + new String(( "表格").getBytes("gb2312"), "ISO-8859-1")
+ ".xls");
ServletOutputStream outStream = null;
try {
outStream = response.getOutputStream();
workbook.write(outStream);
} catch (Exception e) {
e.printStackTrace();
} finally {
outStream.close();
}

 

第二种进行导出 有配置

ByteArrayOutputStream fileOut = new ByteArrayOutputStream();
try {
wb.write(fileOut);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
String fn ="表.xls";
byte[] b = fileOut.toByteArray();
inputStream = new ByteArrayInputStream(b);
this.setFilename(new String(fn.getBytes("GBK"), "ISO8859-1"));
fileOut.close();
return "download";

<!--struts-action--!>

<result name="download" type="stream">
<param name="contentType">application/octet-stream</param>
<param name="inputName">inputStream</param>
<param name="contentDisposition">attachment;filename="${filename}"</param>
<param name="bufferSize">4096</param>
</result>

将读到的excel导出数据库

原文:http://www.cnblogs.com/jquerypan/p/5329569.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!