-
Notifications
You must be signed in to change notification settings - Fork 7.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
重写hasNext后doReadAll无法读取下一个sheet #3199
Comments
#3163 |
那请问fix版本大概会什么时候release |
@zhuangjiaju |
请问要如何增加判断,我试了【不重写hasNext,直接在invoke方法增加条数的判断后return】,但从耗时来看,依然会继续调用invoke方法。有没有什么办法可以提前终止读取第一页sheet、开始读取第二页 |
加一个卫语句 if(!hasNext){ |
class YourListener(
// key: sheet name ;value: list of field name
val headNames: LinkedHashMap<String, List<String>>,
) : AnalysisEventListener<Map<Int, String>?>() {
private val dataList = ArrayList<Map<Int, String>?>()
companion object {
private val logger: Logger = LoggerFactory.getLogger(YourListener::class.java)
}
override fun doAfterAllAnalysed(context: AnalysisContext?) {
logger.info("条数:${dataList.size}")
}
override fun invoke(data: Map<Int, String>?, context: AnalysisContext?) {
if (!hasNext(context)) {
return
}
logger.info("invoke...")
dataList.add(data)
}
// 解析表头
override fun invokeHeadMap(headMap: MutableMap<Int, String>?, context: AnalysisContext?) {
// 当前sheet页名
val currentSheetName = context?.readSheetHolder()?.sheetName
println(currentSheetName)
if (!currentSheetName.isNullOrBlank()) {
headNames[currentSheetName] = headMap?.values?.toList() ?: emptyList()
}
}
override fun hasNext(context: AnalysisContext?): Boolean {
return context!!.readSheetHolder()!!.rowIndex <= 20
}
}
// mian()
val doReadAllSync = EasyExcel.read(file.inputStream).readCache(MapCache())
.readDefaultReturn(ReadDefaultReturnEnum.ACTUAL_DATA)
.ignoreEmptyRow(true)
.registerReadListener(YourListener(headMap)).headRowNumber(1).doReadAllSync<Map<Integer, Any>>() 中断后第二页sheet不会读取 |
已解决。获取sheetList,调用reader.read(),但实在想不明白有啥差别,望指教 val reader = EasyExcel.read(storageFile).readCache(MapCache())
.readDefaultReturn(ReadDefaultReturnEnum.ACTUAL_DATA)
.ignoreEmptyRow(true)
.registerReadListener(SheetAndColumnTypeAnalyseListener(headMap)).headRowNumber(1).build()
val sheetList = reader.excelExecutor().sheetList()
reader.read(sheetList)
reader.close() |
建议先去看文档
快速开始 、常见问题
异常代码
异常提示
问题描述
版本:easyexcel:3.3.1
问题:当重写hasNext()后,doReadAll失效
需求:读取每个sheet页的前n行,
详细:一开始使用的是【invoke()方法增加判断后返回return】但发现有性能问题;该用【重写hasNext】的方式后发现无法读取下一个sheet页,即listener中的回调方法只执行了一次
The text was updated successfully, but these errors were encountered: