真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

基與easyExcel實(shí)現(xiàn)excel模版導(dǎo)出-創(chuàng)新互聯(lián)

Easyexcel官方文檔

創(chuàng)新互聯(lián)-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價(jià)比武鄉(xiāng)網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫(kù),直接使用。一站式武鄉(xiāng)網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋武鄉(xiāng)地區(qū)。費(fèi)用合理售后完善,10多年實(shí)體公司更值得信賴。

excel模版位置:

模版數(shù)據(jù)填充處理:{.對(duì)應(yīng)的實(shí)體對(duì)象字段名}

com.alibabaeasyexcel3.1.0

直接上代碼:

public void export(HttpServletResponse response) throws IOException {
        ListcustomerComplaintCategoryVOList = DataTransformer.transform(customerComplaintService.selectCustomerComplaintDetailList(), CustomerComplaintDetailVO.class);
        if (CollectionUtils.isEmpty(customerComplaintCategoryVOList)) {
            throw new BusinessException("無可用數(shù)據(jù),導(dǎo)出失敗");
        }
        Resource resource = new ClassPathResource("template/客訴單導(dǎo)出模版.xlsx");
        String templatePath = resource.getFile().getPath();
        InputStream inputStream = ClassPathResource.class.getClassLoader().getResourceAsStream("template/客訴單導(dǎo)出模版.xlsx");
        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
        response.setCharacterEncoding("utf-8");
        // URLEncoder.encode防止中文亂碼
        String fileName = URLEncoder.encode("客訴單明細(xì)", "UTF-8");
        response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
        ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream()).withTemplate(templatePath).build();
//        ExcelWriter excelWriter = EasyExcel.write("D:/Users/wsh/Desktop/客訴單導(dǎo)出模版.xlsx").withTemplate(inputStream).build();
        WriteSheet writeSheet = EasyExcel.writerSheet().build();
        excelWriter.fill(customerComplaintCategoryVOList, writeSheet);
        // 關(guān)閉流
        excelWriter.finish();

該寫法本地一點(diǎn)問題沒有,放到服務(wù)器上,前端請(qǐng)求,報(bào):找不到模版文件

經(jīng)過一些了解,jar包的resource的位置發(fā)生改變,優(yōu)化方案:

public void export(HttpServletResponse response) throws IOException {
        ListcustomerComplaintCategoryVOList = DataTransformer.transform(customerComplaintService.selectCustomerComplaintDetailList(), CustomerComplaintDetailVO.class);
        if (CollectionUtils.isEmpty(customerComplaintCategoryVOList)) {
            throw new BusinessException("無可用數(shù)據(jù),導(dǎo)出失敗");
        }
        InputStream inputStream = ClassPathResource.class.getClassLoader().getResourceAsStream("template/客訴單導(dǎo)出模版.xlsx");
        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
        response.setCharacterEncoding("utf-8");
        // URLEncoder.encode防止中文亂碼
        String fileName = URLEncoder.encode("客訴單明細(xì)", "UTF-8");
        response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
        ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream()).withTemplate(inputStream).build();
//        ExcelWriter excelWriter = EasyExcel.write("D:/Users/wsh/Desktop/客訴單導(dǎo)出模版.xlsx").withTemplate(inputStream).build();
        WriteSheet writeSheet = EasyExcel.writerSheet().build();
        excelWriter.fill(customerComplaintCategoryVOList, writeSheet);
        // 關(guān)閉流
        excelWriter.finish();

最終結(jié)果

你是否還在尋找穩(wěn)定的海外服務(wù)器提供商?創(chuàng)新互聯(lián)www.cdcxhl.cn海外機(jī)房具備T級(jí)流量清洗系統(tǒng)配攻擊溯源,準(zhǔn)確流量調(diào)度確保服務(wù)器高可用性,企業(yè)級(jí)服務(wù)器適合批量采購(gòu),新人活動(dòng)首月15元起,快前往官網(wǎng)查看詳情吧


本文名稱:基與easyExcel實(shí)現(xiàn)excel模版導(dǎo)出-創(chuàng)新互聯(lián)
標(biāo)題鏈接:http://weahome.cn/article/coeghj.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部