Browse Source

修复空行读取空指针异常

bugfix v2.0.0-beta6
Jiaju Zhuang 5 years ago
parent
commit
39937610ef
  1. 5
      src/main/java/com/alibaba/excel/analysis/v07/handlers/ProcessResultCellHandler.java
  2. 8
      src/main/java/com/alibaba/excel/util/PositionUtils.java

5
src/main/java/com/alibaba/excel/analysis/v07/handlers/ProcessResultCellHandler.java

@ -10,6 +10,7 @@ import com.alibaba.excel.constant.ExcelXmlConstants;
import com.alibaba.excel.context.AnalysisContext; import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.read.listener.event.EachRowAnalysisFinishEvent; import com.alibaba.excel.read.listener.event.EachRowAnalysisFinishEvent;
import com.alibaba.excel.read.metadata.holder.ReadRowHolder; import com.alibaba.excel.read.metadata.holder.ReadRowHolder;
import com.alibaba.excel.util.PositionUtils;
/** /**
* Cell Handler * Cell Handler
@ -32,8 +33,8 @@ public class ProcessResultCellHandler implements XlsxCellHandler {
@Override @Override
public void startHandle(String name, Attributes attributes) { public void startHandle(String name, Attributes attributes) {
analysisContext analysisContext.readRowHolder(
.readRowHolder(new ReadRowHolder(Integer.valueOf(attributes.getValue(ExcelXmlConstants.POSITION)), new ReadRowHolder(PositionUtils.getRowByRowTagt(attributes.getValue(ExcelXmlConstants.POSITION)),
analysisContext.readSheetHolder().getGlobalConfiguration())); analysisContext.readSheetHolder().getGlobalConfiguration()));
} }

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

@ -7,6 +7,14 @@ public class PositionUtils {
private PositionUtils() {} private PositionUtils() {}
public static int getRowByRowTagt(String rowTagt) {
int row = 0;
if (rowTagt != null) {
row = Integer.parseInt(rowTagt) - 1;
}
return row;
}
public static int getRow(String currentCellIndex) { public static int getRow(String currentCellIndex) {
int row = 0; int row = 0;
if (currentCellIndex != null) { if (currentCellIndex != null) {

Loading…
Cancel
Save