Java 利用poi 导出excel表格如何在导出时自由选择路径?

 我来答
思念是一种醉过
高粉答主

2018-01-02 · 每个回答都超有意思的
知道大有可为答主
回答量:224
采纳率:100%
帮助的人:4.3万
展开全部

导出时自由选择路径的代码如下:

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


OutputStream output = response.getOutputStream();


response.reset();


response.setHeader("Content-disposition", "attachment; filename=" + 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 = 0; i < 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);

}

推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式