基于Apache poi封装,在上层做了模型转换的封装,让使用者更加简单方便
依赖:
- poi:4.1.2
- poi-ooxml:4.1.2
<dependency>
<groupId>com.sushengren</groupId>
<artifactId>easyword</artifactId>
<version>1.0.0</version>
</dependency>
public class TestEntity {
@WordProperty(value = "文物名称")
private String value1;
@WordProperty("文物级别")
private String value2;
@WordProperty("总登记号")
private String value3;
@WordProperty("分类号")
private String value4;
@WordProperty("档案编号")
private String value5;
@WordProperty("年")
private String value6;
@WordProperty("月")
private String value7;
@WordProperty("日")
private String value8;
@WordProperty("制档人")
private String value9;
@WordProperty(value = "图片", handle = PictureFillTypeHandle.class)
private InputStream img;
// 省略getting,setting
}
TestEntity testEntity = new TestEntity();
testEntity.setValue1("北宋“富”字大狮子绣球藤花纹绫");
testEntity.setValue2("一级");
testEntity.setValue3("T0001");
testEntity.setValue4("F0001");
testEntity.setValue5("DA00001");
testEntity.setValue6("2020");
testEntity.setValue7("12");
testEntity.setValue8("24");
testEntity.setValue9("杰克");
testEntity.setImg(new FileInputStream(new File("C:\\Users\\AD\\Pictures\\01.jpg")));
File file = new File("C:\\Users\\AD\\Desktop\\CollectionFile.docx");
FileOutputStream out = new FileOutputStream("C:\\Users\\AD\\Desktop\\CollectionFile1.docx");
EasyWord.of(file).doWrite(testEntity).toOutputStream(out);