mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
add template support
This commit is contained in:
@@ -143,7 +143,7 @@ public class ExcelWriteTest {
|
||||
writer.writeRow(row2);
|
||||
|
||||
// 生成文件或导出Excel
|
||||
writer.flush(FileUtil.file("d:/test/writeWithSheetTest.xlsx"));
|
||||
writer.flush(FileUtil.file("d:/test/writeWithSheetTest.xlsx"), true);
|
||||
|
||||
writer.close();
|
||||
}
|
||||
@@ -868,7 +868,7 @@ public class ExcelWriteTest {
|
||||
|
||||
writer.writeImg(file, 0, 0, 5, 10);
|
||||
|
||||
writer.flush(new File("C:\\Users\\zsz\\Desktop\\2.xlsx"));
|
||||
writer.flush(new File("C:\\Users\\zsz\\Desktop\\2.xlsx"), true);
|
||||
|
||||
writer.close();
|
||||
}
|
||||
|
@@ -22,6 +22,6 @@ public class TemplateContextTest {
|
||||
final ExcelWriter writer = ExcelUtil.getWriter("template.xlsx");
|
||||
final TemplateContext templateContext = new TemplateContext(writer.getSheet());
|
||||
Assertions.assertNotNull(templateContext.getCell("date"));
|
||||
Assertions.assertNotNull(templateContext.getCell(".month"));
|
||||
Assertions.assertNotNull(templateContext.getCell("month"));
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,34 @@
|
||||
package org.dromara.hutool.poi.excel.writer;
|
||||
|
||||
import org.dromara.hutool.core.io.file.FileUtil;
|
||||
import org.dromara.hutool.core.map.MapUtil;
|
||||
import org.dromara.hutool.poi.excel.ExcelUtil;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class TemplateWriterTest {
|
||||
@Test
|
||||
void writeRowTest() {
|
||||
final ExcelWriter writer = ExcelUtil.getWriter("d:/test/template.xlsx");
|
||||
|
||||
// 单个替换的变量
|
||||
writer.fillRow(MapUtil
|
||||
.builder("date", (Object)"2024-01-01")
|
||||
.build());
|
||||
|
||||
// 列表替换
|
||||
for (int i = 0; i < 10; i++) {
|
||||
writer.fillRow(MapUtil
|
||||
.builder("user.name", (Object)"张三")
|
||||
.put("user.age", 18)
|
||||
.put("year", 2024)
|
||||
.put("month", 8)
|
||||
.put("day", 24)
|
||||
.put("day", 24)
|
||||
.put("user.area123", "某某市")
|
||||
.put("invalid", "不替换")
|
||||
.build());
|
||||
}
|
||||
|
||||
writer.flush(FileUtil.file("d:/test/templateResult.xlsx"), true);
|
||||
}
|
||||
}
|
Binary file not shown.
Reference in New Issue
Block a user