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

Sheet index (1) is out of range (0..0) #41

Open
flacohenao opened this issue Sep 11, 2017 · 3 comments

Comments

Projects
None yet
3 participants
@flacohenao
Copy link

commented Sep 11, 2017

Hey. I'm having this error using your extension library.

when I execute the job it works just fine. but at the second time of executing, it gives me that error.

 @Bean
    public PoiItemReader<ActivosExcel> excelReader() throws MalformedURLException {
        PoiItemReader<ActivosExcel> reader = new PoiItemReader<>();
        reader.setSaveState(false);
        reader.setLinesToSkip(1);
        reader.setResource(new UrlResource("file:\\file.xlsx") {
        });
        reader.setRowMapper(excelRowMapper());
        return reader;
    }

that is my Reader there... the complete error is:

Caused by: java.lang.IllegalArgumentException: Sheet index (1) is out of range (0..0)
	at org.apache.poi.xssf.usermodel.XSSFWorkbook.validateSheetIndex(XSSFWorkbook.java:1527) ~[poi-ooxml-3.16.jar:3.16]
	at org.apache.poi.xssf.usermodel.XSSFWorkbook.getSheetAt(XSSFWorkbook.java:1134) ~[poi-ooxml-3.16.jar:3.16]
	at org.apache.poi.xssf.usermodel.XSSFWorkbook.getSheetAt(XSSFWorkbook.java:121) ~[poi-ooxml-3.16.jar:3.16]
	at org.springframework.batch.item.excel.poi.PoiItemReader.getSheet(PoiItemReader.java:47) ~[spring-batch-excel-0.5.0-SNAPSHOT.jar:na]
	at org.springframework.batch.item.excel.AbstractExcelItemReader.openSheet(AbstractExcelItemReader.java:120) ~[spring-batch-excel-0.5.0-SNAPSHOT.jar:na]
	at org.springframework.batch.item.excel.AbstractExcelItemReader.doOpen(AbstractExcelItemReader.java:112) ~[spring-batch-excel-0.5.0-SNAPSHOT.jar:na]
	at org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.open(AbstractItemCountingItemStreamItemReader.java:144) ~[spring-batch-infrastructure-3.0.8.RELEASE.jar:3.0.8.RELEASE]
	... 79 common frames omitted

can you please help me? or should I do a custom Reader with POI. If that's the case, can you give me an example of how to do it?

thank you.

UPDATE: The first time that I use it, it works (my .xlsx file only have 1 sheet.) but the second time it doesnt because The Reader doesnt find a second sheet.. so it throws that error.

I did a little test and i just created another sheet in file and it worked. but still have the problem in code.

Where is the index incrementing? it should always be 0!

@simonbahuchet

This comment has been minimized.

Copy link

commented Sep 12, 2017

@flacohenao

This comment has been minimized.

Copy link
Author

commented Sep 12, 2017

@simonbahuchet Thanks for the reply.

I solve the problem just creating the exact Reader and sheet just putting the .getIndexAt() method public and setting the sheet index I want to get.

I took a look at the library you recomended.. but its just for 2007 format, doesnt support .xlsx fortmat.

Do you think I managed that poorly?

thanks.

@shoaibshaikh1516

This comment has been minimized.

Copy link

commented Dec 9, 2018

@flacohenao can you provide your code, where you have fixed above issue (Sheet index (1) is out of range (0..0)) @flacohenao

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.