mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
fix code
This commit is contained in:
parent
b91561efe6
commit
59d155e00f
@ -7,29 +7,72 @@ import org.ofdrw.layout.element.Div;
|
|||||||
import org.ofdrw.layout.element.Paragraph;
|
import org.ofdrw.layout.element.Paragraph;
|
||||||
|
|
||||||
import java.io.Closeable;
|
import java.io.Closeable;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.OutputStream;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* OFD文件生成器
|
||||||
|
*
|
||||||
|
* @author looly
|
||||||
|
* @since 5.5.3
|
||||||
|
*/
|
||||||
public class OfdWriter implements Serializable, Closeable {
|
public class OfdWriter implements Serializable, Closeable {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
private final Path destFile;
|
|
||||||
private final OFDDoc doc;
|
private final OFDDoc doc;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构造
|
||||||
|
*
|
||||||
|
* @param file 生成的文件
|
||||||
|
*/
|
||||||
|
public OfdWriter(File file){
|
||||||
|
this(file.toPath());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构造
|
||||||
|
*
|
||||||
|
* @param file 生成的文件
|
||||||
|
*/
|
||||||
public OfdWriter(Path file){
|
public OfdWriter(Path file){
|
||||||
this.destFile = file;
|
|
||||||
this.doc = new OFDDoc(file);
|
this.doc = new OFDDoc(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构造
|
||||||
|
*
|
||||||
|
* @param out 需要输出的流
|
||||||
|
*/
|
||||||
|
public OfdWriter(OutputStream out){
|
||||||
|
this.doc = new OFDDoc(out);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 增加文本内容
|
||||||
|
*
|
||||||
|
* @param font 字体
|
||||||
|
* @param texts 文本
|
||||||
|
* @return this
|
||||||
|
*/
|
||||||
public OfdWriter addText(Font font, String... texts){
|
public OfdWriter addText(Font font, String... texts){
|
||||||
final Paragraph paragraph = new Paragraph();
|
final Paragraph paragraph = new Paragraph();
|
||||||
paragraph.setDefaultFont(font);
|
if(null != font){
|
||||||
|
paragraph.setDefaultFont(font);
|
||||||
|
}
|
||||||
for (String text : texts) {
|
for (String text : texts) {
|
||||||
paragraph.add(text);
|
paragraph.add(text);
|
||||||
}
|
}
|
||||||
return add(paragraph);
|
return add(paragraph);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 增加节点,
|
||||||
|
* @param div 节点,可以是段落、Canvas、Img或者填充
|
||||||
|
* @return this
|
||||||
|
*/
|
||||||
public OfdWriter add(Div div){
|
public OfdWriter add(Div div){
|
||||||
this.doc.add(div);
|
this.doc.add(div);
|
||||||
return this;
|
return this;
|
||||||
|
@ -0,0 +1,16 @@
|
|||||||
|
package cn.hutool.poi.ofd;
|
||||||
|
|
||||||
|
import cn.hutool.core.io.FileUtil;
|
||||||
|
import org.junit.Ignore;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class OfdWriterTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Ignore
|
||||||
|
public void writeTest(){
|
||||||
|
final OfdWriter ofdWriter = new OfdWriter(FileUtil.file("d:/test/test.ofd"));
|
||||||
|
ofdWriter.addText(null, "测试文本");
|
||||||
|
ofdWriter.close();
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user