javapoi数据导出成excel如何才能指定文件输出路径 现在是知道E盘路径 怎么弄成d框选择路径

javapoi数据导出成excel如何才能指定文件输出路径 现在是知道E盘路径 怎么弄成d框选择路径,第1张

点导出的时候,把所需要的数据传入导出界面JSP,这是我自己拼接的,代码如下

<%@ page contentType="application/vnd.ms-excelcharset=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","attachmentfilename="+unicoStr)

%>

<html>

<head>

<meta http-equiv="Content-Type" content="text/htmlcharset=UTF-8">

<style>

#tableinfo tr td{

text-align: centerfont-size: 13pxborder: 1px solid #64ABD6

}

#tableinfo{width: 100%border-collapse: collapseheight: 30pxline-height: 30px}

</style>

</head>

<body >

<table cellspacing="0" id="tableinfo" >

<tr>

<td style="text-align: centerfont-size:30pxfont-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=0i<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>

导轿裤出时自由选择路径的代码如裂帆毁下:

1、后台输出Excel文件代码:

OutputStream output = response.getOutputStream()

response.reset()

response.setHeader("Content-disposition", "attachmentfilename=" + path)

response.setContentType("Content-Type:application/vnd.ms-excel ")

wb.write(output)

output.close()

2、前端代码:

window.open("getExcelList","_blank")

导出excel数据

* @param id

* @param m

* @return

*/

@RequestMapping("/exportExcel")

public void exportExcel(@RequestParam("id") Integer id, Model m,HttpServletRequest req, HttpServletResponse resp) {

try {

ExportExcel<P2pLoanPlanVo>ex = new ExportExcel<P2pLoanPlanVo>()

String[] headers = {"最迟还款日", "还款金额","剩余几天","逾期几天", "罚息","是否垫付","状态","是肆备否发放收益"}

List<P2pLoanPlanVo>dataset = new ArrayList<P2pLoanPlanVo>()

List<P2pLoanPlan>plans = this.planService.getListByLoan(id)

for (int i = 0i <plans.size()i++) {

P2pLoanPlanVo p2pLoanPlanVo = new P2pLoanPlanVo()

p2pLoanPlanVo.setRepayDate(plans.get(i).getRepayDate())

p2pLoanPlanVo.setRepayAmount(plans.get(i).getRepayAmount())

if(plans.get(i).getRepayDays() >= 0 &&plans.get(i).getStatus() == 0){

p2pLoanPlanVo.setRepayDays(plans.get(i).getRepayDays())

}else{

p2pLoanPlanVo.setRepayDays(0)

}

if(plans.get(i).getRepayDays() <0 &&plans.get(i).getStatus() == 0){

p2pLoanPlanVo.setRepayYqDays(-plans.get(i).getRepayDays())

}else{

p2pLoanPlanVo.setRepayYqDays(0)

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/tougao/8157835.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-14
下一篇 2023-04-14

发表评论

登录后才能评论

评论列表(0条)

保存