forked from fanruan/easyexcel
zhuangjiaju
6 years ago
20 changed files with 483 additions and 98 deletions
@ -1,11 +0,0 @@
|
||||
package com.alibaba.excel.annotation; |
||||
|
||||
/** |
||||
* |
||||
* @author jipengfei |
||||
*/ |
||||
public enum FieldType { |
||||
|
||||
STRING, INT, LONG, DATE, BOOLEAN, DOUBLE,EMPTY; |
||||
|
||||
} |
@ -0,0 +1,35 @@
|
||||
package com.alibaba.excel.converters.booleanconverter; |
||||
|
||||
import com.alibaba.excel.converters.Converter; |
||||
import com.alibaba.excel.enums.CellDataTypeEnum; |
||||
import com.alibaba.excel.metadata.CellData; |
||||
import com.alibaba.excel.metadata.ExcelColumnProperty; |
||||
|
||||
/** |
||||
* Boolean and boolean converter |
||||
* |
||||
* @author zhuangjiaju |
||||
*/ |
||||
public class BooleanBooleanConverter implements Converter<Boolean> { |
||||
|
||||
@Override |
||||
public Class supportJavaTypeKey() { |
||||
return Boolean.class; |
||||
} |
||||
|
||||
@Override |
||||
public CellDataTypeEnum supportExcelTypeKey() { |
||||
return CellDataTypeEnum.BOOLEAN; |
||||
} |
||||
|
||||
@Override |
||||
public Boolean convertToJavaData(CellData cellData, ExcelColumnProperty columnProperty) { |
||||
return cellData.getBooleanValue(); |
||||
} |
||||
|
||||
@Override |
||||
public CellData convertToExcelData(Boolean value, ExcelColumnProperty columnProperty) { |
||||
return new CellData(value); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,44 @@
|
||||
package com.alibaba.excel.converters.booleanconverter; |
||||
|
||||
import com.alibaba.excel.converters.Converter; |
||||
import com.alibaba.excel.enums.CellDataTypeEnum; |
||||
import com.alibaba.excel.metadata.CellData; |
||||
import com.alibaba.excel.metadata.ExcelColumnProperty; |
||||
|
||||
/** |
||||
* Boolean and number converter |
||||
* |
||||
* @author zhuangjiaju |
||||
*/ |
||||
public class BooleanNumberConverter implements Converter<Boolean> { |
||||
|
||||
private static final Double ONE = 1.0; |
||||
private static final Double ZERO = 0.0; |
||||
|
||||
@Override |
||||
public Class supportJavaTypeKey() { |
||||
return Boolean.class; |
||||
} |
||||
|
||||
@Override |
||||
public CellDataTypeEnum supportExcelTypeKey() { |
||||
return CellDataTypeEnum.NUMBER; |
||||
} |
||||
|
||||
@Override |
||||
public Boolean convertToJavaData(CellData cellData, ExcelColumnProperty columnProperty) { |
||||
if (ONE.equals(cellData.getDoubleValue())) { |
||||
return Boolean.TRUE; |
||||
} |
||||
return Boolean.FALSE; |
||||
} |
||||
|
||||
@Override |
||||
public CellData convertToExcelData(Boolean value, ExcelColumnProperty columnProperty) { |
||||
if (value) { |
||||
return new CellData(ONE); |
||||
} |
||||
return new CellData(ZERO); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,35 @@
|
||||
package com.alibaba.excel.converters.booleanconverter; |
||||
|
||||
import com.alibaba.excel.converters.Converter; |
||||
import com.alibaba.excel.enums.CellDataTypeEnum; |
||||
import com.alibaba.excel.metadata.CellData; |
||||
import com.alibaba.excel.metadata.ExcelColumnProperty; |
||||
|
||||
/** |
||||
* Boolean and string converter |
||||
* |
||||
* @author zhuangjiaju |
||||
*/ |
||||
public class BooleanStringConverter implements Converter<Boolean> { |
||||
|
||||
@Override |
||||
public Class supportJavaTypeKey() { |
||||
return Boolean.class; |
||||
} |
||||
|
||||
@Override |
||||
public CellDataTypeEnum supportExcelTypeKey() { |
||||
return CellDataTypeEnum.STRING; |
||||
} |
||||
|
||||
@Override |
||||
public Boolean convertToJavaData(CellData cellData, ExcelColumnProperty columnProperty) { |
||||
return Boolean.valueOf(cellData.getStringValue()); |
||||
} |
||||
|
||||
@Override |
||||
public CellData convertToExcelData(Boolean value, ExcelColumnProperty columnProperty) { |
||||
return new CellData(value.toString()); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,43 @@
|
||||
package com.alibaba.excel.converters.byteconverter; |
||||
|
||||
import com.alibaba.excel.converters.Converter; |
||||
import com.alibaba.excel.enums.CellDataTypeEnum; |
||||
import com.alibaba.excel.metadata.CellData; |
||||
import com.alibaba.excel.metadata.ExcelColumnProperty; |
||||
|
||||
/** |
||||
* Byte and boolean converter |
||||
* |
||||
* @author zhuangjiaju |
||||
*/ |
||||
public class ByteBooleanConverter implements Converter<Byte> { |
||||
private static final Byte ONE = (byte)1; |
||||
private static final Byte ZERO = (byte)0; |
||||
|
||||
@Override |
||||
public Class supportJavaTypeKey() { |
||||
return Byte.class; |
||||
} |
||||
|
||||
@Override |
||||
public CellDataTypeEnum supportExcelTypeKey() { |
||||
return CellDataTypeEnum.BOOLEAN; |
||||
} |
||||
|
||||
@Override |
||||
public Byte convertToJavaData(CellData cellData, ExcelColumnProperty columnProperty) { |
||||
if (cellData.getBooleanValue()) { |
||||
return ONE; |
||||
} |
||||
return ZERO; |
||||
} |
||||
|
||||
@Override |
||||
public CellData convertToExcelData(Byte value, ExcelColumnProperty columnProperty) { |
||||
if (ONE.equals(value)) { |
||||
return new CellData(Boolean.TRUE); |
||||
} |
||||
return new CellData(Boolean.FALSE); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,35 @@
|
||||
package com.alibaba.excel.converters.byteconverter; |
||||
|
||||
import com.alibaba.excel.converters.Converter; |
||||
import com.alibaba.excel.enums.CellDataTypeEnum; |
||||
import com.alibaba.excel.metadata.CellData; |
||||
import com.alibaba.excel.metadata.ExcelColumnProperty; |
||||
|
||||
/** |
||||
* Byte and number converter |
||||
* |
||||
* @author zhuangjiaju |
||||
*/ |
||||
public class ByteNumberConverter implements Converter<Byte> { |
||||
|
||||
@Override |
||||
public Class supportJavaTypeKey() { |
||||
return Byte.class; |
||||
} |
||||
|
||||
@Override |
||||
public CellDataTypeEnum supportExcelTypeKey() { |
||||
return CellDataTypeEnum.NUMBER; |
||||
} |
||||
|
||||
@Override |
||||
public Byte convertToJavaData(CellData cellData, ExcelColumnProperty columnProperty) { |
||||
return cellData.getDoubleValue().byteValue(); |
||||
} |
||||
|
||||
@Override |
||||
public CellData convertToExcelData(Byte value, ExcelColumnProperty columnProperty) { |
||||
return new CellData((double)value); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,35 @@
|
||||
package com.alibaba.excel.converters.byteconverter; |
||||
|
||||
import com.alibaba.excel.converters.Converter; |
||||
import com.alibaba.excel.enums.CellDataTypeEnum; |
||||
import com.alibaba.excel.metadata.CellData; |
||||
import com.alibaba.excel.metadata.ExcelColumnProperty; |
||||
|
||||
/** |
||||
* Byte and string converter |
||||
* |
||||
* @author zhuangjiaju |
||||
*/ |
||||
public class ByteStringConverter implements Converter<Byte> { |
||||
|
||||
@Override |
||||
public Class supportJavaTypeKey() { |
||||
return Byte.class; |
||||
} |
||||
|
||||
@Override |
||||
public CellDataTypeEnum supportExcelTypeKey() { |
||||
return CellDataTypeEnum.STRING; |
||||
} |
||||
|
||||
@Override |
||||
public Byte convertToJavaData(CellData cellData, ExcelColumnProperty columnProperty) { |
||||
return Byte.valueOf(cellData.getStringValue()); |
||||
} |
||||
|
||||
@Override |
||||
public CellData convertToExcelData(Byte value, ExcelColumnProperty columnProperty) { |
||||
return new CellData(value.toString()); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,43 @@
|
||||
package com.alibaba.excel.converters.doubleconverter; |
||||
|
||||
import com.alibaba.excel.converters.Converter; |
||||
import com.alibaba.excel.enums.CellDataTypeEnum; |
||||
import com.alibaba.excel.metadata.CellData; |
||||
import com.alibaba.excel.metadata.ExcelColumnProperty; |
||||
|
||||
/** |
||||
* Byte and boolean converter |
||||
* |
||||
* @author zhuangjiaju |
||||
*/ |
||||
public class ByteBooleanConverter implements Converter<Byte> { |
||||
private static final Byte ONE = (byte)1; |
||||
private static final Byte ZERO = (byte)0; |
||||
|
||||
@Override |
||||
public Class supportJavaTypeKey() { |
||||
return Byte.class; |
||||
} |
||||
|
||||
@Override |
||||
public CellDataTypeEnum supportExcelTypeKey() { |
||||
return CellDataTypeEnum.BOOLEAN; |
||||
} |
||||
|
||||
@Override |
||||
public Byte convertToJavaData(CellData cellData, ExcelColumnProperty columnProperty) { |
||||
if (cellData.getBooleanValue()) { |
||||
return ONE; |
||||
} |
||||
return ZERO; |
||||
} |
||||
|
||||
@Override |
||||
public CellData convertToExcelData(Byte value, ExcelColumnProperty columnProperty) { |
||||
if (ONE.equals(value)) { |
||||
return new CellData(Boolean.TRUE); |
||||
} |
||||
return new CellData(Boolean.FALSE); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,35 @@
|
||||
package com.alibaba.excel.converters.doubleconverter; |
||||
|
||||
import com.alibaba.excel.converters.Converter; |
||||
import com.alibaba.excel.enums.CellDataTypeEnum; |
||||
import com.alibaba.excel.metadata.CellData; |
||||
import com.alibaba.excel.metadata.ExcelColumnProperty; |
||||
|
||||
/** |
||||
* Byte and number converter |
||||
* |
||||
* @author zhuangjiaju |
||||
*/ |
||||
public class ByteNumberConverter implements Converter<Byte> { |
||||
|
||||
@Override |
||||
public Class supportJavaTypeKey() { |
||||
return Byte.class; |
||||
} |
||||
|
||||
@Override |
||||
public CellDataTypeEnum supportExcelTypeKey() { |
||||
return CellDataTypeEnum.NUMBER; |
||||
} |
||||
|
||||
@Override |
||||
public Byte convertToJavaData(CellData cellData, ExcelColumnProperty columnProperty) { |
||||
return cellData.getDoubleValue().byteValue(); |
||||
} |
||||
|
||||
@Override |
||||
public CellData convertToExcelData(Byte value, ExcelColumnProperty columnProperty) { |
||||
return new CellData((double)value); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,34 @@
|
||||
package com.alibaba.excel.converters.doubleconverter; |
||||
|
||||
import com.alibaba.excel.converters.Converter; |
||||
import com.alibaba.excel.enums.CellDataTypeEnum; |
||||
import com.alibaba.excel.metadata.CellData; |
||||
import com.alibaba.excel.metadata.ExcelColumnProperty; |
||||
|
||||
/** |
||||
* Double and string converter |
||||
* |
||||
* @author zhuangjiaju |
||||
*/ |
||||
public class DoubleStringConverter implements Converter<Double> { |
||||
|
||||
@Override |
||||
public Class supportJavaTypeKey() { |
||||
return Double.class; |
||||
} |
||||
|
||||
@Override |
||||
public CellDataTypeEnum supportExcelTypeKey() { |
||||
return CellDataTypeEnum.STRING; |
||||
} |
||||
|
||||
@Override |
||||
public Double convertToJavaData(CellData cellData, ExcelColumnProperty columnProperty) { |
||||
return Double.valueOf(cellData.getStringValue()); |
||||
} |
||||
|
||||
@Override |
||||
public CellData convertToExcelData(Double value, ExcelColumnProperty columnProperty) { |
||||
return new CellData(value.toString()); |
||||
} |
||||
} |
@ -1,73 +0,0 @@
|
||||
package com.alibaba.excel.util; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
import java.util.Stack; |
||||
|
||||
import com.alibaba.excel.metadata.IndexValue; |
||||
|
||||
/** |
||||
* 去除空Cell |
||||
* @author jipengfei |
||||
*/ |
||||
public class IndexValueConverter { |
||||
public static List<String> converter(List<IndexValue> i_list) { |
||||
|
||||
List<String> tem = new ArrayList<String>(); |
||||
|
||||
char[] start = {'@'}; |
||||
int j = 0; |
||||
for (; j < i_list.size(); j++) { |
||||
IndexValue currentIndexValue = i_list.get(j); |
||||
char[] currentIndex = currentIndexValue.getV_index().replaceAll("[0-9]", "").toCharArray(); |
||||
if (j > 0) { |
||||
start = i_list.get(j - 1).getV_index().replaceAll("[0-9]", "").toCharArray(); |
||||
} |
||||
int deep = subtraction26(currentIndex, start); |
||||
int k = 0; |
||||
for (; k < deep - 1; k++) { |
||||
tem.add(null); |
||||
} |
||||
tem.add(currentIndexValue.getV_value()); |
||||
} |
||||
return tem; |
||||
} |
||||
|
||||
private static int subtraction26(char[] currentIndex, char[] beforeIndex) { |
||||
int result = 0; |
||||
|
||||
Stack<Character> currentStack = new Stack<Character>(); |
||||
Stack<Character> berforStack = new Stack<Character>(); |
||||
|
||||
for (int i = 0; i < currentIndex.length; i++) { |
||||
currentStack.push(currentIndex[i]); |
||||
} |
||||
for (int i = 0; i < beforeIndex.length; i++) { |
||||
berforStack.push(beforeIndex[i]); |
||||
} |
||||
int i = 0; |
||||
char beforechar = '@'; |
||||
while (!currentStack.isEmpty()) { |
||||
char currentChar = currentStack.pop(); |
||||
if (!berforStack.isEmpty()) { |
||||
beforechar = berforStack.pop(); |
||||
} |
||||
int n = currentChar - beforechar; |
||||
if(n<0){ |
||||
n = n+26; |
||||
if(!currentStack.isEmpty()){ |
||||
char borrow = currentStack.pop(); |
||||
char newBorrow =(char)(borrow -1); |
||||
currentStack.push(newBorrow); |
||||
} |
||||
} |
||||
|
||||
|
||||
result += n * Math.pow(26, i); |
||||
i++; |
||||
beforechar='@'; |
||||
} |
||||
|
||||
return result; |
||||
} |
||||
} |
@ -1,10 +0,0 @@
|
||||
package com.alibaba.excel.util; |
||||
|
||||
import org.apache.poi.ss.usermodel.Workbook; |
||||
|
||||
public class RowUtil { |
||||
|
||||
//public static int computeNextRow(Workbook workbook,int startRow){
|
||||
//
|
||||
//}
|
||||
} |
@ -0,0 +1,29 @@
|
||||
package com.alibaba.easyexcel.test.wirte.order; |
||||
|
||||
import com.alibaba.excel.annotation.ExcelProperty; |
||||
|
||||
/** |
||||
* @author zhuangjiaju |
||||
*/ |
||||
public class OrderData { |
||||
@ExcelProperty(value = "第一个", index = 1) |
||||
private String index1; |
||||
@ExcelProperty(value = "第10个", index = 10) |
||||
private String index10; |
||||
|
||||
public String getIndex1() { |
||||
return index1; |
||||
} |
||||
|
||||
public void setIndex1(String index1) { |
||||
this.index1 = index1; |
||||
} |
||||
|
||||
public String getIndex10() { |
||||
return index10; |
||||
} |
||||
|
||||
public void setIndex10(String index10) { |
||||
this.index10 = index10; |
||||
} |
||||
} |
@ -0,0 +1,39 @@
|
||||
package com.alibaba.easyexcel.test.wirte.order; |
||||
|
||||
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.metadata.Sheet; |
||||
|
||||
/** |
||||
* Order data test |
||||
* |
||||
* @author zhuangjiaju |
||||
*/ |
||||
public class OrderData07Test { |
||||
|
||||
@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; |
||||
} |
||||
} |
Loading…
Reference in new issue