Skip to content
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

[add] direct Stream support as read output #3052

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

wolray
Copy link

@wolray wolray commented Mar 15, 2023

给EasyExcel添加直接的Stream支持,不加入任何中间缓存
用户不需要创建匿名ReadListener类,甚至不需要感知它的存在
读取Excel的过程直接转化为流式API,也就是Stream,之后可以随意聚合为List, Map或者进行别的任何操作
整个封装没有任何额外性能或内存开销,甚至连原本PageReadListener里的cachedDataList也省了

这一版提交没有处理sheet()等相关可选操作,仅作为原理展示
新增的方法本身是static函数,所以可以随意复制到本地进行测试

@CLAassistant
Copy link

CLAassistant commented Mar 15, 2023

CLA assistant check
All committers have signed the CLA.

@wolray
Copy link
Author

wolray commented Mar 15, 2023

hi,为了保持与原版一致,支持多种数据源与sheet设置,我又提交了一版代码,应该达到可发布的状态了
全部提交只有新增文件和代码,没有任何删减
读取Excel为Stream现在非常简单

// 根据路径读取全部sheet
Stream<DemoData> stream1 = EasyExcel.read("file", DemoData.class).toStream();
// 从文件对象读取与第一个sheet
Stream<DemoData> stream2 = EasyExcel.read(new File("file"), DemoData.class).toStream(0);
// 从InputStream读取指定名字sheet
Stream<DemoData> stream3 = EasyExcel.read(Files.newInputStream(Paths.get("file")), DemoData.class).toStream("Sheet1");

@nasodaengineer
Copy link

你这个流没法limit把

@wolray
Copy link
Author

wolray commented Apr 14, 2023

直接是没法limit,但要加也简单,加个int参数带进去就行
需要的话我可以加上

@nasodaengineer
Copy link

感觉可以定义为一种新的接口继承Consumer<BiConsumer<T, AnalysisContext>>>返回,提供一些流式操作的默认方法,这样既不会丢失行信息,也可以避免用户的一些非法操作

@wolray
Copy link
Author

wolray commented Apr 17, 2023

嗯,相当于一个简单版的callback流,提供常用操作就好,limit也能实现。
我觉得可。

@RabbitHareLu
Copy link

合并为啥被阻止了呢, 正想着自己封装不好呢, 官方也不提供, 好不容易看到一个符合需求的还被拒绝合并了

@nasodaengineer
Copy link

合并为啥被阻止了呢, 正想着自己封装不好呢, 官方也不提供, 好不容易看到一个符合需求的还被拒绝合并了

官方摆烂很久了

@psxjoy
Copy link
Collaborator

psxjoy commented Aug 15, 2024

Great improvement! This seems to be a highly requested feature. I’ll spend some time researching it and will discuss with other project members whether to implement this request (I personally think this feature is interesting as it could help light users focus more on the business code itself). I’ll update the status of this issue and share updates promptly.

很好的PR!我将和其他开发人员讨论是否要增加类似的功能。我会及时修改这个 PR 的状态和更新消息。

@nasodaengineer
Copy link

Great improvement! This seems to be a highly requested feature. I’ll spend some time researching it and will discuss with other project members whether to implement this request (I personally think this feature is interesting as it could help light users focus more on the business code itself). I’ll update the status of this issue and share updates promptly.

很好的PR!我将和其他开发人员讨论是否要增加类似的功能。我会及时修改这个 PR 的状态和更新消息。

都停更了也没消息

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants