0
**解析Excel表头时出现的异常
**
触发Bug的代码
private static class HeadDataListener extends AnalysisEventListener<Map<Integer, String>> {
Map<Integer, String> headMapResult=new HashMap<>();
@Override
public void invoke(Map<Integer, String> data, AnalysisContext context) {
}
@Override
public void doAfterAllAnalysed(AnalysisContext context) {
}
/**
* 这里会一行行的返回头
*
* @param headMap
* @param context
*/
@Override
public void invokeHeadMap(Map<Integer, String> headMap, AnalysisContext context) {
headMapResult=headMap;
}
public Map<Integer, String> getHeadMapResult() {
return headMapResult;
}
public void setHeadMapResult(Map<Integer, String> headMapResult) {
this.headMapResult = headMapResult;
}
}
public static Map<Integer, String> getExcelHeader(InputStream inputStream){
HeadDataListener headDataListener = new HeadDataListener();
EasyExcelFactory.read(inputStream, headDataListener).build().readAll();
return headDataListener.getHeadMapResult();
}
```java
java.lang.NullPointerException: null
at org.apache.poi.xssf.usermodel.XSSFTableStyle.<init>(XSSFTableStyle.java:64) ~[poi-ooxml-3.17.jar:3.17]
at org.apache.poi.xssf.model.StylesTable.readFrom(StylesTable.java:247) ~[poi-ooxml-3.17.jar:3.17]
at org.apache.poi.xssf.model.StylesTable.<init>(StylesTable.java:141) ~[poi-ooxml-3.17.jar:3.17]
at org.apache.poi.xssf.eventusermodel.XSSFReader.getStylesTable(XSSFReader.java:126) ~[poi-ooxml-3.17.jar:3.17]
at com.alibaba.excel.analysis.v07.XlsxSaxAnalyser.<init>(XlsxSaxAnalyser.java:81) ~[easyexcel-2.2.6.jar:na]
at com.alibaba.excel.analysis.ExcelAnalyserImpl.choiceExcelExecutor(ExcelAnalyserImpl.java:99) ~[easyexcel-2.2.6.jar:na]
at com.alibaba.excel.analysis.ExcelAnalyserImpl.<init>(ExcelAnalyserImpl.java:51) ~[easyexcel-2.2.6.jar:na]
at com.alibaba.excel.ExcelReader.<init>(ExcelReader.java:145) ~[easyexcel-2.2.6.jar:na]
at com.alibaba.excel.read.builder.ExcelReaderBuilder.build(ExcelReaderBuilder.java:193) ~[easyexcel-2.2.6.jar:na]
原文件如下 easyexcel_error.xlsx