forked from github/easyexcel
zhuangjiaju
5 years ago
56 changed files with 1040 additions and 730 deletions
@ -1,52 +0,0 @@
|
||||
package com.alibaba.excel.converters; |
||||
|
||||
import com.alibaba.excel.enums.CellDataTypeEnum; |
||||
|
||||
/** |
||||
* Converter unique key |
||||
* |
||||
* @author zhuangjiaju |
||||
*/ |
||||
public class ConverterKey { |
||||
|
||||
private Class javaTypeKey; |
||||
private CellDataTypeEnum excelTypeKey; |
||||
|
||||
public ConverterKey(Class javaTypeKey, CellDataTypeEnum excelTypeKey) { |
||||
if (javaTypeKey == null || excelTypeKey == null) { |
||||
throw new IllegalArgumentException("All parameters can not be null"); |
||||
} |
||||
this.javaTypeKey = javaTypeKey; |
||||
this.excelTypeKey = excelTypeKey; |
||||
} |
||||
|
||||
public static ConverterKey buildConverterKey(Class javaTypeKey, CellDataTypeEnum excelTypeKey) { |
||||
return new ConverterKey(javaTypeKey, excelTypeKey); |
||||
} |
||||
|
||||
public static ConverterKey buildConverterKey(Converter converter) { |
||||
return buildConverterKey(converter.supportJavaTypeKey(), converter.supportExcelTypeKey()); |
||||
} |
||||
|
||||
@Override |
||||
public boolean equals(Object o) { |
||||
if (this == o) { |
||||
return true; |
||||
} |
||||
if (o == null || getClass() != o.getClass()) { |
||||
return false; |
||||
} |
||||
ConverterKey that = (ConverterKey)o; |
||||
if (javaTypeKey != null ? !javaTypeKey.equals(that.javaTypeKey) : that.javaTypeKey != null) { |
||||
return false; |
||||
} |
||||
return excelTypeKey == that.excelTypeKey; |
||||
} |
||||
|
||||
@Override |
||||
public int hashCode() { |
||||
int result = javaTypeKey != null ? javaTypeKey.hashCode() : 0; |
||||
result = 31 * result + (excelTypeKey != null ? excelTypeKey.hashCode() : 0); |
||||
return result; |
||||
} |
||||
} |
@ -0,0 +1,18 @@
|
||||
package com.alibaba.excel.converters; |
||||
|
||||
import com.alibaba.excel.enums.CellDataTypeEnum; |
||||
|
||||
/** |
||||
* Converter unique key |
||||
* |
||||
* @author zhuangjiaju |
||||
*/ |
||||
public class ConverterKeyBuild { |
||||
public static String buildKey(Class clazz) { |
||||
return clazz.getName(); |
||||
} |
||||
|
||||
public static String buildKey(Class clazz, CellDataTypeEnum cellDataTypeEnum) { |
||||
return clazz.getName() + "-" + cellDataTypeEnum.toString(); |
||||
} |
||||
} |
@ -0,0 +1,60 @@
|
||||
package com.alibaba.easyexcel.test.core.large; |
||||
|
||||
import lombok.Data; |
||||
|
||||
/** |
||||
* @author zhuangjiaju |
||||
*/ |
||||
@Data |
||||
public class LargeData { |
||||
|
||||
private String str1; |
||||
|
||||
private String str2; |
||||
|
||||
private String str3; |
||||
|
||||
private String str4; |
||||
|
||||
private String str5; |
||||
|
||||
private String str6; |
||||
|
||||
private String str7; |
||||
|
||||
private String str8; |
||||
|
||||
private String str9; |
||||
|
||||
private String str10; |
||||
|
||||
private String str11; |
||||
|
||||
private String str12; |
||||
|
||||
private String str13; |
||||
|
||||
private String str14; |
||||
|
||||
private String str15; |
||||
|
||||
private String str16; |
||||
|
||||
private String str17; |
||||
|
||||
private String str18; |
||||
|
||||
private String str19; |
||||
|
||||
private String str20; |
||||
|
||||
private String str21; |
||||
|
||||
private String str22; |
||||
|
||||
private String str23; |
||||
|
||||
private String str24; |
||||
|
||||
private String str25; |
||||
} |
@ -0,0 +1,34 @@
|
||||
package com.alibaba.easyexcel.test.core.large; |
||||
|
||||
import org.junit.Assert; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
|
||||
import com.alibaba.excel.context.AnalysisContext; |
||||
import com.alibaba.excel.event.AnalysisEventListener; |
||||
import com.alibaba.fastjson.JSON; |
||||
|
||||
/** |
||||
* @author zhuangjiaju |
||||
*/ |
||||
public class LargeDataListener extends AnalysisEventListener<LargeData> { |
||||
private static final Logger LOGGER = LoggerFactory.getLogger(LargeDataListener.class); |
||||
private int count = 0; |
||||
|
||||
@Override |
||||
public void invoke(LargeData data, AnalysisContext context) { |
||||
if (count == 0) { |
||||
LOGGER.info("First row:{}", JSON.toJSONString(data)); |
||||
} |
||||
count++; |
||||
if (count % 100000 == 0) { |
||||
LOGGER.info("Already read:{}", count); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public void doAfterAllAnalysed(AnalysisContext context) { |
||||
LOGGER.info("Large row count:{}", count); |
||||
Assert.assertEquals(count, 464509); |
||||
} |
||||
} |
@ -0,0 +1,27 @@
|
||||
package com.alibaba.easyexcel.test.core.large; |
||||
|
||||
import java.io.File; |
||||
|
||||
import org.junit.Test; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
|
||||
import com.alibaba.easyexcel.test.util.TestFileUtil; |
||||
import com.alibaba.excel.EasyExcelFactory; |
||||
|
||||
/** |
||||
* Large data test |
||||
* |
||||
* @author zhuangjiaju |
||||
*/ |
||||
public class LargeDataTest { |
||||
private static final Logger LOGGER = LoggerFactory.getLogger(LargeDataTest.class); |
||||
|
||||
@Test |
||||
public void read() { |
||||
long start = System.currentTimeMillis(); |
||||
EasyExcelFactory.read(TestFileUtil.getPath() + "large" + File.separator + "large07.xlsx", LargeData.class, |
||||
new LargeDataListener()).headRowNumber(2).sheet().doRead().finish(); |
||||
LOGGER.info("Large data total time spent:{}", System.currentTimeMillis() - start); |
||||
} |
||||
} |
@ -0,0 +1,36 @@
|
||||
package com.alibaba.easyexcel.test.core.nohead; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
import org.junit.Test; |
||||
|
||||
import com.alibaba.easyexcel.test.core.order.OrderData; |
||||
|
||||
/** |
||||
* Order data test |
||||
* |
||||
* @author zhuangjiaju |
||||
*/ |
||||
public class NoHeadData07Test { |
||||
|
||||
@Test |
||||
public void simple() { |
||||
// ExcelWriter writer = EasyExcelFactory.writerBuilder().outputFile(TestFileUtil.createNewWriteFile("order07.xlsx"))
|
||||
// .head(OrderData.class).build();
|
||||
// Sheet sheet = EasyExcelFactory.writerSheetBuilder().sheetNo(0).sheetName("order").build();
|
||||
// writer.write(createData(10000 * 100), sheet);
|
||||
// writer.finish();
|
||||
} |
||||
|
||||
private List<OrderData> createData(int count) { |
||||
List<OrderData> list = new ArrayList<OrderData>(); |
||||
for (int i = 0; i < count; i++) { |
||||
OrderData orderData = new OrderData(); |
||||
orderData.setIndex1("排序1:" + i); |
||||
orderData.setIndex10("排序10:" + i); |
||||
list.add(orderData); |
||||
} |
||||
return list; |
||||
} |
||||
} |
@ -1,4 +1,4 @@
|
||||
package com.alibaba.easyexcel.test.wirte.order; |
||||
package com.alibaba.easyexcel.test.core.order; |
||||
|
||||
import com.alibaba.excel.annotation.ExcelProperty; |
||||
|
@ -1,4 +1,4 @@
|
||||
package com.alibaba.easyexcel.test.read.simple; |
||||
package com.alibaba.easyexcel.test.core.simple; |
||||
|
||||
import com.alibaba.excel.annotation.ExcelProperty; |
||||
|
@ -0,0 +1,22 @@
|
||||
package com.alibaba.easyexcel.test.core.simple; |
||||
|
||||
import java.io.File; |
||||
|
||||
import org.junit.Test; |
||||
|
||||
import com.alibaba.easyexcel.test.util.TestFileUtil; |
||||
import com.alibaba.excel.EasyExcelFactory; |
||||
|
||||
/** |
||||
* Simple data test |
||||
* |
||||
* @author zhuangjiaju |
||||
*/ |
||||
public class SimpleDataTest { |
||||
|
||||
@Test |
||||
public void read() { |
||||
EasyExcelFactory.read(TestFileUtil.getPath() + "simple" + File.separator + "simple07Test.xlsx", |
||||
SimpleData.class, new SimpleDataListener()).sheet().doRead().finish(); |
||||
} |
||||
} |
@ -1,40 +0,0 @@
|
||||
package com.alibaba.easyexcel.test.ehcache; |
||||
|
||||
import java.io.File; |
||||
|
||||
import org.ehcache.Cache; |
||||
import org.ehcache.PersistentCacheManager; |
||||
import org.ehcache.config.builders.CacheConfigurationBuilder; |
||||
import org.ehcache.config.builders.CacheManagerBuilder; |
||||
import org.ehcache.config.builders.ResourcePoolsBuilder; |
||||
import org.ehcache.config.units.MemoryUnit; |
||||
import org.junit.Ignore; |
||||
import org.junit.Test; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
|
||||
import com.alibaba.excel.util.POITempFile; |
||||
|
||||
/** |
||||
* @author zhuangjiaju |
||||
*/ |
||||
@Ignore |
||||
public class EncacheTest { |
||||
private static final Logger LOGGER = LoggerFactory.getLogger(EncacheTest.class); |
||||
|
||||
@Test |
||||
public void cache() { |
||||
File file = POITempFile.createCacheTmpFile(); |
||||
PersistentCacheManager persistentCacheManager = |
||||
CacheManagerBuilder.newCacheManagerBuilder().with(CacheManagerBuilder.persistence(file)) |
||||
.withCache("cache", CacheConfigurationBuilder.newCacheConfigurationBuilder(Integer.class, String.class, |
||||
ResourcePoolsBuilder.newResourcePoolsBuilder().disk(10, MemoryUnit.GB))) |
||||
.build(true); |
||||
Cache<Integer, String> cache = persistentCacheManager.getCache("cache", Integer.class, String.class); |
||||
cache.put(1, "测试1"); |
||||
LOGGER.info("cache:{}", cache.get(1)); |
||||
persistentCacheManager.close(); |
||||
LOGGER.info("close"); |
||||
POITempFile.delete(file); |
||||
} |
||||
} |
@ -1,189 +0,0 @@
|
||||
package com.alibaba.easyexcel.test.read; |
||||
|
||||
import java.io.IOException; |
||||
import java.io.InputStream; |
||||
import java.util.List; |
||||
|
||||
import org.junit.Test; |
||||
|
||||
import com.alibaba.easyexcel.test.listen.ExcelListener; |
||||
import com.alibaba.easyexcel.test.model.ReadModel; |
||||
import com.alibaba.easyexcel.test.model.ReadModel2; |
||||
import com.alibaba.easyexcel.test.util.FileUtil; |
||||
import com.alibaba.excel.EasyExcelFactory; |
||||
import com.alibaba.excel.ExcelReader; |
||||
import com.alibaba.excel.write.metadata.Sheet; |
||||
|
||||
public class ReadTest { |
||||
|
||||
|
||||
/** |
||||
* 07版本excel读数据量少于1千行数据,内部采用回调方法. |
||||
* |
||||
* @throws IOException 简单抛出异常,真实环境需要catch异常,同时在finally中关闭流 |
||||
*/ |
||||
@Test |
||||
public void simpleReadListStringV2007() throws IOException { |
||||
InputStream inputStream = FileUtil.getResourcesFileInputStream("2007.xlsx"); |
||||
List<Object> data = EasyExcelFactory.read(inputStream, new Sheet(1, 0)); |
||||
inputStream.close(); |
||||
print(data); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 07版本excel读数据量少于1千行数据自动转成javamodel,内部采用回调方法. |
||||
* |
||||
* @throws IOException 简单抛出异常,真实环境需要catch异常,同时在finally中关闭流 |
||||
*/ |
||||
@Test |
||||
public void simpleReadJavaModelV2007() throws IOException { |
||||
InputStream inputStream = FileUtil.getResourcesFileInputStream("2007.xlsx"); |
||||
List<Object> data = EasyExcelFactory.read(inputStream, new Sheet(2, 1, ReadModel.class)); |
||||
inputStream.close(); |
||||
print(data); |
||||
} |
||||
|
||||
/** |
||||
* 07版本excel读数据量大于1千行,内部采用回调方法. |
||||
* |
||||
* @throws IOException 简单抛出异常,真实环境需要catch异常,同时在finally中关闭流 |
||||
*/ |
||||
@Test |
||||
public void saxReadListStringV2007() throws IOException { |
||||
InputStream inputStream = FileUtil.getResourcesFileInputStream("2007.xlsx"); |
||||
ExcelListener excelListener = new ExcelListener(); |
||||
EasyExcelFactory.readBySax(inputStream, new Sheet(1, 1), excelListener); |
||||
inputStream.close(); |
||||
|
||||
} |
||||
/** |
||||
* 07版本excel读数据量大于1千行,内部采用回调方法. |
||||
* |
||||
* @throws IOException 简单抛出异常,真实环境需要catch异常,同时在finally中关闭流 |
||||
*/ |
||||
@Test |
||||
public void saxReadJavaModelV2007() throws IOException { |
||||
InputStream inputStream = FileUtil.getResourcesFileInputStream("2007.xlsx"); |
||||
ExcelListener excelListener = new ExcelListener(); |
||||
EasyExcelFactory.readBySax(inputStream, new Sheet(2, 1, ReadModel.class), excelListener); |
||||
inputStream.close(); |
||||
} |
||||
|
||||
/** |
||||
* 07版本excel读取sheet |
||||
* |
||||
* @throws IOException 简单抛出异常,真实环境需要catch异常,同时在finally中关闭流 |
||||
*/ |
||||
@Test |
||||
public void saxReadSheetsV2007() throws IOException { |
||||
InputStream inputStream = FileUtil.getResourcesFileInputStream("2007.xlsx"); |
||||
ExcelListener excelListener = new ExcelListener(); |
||||
ExcelReader excelReader = EasyExcelFactory.getReader(inputStream,excelListener); |
||||
List<Sheet> sheets = excelReader.getSheets(); |
||||
System.out.println("llll****"+sheets); |
||||
System.out.println(); |
||||
for (Sheet sheet:sheets) { |
||||
if(sheet.getSheetNo() ==1) { |
||||
excelReader.read(sheet); |
||||
}else if(sheet.getSheetNo() ==2){ |
||||
sheet.setHeadLineMun(1); |
||||
sheet.setClazz(ReadModel.class); |
||||
excelReader.read(sheet); |
||||
}else if(sheet.getSheetNo() ==3){ |
||||
sheet.setHeadLineMun(1); |
||||
sheet.setClazz(ReadModel2.class); |
||||
excelReader.read(sheet); |
||||
} |
||||
} |
||||
inputStream.close(); |
||||
} |
||||
|
||||
|
||||
|
||||
/** |
||||
* 03版本excel读数据量少于1千行数据,内部采用回调方法. |
||||
* |
||||
* @throws IOException 简单抛出异常,真实环境需要catch异常,同时在finally中关闭流 |
||||
*/ |
||||
@Test |
||||
public void simpleReadListStringV2003() throws IOException { |
||||
InputStream inputStream = FileUtil.getResourcesFileInputStream("2003.xls"); |
||||
List<Object> data = EasyExcelFactory.read(inputStream, new Sheet(1, 0)); |
||||
inputStream.close(); |
||||
print(data); |
||||
} |
||||
|
||||
/** |
||||
* 03版本excel读数据量少于1千行数据转成javamodel,内部采用回调方法. |
||||
* |
||||
* @throws IOException 简单抛出异常,真实环境需要catch异常,同时在finally中关闭流 |
||||
*/ |
||||
@Test |
||||
public void simpleReadJavaModelV2003() throws IOException { |
||||
InputStream inputStream = FileUtil.getResourcesFileInputStream("2003.xls"); |
||||
List<Object> data = EasyExcelFactory.read(inputStream, new Sheet(2, 1, ReadModel.class)); |
||||
inputStream.close(); |
||||
print(data); |
||||
} |
||||
|
||||
/** |
||||
* 03版本excel读数据量大于1千行数据,内部采用回调方法. |
||||
* |
||||
* @throws IOException 简单抛出异常,真实环境需要catch异常,同时在finally中关闭流 |
||||
*/ |
||||
@Test |
||||
public void saxReadListStringV2003() throws IOException { |
||||
InputStream inputStream = FileUtil.getResourcesFileInputStream("2003.xls"); |
||||
ExcelListener excelListener = new ExcelListener(); |
||||
EasyExcelFactory.readBySax(inputStream, new Sheet(2, 1), excelListener); |
||||
inputStream.close(); |
||||
} |
||||
|
||||
/** |
||||
* 03版本excel读数据量大于1千行数据转成javamodel,内部采用回调方法. |
||||
* |
||||
* @throws IOException 简单抛出异常,真实环境需要catch异常,同时在finally中关闭流 |
||||
*/ |
||||
@Test |
||||
public void saxReadJavaModelV2003() throws IOException { |
||||
InputStream inputStream = FileUtil.getResourcesFileInputStream("2003.xls"); |
||||
ExcelListener excelListener = new ExcelListener(); |
||||
EasyExcelFactory.readBySax(inputStream, new Sheet(2, 1, ReadModel.class), excelListener); |
||||
inputStream.close(); |
||||
} |
||||
|
||||
/** |
||||
* 00版本excel读取sheet |
||||
* |
||||
* @throws IOException 简单抛出异常,真实环境需要catch异常,同时在finally中关闭流 |
||||
*/ |
||||
@Test |
||||
public void saxReadSheetsV2003() throws IOException { |
||||
InputStream inputStream = FileUtil.getResourcesFileInputStream("2003.xls"); |
||||
ExcelListener excelListener = new ExcelListener(); |
||||
ExcelReader excelReader = EasyExcelFactory.getReader(inputStream, excelListener); |
||||
List<Sheet> sheets = excelReader.getSheets(); |
||||
System.out.println(); |
||||
for (Sheet sheet : sheets) { |
||||
if (sheet.getSheetNo() == 1) { |
||||
excelReader.read(sheet); |
||||
} else { |
||||
sheet.setHeadLineMun(2); |
||||
sheet.setClazz(ReadModel.class); |
||||
excelReader.read(sheet); |
||||
} |
||||
} |
||||
inputStream.close(); |
||||
} |
||||
|
||||
|
||||
public void print(List<Object> datas){ |
||||
int i=0; |
||||
for (Object ob:datas) { |
||||
System.out.println(i++); |
||||
System.out.println(ob); |
||||
} |
||||
} |
||||
|
||||
} |
@ -1,57 +0,0 @@
|
||||
package com.alibaba.easyexcel.test.read.large; |
||||
|
||||
import java.io.InputStream; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
import org.junit.Test; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
|
||||
import com.alibaba.easyexcel.test.util.FileUtil; |
||||
import com.alibaba.excel.EasyExcelFactory; |
||||
import com.alibaba.excel.ExcelReader; |
||||
import com.alibaba.excel.context.AnalysisContext; |
||||
import com.alibaba.excel.event.AnalysisEventListener; |
||||
import com.alibaba.excel.metadata.Sheet; |
||||
|
||||
/** |
||||
* Simple data test |
||||
* |
||||
* @author zhuangjiaju |
||||
*/ |
||||
public class LargeData07Test { |
||||
private static final Logger LOGGER = LoggerFactory.getLogger(LargeData07Test.class); |
||||
|
||||
@Test |
||||
public void large() throws Exception { |
||||
EasyExcelFactory.read().registerReadListener(listener).file(in).sheet().sheetNo(sheetNo).doRead().finish(); |
||||
|
||||
//
|
||||
// public static List<Object> read(InputStream in, Sheet sheet) {
|
||||
// final List<Object> rows = new ArrayList<Object>();
|
||||
// new ExcelReader(in, null, new AnalysisEventListener<Object>() {
|
||||
// @Override
|
||||
// public void invoke(Object object, AnalysisContext context) {
|
||||
// rows.add(object);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void doAfterAllAnalysed(AnalysisContext context) {}
|
||||
// }, false).read(sheet);
|
||||
// return rows;
|
||||
// }
|
||||
// LOGGER.info("start");
|
||||
// long start = System.currentTimeMillis();
|
||||
// // InputStream inputStream = FileUtil.readFile("large/large07.xlsx");
|
||||
// ExcelReader excelReader = EasyExcelFactory.getReader(null, new LargeDataListener());
|
||||
// excelReader.read(new Sheet(1, 1));
|
||||
// // inputStream.close();
|
||||
// LOGGER.info("time:{}", System.currentTimeMillis() - start);
|
||||
} |
||||
|
||||
@Test |
||||
public void hello() throws Exception { |
||||
LOGGER.info("start"); |
||||
} |
||||
} |
@ -1,29 +0,0 @@
|
||||
package com.alibaba.easyexcel.test.read.large; |
||||
|
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
|
||||
import com.alibaba.easyexcel.test.read.simple.SimpleDataListener; |
||||
import com.alibaba.excel.context.AnalysisContext; |
||||
import com.alibaba.excel.event.AnalysisEventListener; |
||||
import com.alibaba.fastjson.JSON; |
||||
|
||||
/** |
||||
* @author zhuangjiaju |
||||
*/ |
||||
public class LargeDataListener extends AnalysisEventListener<Object> { |
||||
private static final Logger LOGGER = LoggerFactory.getLogger(SimpleDataListener.class); |
||||
private int count = 0; |
||||
|
||||
@Override |
||||
public void invoke(Object object, AnalysisContext context) { |
||||
count++; |
||||
if (count % 100000 == 0) { |
||||
LOGGER.info("row:{} ,mem:{},data:{}", count, Runtime.getRuntime().totalMemory(), JSON.toJSONString(object)); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public void doAfterAllAnalysed(AnalysisContext context) {} |
||||
|
||||
} |
@ -1,26 +0,0 @@
|
||||
package com.alibaba.easyexcel.test.read.simple; |
||||
|
||||
import java.io.InputStream; |
||||
|
||||
import org.junit.Test; |
||||
|
||||
import com.alibaba.easyexcel.test.util.FileUtil; |
||||
import com.alibaba.excel.EasyExcelFactory; |
||||
import com.alibaba.excel.ExcelReader; |
||||
import com.alibaba.excel.write.metadata.Sheet; |
||||
|
||||
/** |
||||
* Simple data test |
||||
* |
||||
* @author zhuangjiaju |
||||
*/ |
||||
public class SimpleData07Test { |
||||
|
||||
@Test |
||||
public void simple() throws Exception { |
||||
InputStream inputStream = FileUtil.readFile("simple/simple07.xlsx"); |
||||
ExcelReader excelReader = EasyExcelFactory.getReader(inputStream, new SimpleDataListener()); |
||||
excelReader.read(new Sheet(1, 1), SimpleData.class); |
||||
inputStream.close(); |
||||
} |
||||
} |
@ -1,13 +0,0 @@
|
||||
package com.alibaba.easyexcel.test.wirte; |
||||
|
||||
import java.io.IOException; |
||||
|
||||
import org.junit.Test; |
||||
|
||||
public class WriteTest { |
||||
|
||||
@Test |
||||
public void writeV2007() throws IOException { |
||||
|
||||
} |
||||
} |
@ -1,40 +0,0 @@
|
||||
package com.alibaba.easyexcel.test.wirte.nohead; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
import org.junit.Test; |
||||
|
||||
import com.alibaba.easyexcel.test.util.FileUtil; |
||||
import com.alibaba.easyexcel.test.wirte.order.OrderData; |
||||
import com.alibaba.excel.EasyExcelFactory; |
||||
import com.alibaba.excel.ExcelWriter; |
||||
import com.alibaba.excel.write.metadata.Sheet; |
||||
|
||||
/** |
||||
* Order data test |
||||
* |
||||
* @author zhuangjiaju |
||||
*/ |
||||
public class NoHeadData07Test { |
||||
|
||||
@Test |
||||
public void simple() { |
||||
ExcelWriter writer = EasyExcelFactory.writerBuilder().outputFile(FileUtil.createNewWriteFile("order07.xlsx")) |
||||
.head(OrderData.class).build(); |
||||
Sheet sheet = EasyExcelFactory.writerSheetBuilder().sheetNo(0).sheetName("order").build(); |
||||
writer.write(createData(10000 * 100), sheet); |
||||
writer.finish(); |
||||
} |
||||
|
||||
private List<OrderData> createData(int count) { |
||||
List<OrderData> list = new ArrayList<OrderData>(); |
||||
for (int i = 0; i < count; i++) { |
||||
OrderData orderData = new OrderData(); |
||||
orderData.setIndex1("排序1:" + i); |
||||
orderData.setIndex10("排序10:" + i); |
||||
list.add(orderData); |
||||
} |
||||
return list; |
||||
} |
||||
} |
@ -1,16 +0,0 @@
|
||||
package com.alibaba.easyexcel.test.wirte.simple; |
||||
|
||||
import com.alibaba.excel.annotation.ExcelProperty; |
||||
|
||||
import lombok.Data; |
||||
|
||||
/** |
||||
* @author zhuangjiaju |
||||
*/ |
||||
@Data |
||||
public class SimpleData { |
||||
@ExcelProperty("字符串1") |
||||
private String string1; |
||||
@ExcelProperty("字符串2") |
||||
private String string2; |
||||
} |
@ -1,17 +0,0 @@
|
||||
package com.alibaba.easyexcel.test.wirte.simple; |
||||
|
||||
import org.junit.Test; |
||||
|
||||
/** |
||||
* Simple data test |
||||
* |
||||
* @author zhuangjiaju |
||||
*/ |
||||
public class SimpleData03Test { |
||||
|
||||
@Test |
||||
public void simple07() { |
||||
|
||||
} |
||||
|
||||
} |
@ -1,49 +0,0 @@
|
||||
package com.alibaba.easyexcel.test.wirte.simple; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
import org.junit.Test; |
||||
|
||||
import com.alibaba.easyexcel.test.util.FileUtil; |
||||
import com.alibaba.excel.EasyExcelFactory; |
||||
import com.alibaba.excel.ExcelWriter; |
||||
import com.alibaba.excel.write.metadata.Sheet; |
||||
|
||||
/** |
||||
* Simple data test |
||||
* |
||||
* @author zhuangjiaju |
||||
*/ |
||||
public class SimpleData07Test { |
||||
|
||||
@Test |
||||
public void simple() { |
||||
ExcelWriter writer = EasyExcelFactory.writerBuilder().outputFile(FileUtil.createNewWriteFile("simple07.xlsx")) |
||||
.head(SimpleData.class).build(); |
||||
Sheet sheet = EasyExcelFactory.writerSheetBuilder().sheetNo(0).sheetName("simple").build(); |
||||
writer.write(createData(10), sheet); |
||||
writer.finish(); |
||||
} |
||||
|
||||
@Test |
||||
public void repeatWrite() { |
||||
ExcelWriter writer = EasyExcelFactory.writerBuilder() |
||||
.outputFile(FileUtil.createNewWriteFile("repeatWrite07.xlsx")).head(SimpleData.class).build(); |
||||
Sheet sheet = EasyExcelFactory.writerSheetBuilder().sheetNo(0).sheetName("simple").build(); |
||||
writer.write(createData(10), sheet); |
||||
writer.write(createData(10), sheet); |
||||
writer.finish(); |
||||
} |
||||
|
||||
private List<SimpleData> createData(int count) { |
||||
List<SimpleData> list = new ArrayList<SimpleData>(); |
||||
for (int i = 0; i < count; i++) { |
||||
SimpleData simpleData = new SimpleData(); |
||||
simpleData.setString1("一号字" + i); |
||||
simpleData.setString2("二号字" + i); |
||||
list.add(simpleData); |
||||
} |
||||
return list; |
||||
} |
||||
} |
Loading…
Reference in new issue