From 40c4313720cd5ad3907f959ad6383b7033437d8f Mon Sep 17 00:00:00 2001 From: Looly Date: Wed, 29 May 2024 19:58:50 +0800 Subject: [PATCH] add test --- .../cn/hutool/poi/excel/WriteStyleTest.java | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 hutool-poi/src/test/java/cn/hutool/poi/excel/WriteStyleTest.java diff --git a/hutool-poi/src/test/java/cn/hutool/poi/excel/WriteStyleTest.java b/hutool-poi/src/test/java/cn/hutool/poi/excel/WriteStyleTest.java new file mode 100644 index 000000000..eba2ca4c6 --- /dev/null +++ b/hutool-poi/src/test/java/cn/hutool/poi/excel/WriteStyleTest.java @@ -0,0 +1,41 @@ +package cn.hutool.poi.excel; + +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.date.DateUtil; +import cn.hutool.poi.excel.style.StyleUtil; +import org.apache.poi.ss.usermodel.CellStyle; +import org.apache.poi.ss.usermodel.Font; +import org.junit.Ignore; +import org.junit.Test; + +import java.util.List; + +/** + * 设置列样式测试 + */ +public class WriteStyleTest { + @Test + @Ignore + public void writeTest() { + List row1 = CollUtil.newArrayList("aaaaa", "bb", "cc", "dd", DateUtil.date(), 3.22676575765); + List row2 = CollUtil.newArrayList("aa1", "bb1", "cc1", "dd1", DateUtil.date(), 250.7676); + List row3 = CollUtil.newArrayList("aa2", "bb2", "cc2", "dd2", DateUtil.date(), 0.111); + List row4 = CollUtil.newArrayList("aa3", "bb3", "cc3", "dd3", DateUtil.date(), 35); + List row5 = CollUtil.newArrayList("aa4", "bb4", "cc4", "dd4", DateUtil.date(), 28.00); + List> rows = CollUtil.newArrayList(row1, row2, row3, row4, row5); + + ExcelWriter writer = ExcelUtil.getWriter("d:/test/writeTest.xlsx"); + writer.setStyleSet(null); + + final CellStyle cellStyle = StyleUtil.createDefaultCellStyle(writer.getWorkbook()); + cellStyle.setFont(StyleUtil.createFont(writer.getWorkbook(), Font.COLOR_RED, (short) 12, "宋体")); + + writer.write(rows); + + for (int i = 0; i < writer.getRowCount(); i++) { + writer.setStyle(cellStyle, 2, i); + } + + writer.close(); + } +}