Skip to content

Commit

Permalink
修复表头问题
Browse files Browse the repository at this point in the history
  • Loading branch information
dangdang01234 committed Nov 14, 2018
1 parent 19ebaf2 commit b28a117
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public ExcelAnalyserImpl(InputStream inputStream, ExcelTypeEnum excelTypeEnum, O
eventListener, trim);
}


private BaseSaxAnalyser getSaxAnalyser() {
if (saxAnalyser != null) {
return this.saxAnalyser;
Expand All @@ -50,14 +49,14 @@ private BaseSaxAnalyser getSaxAnalyser() {
if (!analysisContext.getInputStream().markSupported()) {
throw new ExcelAnalysisException(
"Xls must be available markSupported,you can do like this <code> new "
+ "BufferedInputStream(new FileInputStream(\"/xxxx/xxx/77.xlsx\"))</code> ");
+ "BufferedInputStream(new FileInputStream(\"/xxxx\"))</code> ");
}
this.saxAnalyser = new XlsSaxAnalyser(analysisContext);
}
}
} catch (Exception e) {
throw new ExcelAnalysisException("File type error,io must be available markSupported,you can do like "
+ "this <code> new BufferedInputStream(new FileInputStream(\\\"/xxxx/xxx/77.xlsx\\\"))</code> \"", e);
+ "this <code> new BufferedInputStream(new FileInputStream(\\\"/xxxx\\\"))</code> \"", e);
}
return this.saxAnalyser;
}
Expand Down
28 changes: 15 additions & 13 deletions src/main/java/com/alibaba/excel/metadata/ExcelHeadProperty.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,12 @@ private void initColumnProperties() {
if (this.headClazz != null) {
List<Field> fieldList = new ArrayList<Field>();
Class tempClass = this.headClazz;
//当父类为null的时候说明到达了最上层的父类(Object类).
//When the parent class is null, it indicates that the parent class (Object class) has reached the top
// level.
while (tempClass != null) {
fieldList.addAll(Arrays.asList(tempClass .getDeclaredFields()));
fieldList.addAll(Arrays.asList(tempClass.getDeclaredFields()));
//Get the parent class and give it to yourself
tempClass = tempClass.getSuperclass();
//得到父类,然后赋给自己
}
List<List<String>> headList = new ArrayList<List<String>>();
for (Field f : fieldList) {
Expand Down Expand Up @@ -187,27 +188,28 @@ public List<String> getHeadByRowNum(int rowNum) {
* @return the last consecutive string position
*/
private int getLastRangNum(int j, String value, List<String> values) {
int lastRow = -1;
if (StringUtils.isEmpty(value)) {
if (value == null) {
return -1;
}
for (int i = 0; i < values.size(); i++) {
if (j > 0) {
String preValue = values.get(j - 1);
if (value.equals(preValue)) {
return -1;
}
}
int last = j;
for (int i = last + 1; i < values.size(); i++) {
String current = values.get(i);
if (value.equals(current)) {
if (i >= j) {
lastRow = i;
} else {
//if i<j && value.equals(current) Indicates that a merger has occurred
return -1;
}
last = i;
} else {
// if i>j && !value.equals(current) Indicates that the continuous range is exceeded
if (i > j) {
break;
}
}
}
return lastRow;
return last;

}

Expand Down

0 comments on commit b28a117

Please sign in to comment.