javapoi数据导出成excel如何才能指定文件输出路径 现在是知道E盘路径 怎么弄成弹框选择路径
HSSFWorkbookwb=newHSSFWorkbook();//输出数据到wbFileOutputStreamfout=newFileOutputStream("E...
HSSFWorkbook wb = new HSSFWorkbook();
//输出数据到wb
FileOutputStream fout = new FileOutputStream("E:/order.xls");
wb.write(fout); 展开
//输出数据到wb
FileOutputStream fout = new FileOutputStream("E:/order.xls");
wb.write(fout); 展开
3个回答
展开全部
点导出的时候,把所需要的数据传入导出界面JSP,这是我自己拼接的,代码如下
<%@ page contentType="application/vnd.ms-excel; charset=utf-8" %>
<%@ page language="java" import="java.util.*,com.expect.bean.Admin" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String xlsname = request.getAttribute("xlsname").toString();
String fileName = xlsname+".xls";
byte[] yte = fileName.getBytes("GB2312");
String unicoStr = new String(yte, "ISO-8859-1");
response.setHeader("Content-disposition","attachment;filename="+unicoStr);
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style>
#tableinfo tr td{
text-align: center;font-size: 13px;border: 1px solid #64ABD6;
}
#tableinfo{width: 100%;border-collapse: collapse;height: 30px;line-height: 30px;}
</style>
</head>
<body >
<table cellspacing="0" id="tableinfo" >
<tr>
<td style="text-align: center;font-size:30px;font-weight: bold;" id="titletd" colspan="8">
<%=xlsname %>电费表<br/>
</td>
</tr>
<tr>
<td style="text-align: center;" id="titletd" colspan="2">
用户名:
</td>
<td style="text-align: center;" id="titletd">
分厂:
</td>
<td style="text-align: center;" id="titletd">
住宅区:
</td>
<td style="text-align: center;" id="titletd" >
楼层:
</td>
<td style="text-align: center;" id="titletd" >
具体住址:
</td>
<td style="text-align: center;" id="titletd" >
上次度数:
</td>
<td style="text-align: center;" id="titletd" >
本次度数:
</td>
<td style="text-align: center;" id="titletd" >
操作时间:
</td>
</tr>
</table>
<%
List list = (List)request.getAttribute("list");
if(list!=null && list.size()>0){
for(int i=0;i<list.size();i++){
Map m = (Map)list.get(i);
String userName = m.get("userName")==null || m.get("userName").equals("") ? "" : m.get("userName").toString();
String branch = m.get("branch")==null || m.get("branch").equals("") ? "" : m.get("branch").toString();
String upTown = m.get("upTown")==null || m.get("upTown").equals("") ? "" : m.get("upTown").toString();
String storey = m.get("storey")==null || m.get("storey").equals("") ? "" : m.get("storey").toString();
String home = m.get("home")==null || m.get("home").equals("") ? "" : m.get("home").toString();
String totalSum = m.get("totalSum")==null || m.get("totalSum").equals("") ? "" : m.get("totalSum").toString();
String enterTime = m.get("enterTime")==null || m.get("enterTime").equals("") ? "" : m.get("enterTime").toString();
String upMonthCount = m.get("upMonthCount")==null || m.get("upMonthCount").equals("") ? "" : m.get("upMonthCount").toString();
%>
<table cellspacing="0" id="tableinfo" >
<tr>
<td style="text-align: center;" id="titletd" colspan="2">
<%=userName %>
</td>
<td style="text-align: center;" id="titletd" >
<%=branch %>
</td>
<td style="text-align: center;" id="titletd" >
<%=upTown %>
</td>
<td style="text-align: center;" id="titletd" >
<%=storey %>
</td>
<td style="text-align: center;" id="titletd" >
<%=home %>
</td>
<td style="text-align: center;" id="titletd" >
<%=totalSum %>
</td>
<td style="text-align: center;" id="titletd" >
<%=upMonthCount %>
</td>
<td style="text-align: center;" id="titletd" >
<%=enterTime %>
</td>
</tr>
</table>
<%
}
}
%>
</body>
</html>
<%@ page contentType="application/vnd.ms-excel; charset=utf-8" %>
<%@ page language="java" import="java.util.*,com.expect.bean.Admin" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String xlsname = request.getAttribute("xlsname").toString();
String fileName = xlsname+".xls";
byte[] yte = fileName.getBytes("GB2312");
String unicoStr = new String(yte, "ISO-8859-1");
response.setHeader("Content-disposition","attachment;filename="+unicoStr);
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style>
#tableinfo tr td{
text-align: center;font-size: 13px;border: 1px solid #64ABD6;
}
#tableinfo{width: 100%;border-collapse: collapse;height: 30px;line-height: 30px;}
</style>
</head>
<body >
<table cellspacing="0" id="tableinfo" >
<tr>
<td style="text-align: center;font-size:30px;font-weight: bold;" id="titletd" colspan="8">
<%=xlsname %>电费表<br/>
</td>
</tr>
<tr>
<td style="text-align: center;" id="titletd" colspan="2">
用户名:
</td>
<td style="text-align: center;" id="titletd">
分厂:
</td>
<td style="text-align: center;" id="titletd">
住宅区:
</td>
<td style="text-align: center;" id="titletd" >
楼层:
</td>
<td style="text-align: center;" id="titletd" >
具体住址:
</td>
<td style="text-align: center;" id="titletd" >
上次度数:
</td>
<td style="text-align: center;" id="titletd" >
本次度数:
</td>
<td style="text-align: center;" id="titletd" >
操作时间:
</td>
</tr>
</table>
<%
List list = (List)request.getAttribute("list");
if(list!=null && list.size()>0){
for(int i=0;i<list.size();i++){
Map m = (Map)list.get(i);
String userName = m.get("userName")==null || m.get("userName").equals("") ? "" : m.get("userName").toString();
String branch = m.get("branch")==null || m.get("branch").equals("") ? "" : m.get("branch").toString();
String upTown = m.get("upTown")==null || m.get("upTown").equals("") ? "" : m.get("upTown").toString();
String storey = m.get("storey")==null || m.get("storey").equals("") ? "" : m.get("storey").toString();
String home = m.get("home")==null || m.get("home").equals("") ? "" : m.get("home").toString();
String totalSum = m.get("totalSum")==null || m.get("totalSum").equals("") ? "" : m.get("totalSum").toString();
String enterTime = m.get("enterTime")==null || m.get("enterTime").equals("") ? "" : m.get("enterTime").toString();
String upMonthCount = m.get("upMonthCount")==null || m.get("upMonthCount").equals("") ? "" : m.get("upMonthCount").toString();
%>
<table cellspacing="0" id="tableinfo" >
<tr>
<td style="text-align: center;" id="titletd" colspan="2">
<%=userName %>
</td>
<td style="text-align: center;" id="titletd" >
<%=branch %>
</td>
<td style="text-align: center;" id="titletd" >
<%=upTown %>
</td>
<td style="text-align: center;" id="titletd" >
<%=storey %>
</td>
<td style="text-align: center;" id="titletd" >
<%=home %>
</td>
<td style="text-align: center;" id="titletd" >
<%=totalSum %>
</td>
<td style="text-align: center;" id="titletd" >
<%=upMonthCount %>
</td>
<td style="text-align: center;" id="titletd" >
<%=enterTime %>
</td>
</tr>
</table>
<%
}
}
%>
</body>
</html>
展开全部
response.setHeader("Content-Disposition", "attachment;filename=order.xls");// 设定输出文件头
response.setContentType("application/vnd.ms-excel;charset=UTF-8");// 定义输出类型
OutputStream out = response.getOutputStream();
wb.write(out);
response.setContentType("application/vnd.ms-excel;charset=UTF-8");// 定义输出类型
OutputStream out = response.getOutputStream();
wb.write(out);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐于2017-09-07
展开全部
那就在 new FileOutputStream("E:/order.xls"); 前面使用一个文件路径选择框,去一下路径呗
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询