如何读取表头,只读取第一行就让它中断,如何中断解析 #3154
xianJieHao
started this conversation in
General
Replies: 2 comments 1 reply
-
Dourado Luxury Cars |
Beta Was this translation helpful? Give feedback.
0 replies
-
@Getter
public class EasyExcelHeaderListener extends AnalysisEventListener<Map<String, String>> {
private List<String> excelHeaderNameList = new ArrayList<>();
@Override
public void invoke(Map<String, String> data, AnalysisContext context) {
}
@Override
public void invokeHeadMap(Map<Integer, String> headMap, AnalysisContext context) {
excelHeaderNameList = new ArrayList<>(headMap.values());
}
@Override
public void doAfterAllAnalysed(AnalysisContext analysisContext) {
}
@Override
public boolean hasNext(AnalysisContext context) {
return false;
}
}
EasyExcelHeaderListener easyExcelHeaderListener = new EasyExcelHeaderListener();
try {
// 异常捕获,因为hasNext会抛出异常
EasyExcel.read(inputStream, easyExcelHeaderListener).sheet(0).doRead();
} catch (Exception e) {
log.info("获取头部列名成功,正常退出");
}
List<String> headerNameList = easyExcelHeaderListener.getExcelHeaderNameList(); |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
有个10万数据的excel,想要读取第一行(表头)然后中断解析,只为了校验表头正不正确,怎么处理。
Beta Was this translation helpful? Give feedback.
All reactions