zoukankan      html  css  js  c++  java
  • 写着写着就不知道自己定义的方法是干嘛的了

    @GetMapping("/export")
        public void export(HttpServletRequest request, HttpServletResponse response) {
            File file = FileUtils.getExcelFile("docx文件名");
            InputStream is = this.getClass().getClassLoader().getResourceAsStream("templates/customized/" + "auditFromBeforeFundPayment" + ".docx");
            try (OutputStream os = new FileOutputStream(file)) {
                XWPFDocument document = new XWPFDocument(is);
                XWPFTable xwpfTable = document.getTables().get(0);
                List<XWPFTableRow> rows = xwpfTable.getRows();
                rows.get(0).getTableCells().get(1).setText("项目名称");
                XWPFTableRow row1 = rows.get(1);
                List<XWPFTableCell> row1Cells = row1.getTableCells();
                row1Cells.get(1).setText("项目编号");
                row1Cells.get(3).setText("协议编号");
                is.close();
                document.write(os);
            } catch (IOException e) {
                throw new BadRequestException(e.getMessage());
            } catch (Exception e) {
                System.out.println(e.getMessage());
                throw new BadRequestException(e.getMessage());
            }
            FileUtils.downloadFile(request, response,file);
        }

    这行代码一写上,docx文件下载一直报错,无法正常打开。搞得我有点蒙蔽。

    我excel就这么写的啊,都能下载。

    然后想着是不是content-type或者啥的没有定义好?搞错了?然后一看代码,没这个玩意的代码啊。

    蒙蔽,想了下,是不是因为第一行代码的fileName中没有加上docx,这个时候蒙蔽了,给忘了方法是干什么的。

    最后花了差不多20分钟,突然想到进去方法里面看看,发现getExcelFile是用来下载xlsx文件的。修改下方法。

  • 相关阅读:
    bzoj3757 苹果树
    bzoj2743 [HEOI2012]采花
    bzoj4241 历史研究
    bzoj4448 [Scoi2015]情报传递
    bzoj3295 [Cqoi2011]动态逆序对
    bzoj4034 [HAOI2015]T2
    bzoj3339 Rmq Problem
    BZOJ 1017 魔兽地图
    BZOJ 1021 循环的债务
    SUOI #37 清点更多船只
  • 原文地址:https://www.cnblogs.com/woyujiezhen/p/13868081.html
Copyright © 2011-2022 走看看