前置条件:已创建word模板文件 代码示例: public static void readWOrd(String templatePath, String temDir, String fileName, Vo data) { if (data == null || data.getName() == null) { throw new JeecgBootException("数据异常"); } //Assert.notNull(templatePath, "模板路径不能为空"); //Assert.notNull(temDir, "临时文件路径不能为空"); Assert.notNull(fileName, "导出文件名不能为空"); Assert.isTrue(fileName.endsWith(".docx"), "word导出请使用docx格式"); if (!temDir.endsWith("/")) { temDir = temDir + File.separator; } File dir = new File(temDir); if (!dir.exists()) { dir.mkdirs(); } try { // 读取模板文件 FileInputStream fis = new FileInputStream(templatePath+"template.docx"); XWPFDocument document = new XWPFDocument(fis); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); int startRow = 1; // 第一行是标题
java 导出\修改word文件
最新推荐文章于 2025-01-17 13:39:34 发布