根据html导出excel和word

把html字符串转成base64编码传入,直接传入html各种标签后端无法直接接收

接收htmlbase64编码然后通过浏览器下载文件

java 复制代码
@Override
    public void htmlToExcel(ExportPo po, HttpServletResponse response)throws Exception {
        String fileName=po.getFileName()+".xlsx";
        log.info("开始导出"+fileName);
        byte[] decodedBytes = Base64.getDecoder().decode(po.getHtmlBaseCode64());
        ByteArrayInputStream inputStream = new ByteArrayInputStream(decodedBytes);
        Workbook workbook = new Workbook(inputStream);
        response.setContentType("application/octet-stream");
        response.setHeader(HttpHeaders.CONTENT_DISPOSITION,
                "attachment; filename=" + URLEncoder.encode(fileName, "UTF-8"));
        try (ServletOutputStream outputStream = response.getOutputStream()){
            workbook.save(outputStream, SaveFormat.XLSX);
            outputStream.flush();
        }
        log.info(fileName+"导出完成");
    }

    @Override
    public void htmlToWord(ExportPo po, HttpServletResponse response) throws Exception {
        String fileName=po.getFileName()+".docx";
        log.info("开始导出"+fileName);
        byte[] decodedBytes = Base64.getDecoder().decode(po.getHtmlBaseCode64());
        ByteArrayInputStream inputStream = new ByteArrayInputStream(decodedBytes);
        Document doc = new Document(inputStream);
        response.setContentType("application/octet-stream");
        response.setHeader(HttpHeaders.CONTENT_DISPOSITION,
                "attachment; filename=" + URLEncoder.encode(fileName, "UTF-8"));
        try (ServletOutputStream outputStream = response.getOutputStream()){
            doc.save(outputStream, com.aspose.words.SaveFormat.DOCX);
            outputStream.flush();
        }
        log.info(fileName+"导出完成");
    }

读取本地html文件转出后保存到本地

java 复制代码
   private static void htmlToExcel() throws Exception {
        String htmlFile = "C:\\Users\\lenovo\\Desktop\\111.html";
        String excelFile = "C:\\Users\\lenovo\\Desktop\\test2.xlsx";
        Workbook workbook=new Workbook(htmlFile);
        workbook.save(excelFile);
    }

    private static void htmlToWord() throws Exception {
        String htmlFile = "C:\\Users\\lenovo\\Desktop\\111.html";
        String wordFile = "C:\\Users\\lenovo\\Desktop\\保供简报.docx";
        Document doc = new Document(htmlFile);
        doc.save(wordFile, SaveFormat.DOCX);
    }
}
java 复制代码
<dependency>
            <groupId>com.aspose</groupId>
            <artifactId>aspose-cells</artifactId>
            <scope>system</scope>
            <version>25.10</version>
            <systemPath>${project.basedir}/src/main/resources/lib/aspose-cells-25.10.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>com.aspose</groupId>
            <artifactId>aspose-words</artifactId>
            <scope>system</scope>
            <version>19.3</version>
            <systemPath>${project.basedir}/src/main/resources/lib/aspose-words-19.3.jar</systemPath>
        </dependency>
相关推荐
晚烛4 小时前
CANN + 物理信息神经网络(PINNs):求解偏微分方程的新范式
javascript·人工智能·flutter·html·零售
ۓ明哲ڪ5 小时前
网页视频倍速播放.
html
缺点内向7 小时前
C#: 告别繁琐!轻松移除Word文档中的文本与图片水印
c#·自动化·word·.net
觉醒大王8 小时前
哪些文章会被我拒稿?
论文阅读·笔记·深度学习·考研·自然语言处理·html·学习方法
徐小夕@趣谈前端9 小时前
拒绝重复造轮子?我们偏偏花365天,用Vue3写了款AI协同的Word编辑器
人工智能·编辑器·word
Never_Satisfied10 小时前
在JavaScript / HTML中,关于querySelectorAll方法
开发语言·javascript·html
kingwebo'sZone11 小时前
C#使用Aspose.Words把 word转成图片
前端·c#·word
夏幻灵13 小时前
HTML5里最常用的十大标签
前端·html·html5
程序员猫哥_14 小时前
HTML 生成网页工具推荐:从手写代码到 AI 自动生成网页的进化路径
前端·人工智能·html
杨超越luckly14 小时前
HTML应用指南:利用GET请求获取中国500强企业名单,揭秘企业增长、分化与转型的新常态
前端·数据库·html·可视化·中国500强