|
|
|
@ -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 |
|
|
|
@ -159,7 +150,7 @@ public class ExcludeOrIncludeDataTest {
|
|
|
|
|
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); |
|
|
|
@ -175,7 +166,7 @@ public class ExcludeOrIncludeDataTest {
|
|
|
|
|
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); |
|
|
|
@ -189,7 +180,7 @@ public class ExcludeOrIncludeDataTest {
|
|
|
|
|
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); |
|
|
|
@ -203,8 +194,10 @@ public class ExcludeOrIncludeDataTest {
|
|
|
|
|
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); |
|
|
|
@ -220,10 +213,10 @@ public class ExcludeOrIncludeDataTest {
|
|
|
|
|
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); |
|
|
|
@ -240,10 +233,10 @@ public class ExcludeOrIncludeDataTest {
|
|
|
|
|
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); |
|
|
|
|