berek
berek

Reputation: 91

Contents of the unpacked xlsx file and apache poi

The initial problem is the inability to open the xlsx file through poi, while in Excel it opens.

A detailed study of the poi showed that the problem lies in the contents of the file. If you unzip xslx file, then in the xl folder, in addition to all other files there will be two due to which there is a problem

xl/metadata
xl/metadata.xml

when using poi method OPCPackage.open(fileName, PackageAccess.READ) this leads to an error:

org.apache.poi.openxml4j.exceptions.InvalidFormatException: You can't add a part with a part name derived from another part ! [M1.11]

which occurs due to the same file names.

If I just copy the contents of the entire xlsx file to a new created xlsx file and save it, then the xl/metadata file will not be there and it will open through poi well. But I don’t have the task of just fixing the file, I need to figure out why this problem could arise. Is there any idea about the occurrence of xl/metadata in the contents of the xlsx?

Upvotes: 1

Views: 999

Answers (1)

walle lyu
walle lyu

Reputation: 1

This error also happened in my program when I want to create multiple sheets in a workbook with a multi-thread pool. I guess the reason is that when two sheets has the same name, this error occurs. I solved this program by creating sheets in advance, then in the multi-thread pool I got the sheet by its index.

Upvotes: 0

Related Questions