Browse Source

阿里內部最新版本开源,为了稳定性07版本解析修改为底层使用POI解析。

developing
jipengfei.jpf 6 years ago
parent
commit
c598a70424
  1. 27
      src/main/java/com/alibaba/excel/ExcelReader.java
  2. 1
      src/main/java/com/alibaba/excel/analysis/v07/XlsxRowHandler.java
  3. 1
      src/main/java/com/alibaba/excel/analysis/v07/XlsxSaxAnalyser.java
  4. 1
      src/main/java/com/alibaba/excel/annotation/ExcelColumnNum.java
  5. 1
      src/main/java/com/alibaba/excel/context/GenerateContextImpl.java
  6. 6
      src/main/java/com/alibaba/excel/event/AnalysisEventRegisterCenter.java
  7. 1
      src/main/java/com/alibaba/excel/event/OneRowAnalysisFinishEvent.java
  8. 1
      src/main/java/com/alibaba/excel/metadata/CellRange.java
  9. 1
      src/main/java/com/alibaba/excel/metadata/ExcelColumnProperty.java
  10. 1
      src/main/java/com/alibaba/excel/metadata/ExcelHeadProperty.java
  11. 1
      src/main/java/com/alibaba/excel/metadata/Font.java
  12. 1
      src/main/java/com/alibaba/excel/metadata/Table.java
  13. 1
      src/main/java/com/alibaba/excel/metadata/TableStyle.java
  14. 1
      src/main/java/com/alibaba/excel/parameter/ExcelWriteParam.java
  15. 20
      src/main/java/com/alibaba/excel/support/ExcelTypeEnum.java
  16. 1
      src/main/java/com/alibaba/excel/util/IndexValueConverter.java
  17. 1
      src/main/java/com/alibaba/excel/util/POITempFile.java
  18. 1
      src/main/java/com/alibaba/excel/util/PositionUtils.java
  19. 1
      src/main/java/com/alibaba/excel/util/TypeUtil.java
  20. 1
      src/main/java/com/alibaba/excel/write/ExcelBuilderImpl.java
  21. 11
      src/main`java/com/alibaba/excel/annotation/FieldType.java
  22. 17
      src/main`java/com/alibaba/excel/constant/ExcelXmlConstants.java
  23. 1
      src/test/java/function/model/ExcelPropertyIndexModel.java
  24. 4
      src/test/java/read/v03/XLS2003FunctionTest.java
  25. 4
      src/test/java/read/v07/Read2007Xlsx.java
  26. 1
      src/test/java/read/v07/listener/Excel2007WithJavaModelAnalysisListener.java

27
src/main/java/com/alibaba/excel/ExcelReader.java

@ -31,11 +31,23 @@ public class ExcelReader {
* }AnalysisContext
* @param eventListener
*/
@Deprecated
public ExcelReader(InputStream in, ExcelTypeEnum excelTypeEnum, Object customContent,
AnalysisEventListener eventListener) {
this(in, excelTypeEnum, customContent, eventListener, true);
}
/**
* @param in
* @param customContent {@link AnalysisEventListener#invoke(Object, AnalysisContext)
* }AnalysisContext
* @param eventListener
*/
public ExcelReader(InputStream in, Object customContent,
AnalysisEventListener eventListener) {
this(in, customContent, eventListener, true);
}
/**
* old 1.1.0
* @param param
@ -54,12 +66,27 @@ public class ExcelReader {
* @param eventListener
* @param trim
*/
@Deprecated
public ExcelReader(InputStream in, ExcelTypeEnum excelTypeEnum, Object customContent,
AnalysisEventListener eventListener, boolean trim) {
validateParam(in, excelTypeEnum, eventListener);
analyser.init(in, excelTypeEnum, customContent, eventListener, trim);
}
/**
* @param in
* @param customContent {@link AnalysisEventListener#invoke(Object, AnalysisContext)
* }AnalysisContext
* @param eventListener
* @param trim
*/
public ExcelReader(InputStream in, Object customContent,
AnalysisEventListener eventListener, boolean trim) {
ExcelTypeEnum excelTypeEnum = ExcelTypeEnum.valueOf(in);
validateParam(in, excelTypeEnum, eventListener);
analyser.init(in, excelTypeEnum, customContent, eventListener, trim);
}
/**
*/
public void read() {

1
src/main/java/com/alibaba/excel/analysis/v07/XlsxRowHandler.java

@ -18,7 +18,6 @@ import static com.alibaba.excel.constant.ExcelXmlConstants.*;
/**
* @author jipengfei
* @date 2017/08/23
*/
public class XlsxRowHandler extends DefaultHandler {

1
src/main/java/com/alibaba/excel/analysis/v07/XlsxSaxAnalyser.java

@ -25,7 +25,6 @@ import java.util.List;
/**
* @author jipengfei
* @date 2017/08/27
*/
public class XlsxSaxAnalyser extends BaseSaxAnalyser {

1
src/main/java/com/alibaba/excel/annotation/ExcelColumnNum.java

@ -7,7 +7,6 @@ import java.lang.annotation.*;
* Field column num at excel head
*
* @author jipengfei
* @date 2017/03/19
*/
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)

1
src/main/java/com/alibaba/excel/context/GenerateContextImpl.java

@ -3,6 +3,7 @@ package com.alibaba.excel.context;
import com.alibaba.excel.metadata.*;
import com.alibaba.excel.metadata.CellRange;
import com.alibaba.excel.metadata.Table;
import com.alibaba.excel.metadata.TableStyle;
import com.alibaba.excel.support.ExcelTypeEnum;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;

6
src/main/java/com/alibaba/excel/event/AnalysisEventRegisterCenter.java

@ -8,14 +8,14 @@ package com.alibaba.excel.event;
public interface AnalysisEventRegisterCenter {
/**
* @param name
* @param listener
* @param name 监听名定义
* @param listener 具体实现
*/
void appendLister(String name, AnalysisEventListener listener);
/**
* @param event
* @param event 事件
*/
void notifyListeners(OneRowAnalysisFinishEvent event);

1
src/main/java/com/alibaba/excel/event/OneRowAnalysisFinishEvent.java

@ -2,7 +2,6 @@ package com.alibaba.excel.event;
/**
* @author jipengfei
* @date 2017/07/21
*/
public class OneRowAnalysisFinishEvent {

1
src/main/java/com/alibaba/excel/metadata/CellRange.java

@ -2,7 +2,6 @@ package com.alibaba.excel.metadata;
/**
* @author jipengfei
* @date 2017/06/02
*/
public class CellRange {

1
src/main/java/com/alibaba/excel/metadata/ExcelColumnProperty.java

@ -6,7 +6,6 @@ import java.util.List;
/**
* @author jipengfei
* @date 2017/05/31
*/
public class ExcelColumnProperty implements Comparable<ExcelColumnProperty> {

1
src/main/java/com/alibaba/excel/metadata/ExcelHeadProperty.java

@ -9,7 +9,6 @@ import java.util.*;
/**
*
* @author jipengfei
* @date 2017/05/31
*/
public class ExcelHeadProperty {

1
src/main/java/com/alibaba/excel/metadata/Font.java

@ -3,7 +3,6 @@ package com.alibaba.excel.metadata;
/**
*
* @author jipengfei
* @date 2017/05/24
*/
public class Font {

1
src/main/java/com/alibaba/excel/metadata/Table.java

@ -4,7 +4,6 @@ import java.util.List;
/**
* @author jipengfei
* @date 2017/05/16
*/
public class Table {
/**

1
src/main/java/com/alibaba/excel/metadata/TableStyle.java

@ -4,7 +4,6 @@ import org.apache.poi.ss.usermodel.IndexedColors;
/**
* @author jipengfei
* @date 2017/05/24
*/
public class TableStyle {

1
src/main/java/com/alibaba/excel/parameter/ExcelWriteParam.java

@ -8,7 +8,6 @@ import java.io.OutputStream;
* {@link com.alibaba.excel.ExcelWriter}
*
* @author jipengfei
* @date 2017/05/15
*/
@Deprecated
public class ExcelWriteParam {

20
src/main/java/com/alibaba/excel/support/ExcelTypeEnum.java

@ -1,5 +1,10 @@
package com.alibaba.excel.support;
import org.apache.poi.poifs.filesystem.FileMagic;
import java.io.IOException;
import java.io.InputStream;
/**
*
* @author jipengfei
@ -21,4 +26,19 @@ public enum ExcelTypeEnum {
public void setValue(String value) {
this.value = value;
}
public static ExcelTypeEnum valueOf(InputStream inputStream){
try {
FileMagic fileMagic = FileMagic.valueOf(inputStream);
if(FileMagic.OLE2.equals(fileMagic)){
return XLS;
}
if(FileMagic.OOXML.equals(fileMagic)){
return XLSX;
}
throw new IllegalArgumentException("excelTypeEnum can not null");
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}

1
src/main/java/com/alibaba/excel/util/IndexValueConverter.java

@ -9,7 +9,6 @@ import java.util.Stack;
/**
* 去除空Cell
* @author jipengfei
* @date 2017/04/13
*/
public class IndexValueConverter {
public static List<String> converter(List<IndexValue> i_list) {

1
src/main/java/com/alibaba/excel/util/POITempFile.java

@ -5,7 +5,6 @@ import java.io.File;
/**
*
* @author jipengfei
* @date 2017/06/22
*/
public class POITempFile {

1
src/main/java/com/alibaba/excel/util/PositionUtils.java

@ -2,7 +2,6 @@ package com.alibaba.excel.util;
/**
* @author jipengfei
* @date 2017/08/27
*/
public class PositionUtils {

1
src/main/java/com/alibaba/excel/util/TypeUtil.java

@ -14,7 +14,6 @@ import java.util.regex.Pattern;
/**
* @author jipengfei
* @date 2017/03/15
*/
public class TypeUtil {

1
src/main/java/com/alibaba/excel/write/ExcelBuilderImpl.java

@ -21,7 +21,6 @@ import java.util.List;
/**
* @author jipengfei
* @date 2017/05/27
*/
public class ExcelBuilderImpl implements ExcelBuilder {

11
src/main`java/com/alibaba/excel/annotation/FieldType.java

@ -0,0 +1,11 @@
package com.alibaba.excel.annotation;
/**
*
* @author jipengfei
*/
public enum FieldType {
STRING, INT, LONG, DATE, BOOLEAN, DOUBLE,EMPTY;
}

17
src/main`java/com/alibaba/excel/constant/ExcelXmlConstants.java

@ -0,0 +1,17 @@
package com.alibaba.excel.constant;
/**
* @author jipengfei
*/
public class ExcelXmlConstants {
public static final String DIMENSION = "dimension";
public static final String DIMENSION_REF = "ref";
public static final String POSITION = "r";
public static final String ROW_TAG = "row";
public static final String CELL_TAG = "c";
public static final String CELL_VALUE_TAG = "v";
public static final String CELL_VALUE_TAG_1 = "t";
}

1
src/test/java/function/model/ExcelPropertyIndexModel.java

@ -5,7 +5,6 @@ import com.alibaba.excel.metadata.BaseRowModel;
/**
* @author jipengfei
* @date 2017/05/31
*/
public class ExcelPropertyIndexModel extends BaseRowModel {

4
src/test/java/read/v03/XLS2003FunctionTest.java

@ -19,12 +19,12 @@ public class XLS2003FunctionTest extends TestCase {
@Test
public void testExcel2003NoModel() {
InputStream inputStream = getInputStream("loan1.xls");
InputStream inputStream = getInputStream("2003.xls");
try {
// 解析每行结果在listener中处理
ExcelListener listener = new ExcelListener();
ExcelReader excelReader = new ExcelReader(inputStream, ExcelTypeEnum.XLS, null, listener);
ExcelReader excelReader = new ExcelReader(inputStream, null, listener);
excelReader.read();
} catch (Exception e) {
e.printStackTrace();

4
src/test/java/read/v07/Read2007Xlsx.java

@ -23,11 +23,11 @@ public class Read2007Xlsx {
//创建没有自定义模型,没有sheet的解析器,默认解析所有sheet解析结果以List<String>的方式通知监听者
@Test
public void noModel() {
InputStream inputStream = getInputStream("需要分批关闭客户名单 2018.8.24.xlsx");
InputStream inputStream = getInputStream("2007.xlsx");
final List<List<String>> ll = new ArrayList<List<String>>();
try {
ExcelReader reader = new ExcelReader(inputStream, ExcelTypeEnum.XLSX, null,
ExcelReader reader = new ExcelReader(inputStream, null,
new AnalysisEventListener<List<String>>() {
@Override
public void invoke(List<String> object, AnalysisContext context) {

1
src/test/java/read/v07/listener/Excel2007WithJavaModelAnalysisListener.java

@ -12,7 +12,6 @@ import java.util.List;
/**
* @author jipengfei
* @date 2017/08/27
*/
public class Excel2007WithJavaModelAnalysisListener extends AnalysisEventListener {

Loading…
Cancel
Save