Skip to content

Commit

Permalink
修改测试案例
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuangjiaju committed May 30, 2023
1 parent 2ac224c commit bf2c31c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 38 deletions.
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
package com.alibaba.easyexcel.test.core.excludeorinclude;

import java.io.File;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.alibaba.easyexcel.test.util.TestFileUtil;
import com.alibaba.excel.EasyExcel;
import org.junit.jupiter.api.*;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import java.io.File;
import java.util.*;

/**
* @author Jiaju Zhuang
Expand Down Expand Up @@ -159,7 +150,7 @@ private void excludeIndex(File file) {
excludeColumnIndexes.add(0);
excludeColumnIndexes.add(3);
EasyExcel.write(file, ExcludeOrIncludeData.class).excludeColumnIndexes(excludeColumnIndexes).sheet()
.doWrite(data());
.doWrite(data());
List<Map<Integer, String>> dataMap = EasyExcel.read(file).sheet().doReadSync();
Assertions.assertEquals(1, dataMap.size());
Map<Integer, String> record = dataMap.get(0);
Expand All @@ -175,7 +166,7 @@ private void excludeFieldName(File file) {
excludeColumnFieldNames.add("column3");
excludeColumnFieldNames.add("column4");
EasyExcel.write(file, ExcludeOrIncludeData.class).excludeColumnFieldNames(excludeColumnFieldNames).sheet()
.doWrite(data());
.doWrite(data());
List<Map<Integer, String>> dataMap = EasyExcel.read(file).sheet().doReadSync();
Assertions.assertEquals(1, dataMap.size());
Map<Integer, String> record = dataMap.get(0);
Expand All @@ -189,7 +180,7 @@ private void includeIndex(File file) {
includeColumnIndexes.add(1);
includeColumnIndexes.add(2);
EasyExcel.write(file, ExcludeOrIncludeData.class).includeColumnIndexes(includeColumnIndexes).sheet()
.doWrite(data());
.doWrite(data());
List<Map<Integer, String>> dataMap = EasyExcel.read(file).sheet().doReadSync();
Assertions.assertEquals(1, dataMap.size());
Map<Integer, String> record = dataMap.get(0);
Expand All @@ -203,8 +194,10 @@ private void includeFieldName(File file) {
Set<String> includeColumnFieldNames = new HashSet<String>();
includeColumnFieldNames.add("column2");
includeColumnFieldNames.add("column3");
EasyExcel.write(file, ExcludeOrIncludeData.class).includeColumnFieldNames(includeColumnFieldNames).sheet()
.doWrite(data());
EasyExcel.write(file, ExcludeOrIncludeData.class)
.sheet()
.includeColumnFieldNames(includeColumnFieldNames)
.doWrite(data());
List<Map<Integer, String>> dataMap = EasyExcel.read(file).sheet().doReadSync();
Assertions.assertEquals(1, dataMap.size());
Map<Integer, String> record = dataMap.get(0);
Expand All @@ -220,10 +213,10 @@ private void includeFieldNameOrderIndex(File file) {
includeColumnIndexes.add(2);
includeColumnIndexes.add(0);
EasyExcel.write(file, ExcludeOrIncludeData.class)
.includeColumnIndexes(includeColumnIndexes)
.orderByIncludeColumn(true).
sheet()
.doWrite(data());
.includeColumnIndexes(includeColumnIndexes)
.orderByIncludeColumn(true).
sheet()
.doWrite(data());
List<Map<Integer, String>> dataMap = EasyExcel.read(file).sheet().doReadSync();
Assertions.assertEquals(1, dataMap.size());
Map<Integer, String> record = dataMap.get(0);
Expand All @@ -240,10 +233,10 @@ private void includeFieldNameOrder(File file) {
includeColumnFieldNames.add("column2");
includeColumnFieldNames.add("column3");
EasyExcel.write(file, ExcludeOrIncludeData.class)
.includeColumnFieldNames(includeColumnFieldNames)
.orderByIncludeColumn(true).
sheet()
.doWrite(data());
.includeColumnFieldNames(includeColumnFieldNames)
.orderByIncludeColumn(true).
sheet()
.doWrite(data());
List<Map<Integer, String>> dataMap = EasyExcel.read(file).sheet().doReadSync();
Assertions.assertEquals(1, dataMap.size());
Map<Integer, String> record = dataMap.get(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -705,19 +705,6 @@ public void noModelWrite() {
EasyExcel.write(fileName).head(head()).sheet("模板").doWrite(dataList());
}

@Test
public void sheetCol(){
String fileName = TestFileUtil.getPath() + "customCol" + System.currentTimeMillis() + ".xlsx";
try (ExcelWriter excelWriter = EasyExcel.write(fileName, DemoData.class).includeColumnFieldNames(Arrays.asList("string","date","doubleData")).build()) {
// 把sheet设置为不需要头 不然会输出sheet的头 这样看起来第一个table 就有2个头了
WriteSheet writeSheet = EasyExcel.writerSheet("模板").includeColumnFieldNames(Arrays.asList("string","date")).build();
excelWriter.write(data(), writeSheet);
writeSheet = EasyExcel.writerSheet(1,"模板1").needHead(false).build();
// 第二次写如也会创建头,然后在第一次的后面写入数据
WriteTable string = EasyExcel.writerTable().needHead(true).includeColumnFieldNames(Arrays.asList("string")).build();
excelWriter.write(data(),writeSheet,string);
}
}
private List<LongestMatchColumnWidthData> dataLong() {
List<LongestMatchColumnWidthData> list = ListUtils.newArrayList();
for (int i = 0; i < 10; i++) {
Expand Down

0 comments on commit bf2c31c

Please sign in to comment.