-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
39ed3a6
commit 2c45fa0
Showing
2 changed files
with
109 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
src/test/java/com/alibaba/easyexcel/test/temp/WriteLargeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package com.alibaba.easyexcel.test.temp; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.apache.poi.ss.usermodel.BorderStyle; | ||
import org.apache.poi.ss.usermodel.FillPatternType; | ||
import org.apache.poi.ss.usermodel.HorizontalAlignment; | ||
import org.apache.poi.ss.usermodel.IndexedColors; | ||
import org.apache.poi.ss.usermodel.VerticalAlignment; | ||
import org.junit.Ignore; | ||
import org.junit.Test; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.alibaba.easyexcel.test.core.large.LargeData; | ||
import com.alibaba.easyexcel.test.demo.write.DemoData; | ||
import com.alibaba.easyexcel.test.util.TestFileUtil; | ||
import com.alibaba.excel.EasyExcel; | ||
import com.alibaba.excel.ExcelWriter; | ||
import com.alibaba.excel.write.metadata.WriteSheet; | ||
import com.alibaba.excel.write.metadata.style.WriteCellStyle; | ||
import com.alibaba.excel.write.metadata.style.WriteFont; | ||
import com.alibaba.excel.write.style.HorizontalCellStyleStrategy; | ||
|
||
/** | ||
* 临时测试 | ||
* | ||
* @author Jiaju Zhuang | ||
**/ | ||
@Ignore | ||
public class WriteLargeTest { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(WriteLargeTest.class); | ||
private int i = 0; | ||
|
||
@Test | ||
public void test() throws Exception { | ||
// 方法2 如果写到不同的sheet 同一个对象 | ||
String fileName = TestFileUtil.getPath() + "large" + System.currentTimeMillis() + ".xlsx"; | ||
// 头的策略 | ||
WriteCellStyle headWriteCellStyle = new WriteCellStyle(); | ||
// 背景设置为红色 | ||
headWriteCellStyle.setFillForegroundColor(IndexedColors.RED.getIndex()); | ||
WriteFont headWriteFont = new WriteFont(); | ||
headWriteFont.setFontHeightInPoints((short)20); | ||
headWriteCellStyle.setWriteFont(headWriteFont); | ||
// 内容的策略 | ||
WriteCellStyle contentWriteCellStyle = new WriteCellStyle(); | ||
// 这里需要指定 FillPatternType 为FillPatternType.SOLID_FOREGROUND 不然无法显示背景颜色.头默认了 FillPatternType所以可以不指定 | ||
contentWriteCellStyle.setFillPatternType(FillPatternType.SOLID_FOREGROUND); | ||
// 背景绿色 | ||
contentWriteCellStyle.setFillForegroundColor(IndexedColors.GREEN.getIndex()); | ||
WriteFont contentWriteFont = new WriteFont(); | ||
// 字体大小 | ||
contentWriteFont.setFontHeightInPoints((short)20); | ||
contentWriteCellStyle.setWriteFont(contentWriteFont); | ||
// 这个策略是 头是头的样式 内容是内容的样式 其他的策略可以自己实现 | ||
HorizontalCellStyleStrategy horizontalCellStyleStrategy = | ||
new HorizontalCellStyleStrategy(headWriteCellStyle, contentWriteCellStyle); | ||
|
||
|
||
ExcelWriter excelWriter = EasyExcel.write(fileName,LargeData.class).registerWriteHandler(horizontalCellStyleStrategy).build(); | ||
WriteSheet writeSheet = EasyExcel.writerSheet().build(); | ||
for (int j = 0; j < 100; j++) { | ||
excelWriter.write(data(), writeSheet); | ||
LOGGER.info("{} fill success.", j); | ||
} | ||
excelWriter.finish(); | ||
|
||
} | ||
|
||
|
||
private List<LargeData> data() { | ||
List<LargeData> list = new ArrayList<LargeData>(); | ||
int size = i + 5000; | ||
for (; i < size; i++) { | ||
LargeData largeData = new LargeData(); | ||
list.add(largeData); | ||
largeData.setStr1("str1-" + i); | ||
largeData.setStr2("str2-" + i); | ||
largeData.setStr3("str3-" + i); | ||
largeData.setStr4("str4-" + i); | ||
largeData.setStr5("str5-" + i); | ||
largeData.setStr6("str6-" + i); | ||
largeData.setStr7("str7-" + i); | ||
largeData.setStr8("str8-" + i); | ||
largeData.setStr9("str9-" + i); | ||
largeData.setStr10("str10-" + i); | ||
largeData.setStr11("str11-" + i); | ||
largeData.setStr12("str12-" + i); | ||
largeData.setStr13("str13-" + i); | ||
largeData.setStr14("str14-" + i); | ||
largeData.setStr15("str15-" + i); | ||
largeData.setStr16("str16-" + i); | ||
largeData.setStr17("str17-" + i); | ||
largeData.setStr18("str18-" + i); | ||
largeData.setStr19("str19-" + i); | ||
largeData.setStr20("str20-" + i); | ||
largeData.setStr21("str21-" + i); | ||
largeData.setStr22("str22-" + i); | ||
largeData.setStr23("str23-" + i); | ||
largeData.setStr24("str24-" + i); | ||
largeData.setStr25("str25-" + i); | ||
} | ||
return list; | ||
} | ||
} |