spring-batch-extensions icon indicating copy to clipboard operation
spring-batch-extensions copied to clipboard

Mapping multiple sheets with multliple target objects

Open xscorpio972 opened this issue 9 years ago • 19 comments

A workbook with differents sheets can't be read if the objects targets aren't the same type.

xscorpio972 avatar Apr 25 '15 22:04 xscorpio972

I left a note in the PR, but we can continue design discussions here. Instead of creating a whole new reader, why not take the approach of a decorator like the MultiResourceItemReader?

mminella avatar Jun 08 '15 16:06 mminella

We have a use case for exactly this scenario. Is there a chance that the pull request for the proposed solution could be merged? Many thanks

MichelinMan avatar Jun 25 '15 17:06 MichelinMan

Hello,

I didn't have time to implement the solution with the decorator. I'll try to do it the next week, is it ok?

Thanks

2015-06-25 19:53 GMT+02:00 MichelinMan [email protected]:

We have a use case for exactly this scenario. Is there a chance that the pull request for the proposed solution could be merged? Many thanks

— Reply to this email directly or view it on GitHub https://github.com/spring-projects/spring-batch-extensions/issues/17#issuecomment-115343807 .

xscorpio972 avatar Jun 25 '15 18:06 xscorpio972

Thank you, that you be great!

MichelinMan avatar Jun 26 '15 08:06 MichelinMan

I've already created my own implementation using Apache POI following the same idea you're exposing here : https://github.com/almex/Raildelays/blob/master/batch/src/main/java/org/springframework/batch/item/file/ExcelSheetItemReader.java

almex avatar Sep 21 '15 19:09 almex

Would it be possible to fix this issue?

Anbarasan93 avatar Feb 01 '17 06:02 Anbarasan93

i am facing issue with rowmapper. how to use rowmapper.

Karthick-Shanmugam-15 avatar Jul 22 '20 02:07 Karthick-Shanmugam-15

i'm facing this issue right now and found out that there's a PR opened with a solution for it since 2015, so i was wondering when will it could be merged ? thank you in advance @benas

ahmedmokhtar97 avatar Oct 18 '21 14:10 ahmedmokhtar97

I've already created my own implementation using Apache POI following the same idea you're exposing here : https://github.com/almex/Raildelays/blob/master/batch/src/main/java/org/springframework/batch/item/file/ExcelSheetItemReader.java

We have tried to use your package and it's very helpful. Just not able to know how you can include a custom RowMapper. I see you have developed a be.raildelays.batch.bean.BatchExcelRowMapper to use ExchelSheetItemReader.

Is there any generic approach like org.springframework.batch.item.excel.mapping.BeanWrapperRowMapper where we can setTargetType as custom Model?

TechGrizzlee avatar Feb 03 '22 13:02 TechGrizzlee

Please don't use the Spring Batch Excel issues to discuss features in a different library. Either take that to that github repository or ask for feature improvements here.

mdeinum avatar Feb 03 '22 13:02 mdeinum

Hello, I don't know where to address this issue but thsi thread seems to be suitable. How is the work going with handling multiple excel sheets differently? I have noticed that this library's reader reads sheet for sheet, row by row.

Kyeiv avatar Apr 12 '22 08:04 Kyeiv

It doesn't. Configure a different reader per sheet you want to read and limit the reading of rows/sheets for that reader.

mdeinum avatar Apr 12 '22 08:04 mdeinum

Could you provide some more information how to do it? I am really sorry for that question, but i am new to spring batch. I know it isn't a place for such discussion so if you'd be so kind and write to me via email that is given in my description.

Kyeiv avatar Apr 12 '22 08:04 Kyeiv

What I proposed is currently not possible, as we read the whole thing starting from sheet 1. We would need to enhance the readers to include something to specify which sheets to read. However, how should one specify this? A list if numbers to include, a range, a combination or something else? While it might seem easy it might not be as easy as it is at a first glance.

Currently the main usecase for Spring Batch Excel is reading a single sheet excel file, 1 file with multiple sheets isn't done that often (hence no mapping per sheet etc. will exist).

But if you want to have a way of specifying what to read, please open a new ticket for that so that we could make the configuration work to read the file multiple times with different mappings.

mdeinum avatar Apr 12 '22 09:04 mdeinum

Created new issue, thanks.

https://github.com/spring-projects/spring-batch-extensions/issues/95

Kyeiv avatar Apr 12 '22 10:04 Kyeiv

You created an issue for multiple sheets not reading a specific sheet(s).

As it is a niche to have 1 file with multiple sheets and mapped to different objects I'm not willing to implement that in the readers. As it also yields other issues with building steps etc.

mdeinum avatar Apr 12 '22 12:04 mdeinum

You created an issue for multiple sheets not reading a specific sheet(s).

The issue title states "Need of reading one particular sheet or define mapping for every sheet". So I am aiming to read one sheet from the file for example passing ts name as parameter.

Kyeiv avatar Apr 12 '22 12:04 Kyeiv

The issue is an or :). The latter we already concluded isn't going to happen. So the only thing is to read a particular sheet or sheets. Not sure if that should be by name or index, that is for another discussion.

mdeinum avatar Apr 12 '22 12:04 mdeinum

corrected the issue

Kyeiv avatar Apr 12 '22 12:04 Kyeiv

The intent of the Excel readers is to map 1 row to 1 object. Trying to shoehorn this into 1 reader feels like adding much complexity for a niche functionality. For reading a file with multiple sheets you can use multiple steps and re-use parts of the configuration.

mdeinum avatar Oct 02 '23 14:10 mdeinum