diff --git a/CHANGELOG.md b/CHANGELOG.md index 0483e04d4..8073a66c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ * 【core 】 修正DateUtil.betweenXXX注释错误(issue#I28XGW@Gitee) * 【core 】 增加NioUtil * 【core 】 增加GanymedUtil +* 【poi 】 增加OFD支持,OfdWriter ### Bug修复 * 【cache 】 修复Cache中get重复misCount计数问题(issue#1281@Github) diff --git a/hutool-poi/pom.xml b/hutool-poi/pom.xml index 8e67a85d7..d82e04e0e 100644 --- a/hutool-poi/pom.xml +++ b/hutool-poi/pom.xml @@ -18,7 +18,6 @@ 4.1.2 - 2.12.0 @@ -42,9 +41,9 @@ true - xerces - xercesImpl - ${xerces.version} + org.ofdrw + ofdrw-full + 1.7.2 compile true diff --git a/hutool-poi/src/main/java/cn/hutool/poi/ofd/OfdWriter.java b/hutool-poi/src/main/java/cn/hutool/poi/ofd/OfdWriter.java new file mode 100644 index 000000000..b0271c490 --- /dev/null +++ b/hutool-poi/src/main/java/cn/hutool/poi/ofd/OfdWriter.java @@ -0,0 +1,42 @@ +package cn.hutool.poi.ofd; + +import cn.hutool.core.io.IoUtil; +import org.ofdrw.font.Font; +import org.ofdrw.layout.OFDDoc; +import org.ofdrw.layout.element.Div; +import org.ofdrw.layout.element.Paragraph; + +import java.io.Closeable; +import java.io.Serializable; +import java.nio.file.Path; + +public class OfdWriter implements Serializable, Closeable { + private static final long serialVersionUID = 1L; + + private final Path destFile; + private final OFDDoc doc; + + public OfdWriter(Path file){ + this.destFile = file; + this.doc = new OFDDoc(file); + } + + public OfdWriter addText(Font font, String... texts){ + final Paragraph paragraph = new Paragraph(); + paragraph.setDefaultFont(font); + for (String text : texts) { + paragraph.add(text); + } + return add(paragraph); + } + + public OfdWriter add(Div div){ + this.doc.add(div); + return this; + } + + @Override + public void close() { + IoUtil.close(this.doc); + } +} diff --git a/hutool-poi/src/main/java/cn/hutool/poi/ofd/package-info.java b/hutool-poi/src/main/java/cn/hutool/poi/ofd/package-info.java new file mode 100644 index 000000000..e6e362122 --- /dev/null +++ b/hutool-poi/src/main/java/cn/hutool/poi/ofd/package-info.java @@ -0,0 +1,6 @@ +/** + * 开放版式文档(Open Fixed-layout Document )封装,基于ofdrw(https://gitee.com/Trisia/ofdrw) + * + * @author looly + */ +package cn.hutool.poi.ofd; \ No newline at end of file