JanKallman / EPPlus

Create advanced Excel spreadsheets using .NET
3.76k stars 1.18k forks source link

Worksheet position out of range in dotnetcore 2.X #323

Open JesseChang opened 6 years ago

JesseChang commented 6 years ago

Scenario

Reason: unknown.

Package.Workbook.Wordsheets[0] will sometimes cause Worksheet position out of range in aspnetcore 2.X. Mine environment is epplus library is used in docker container on linux server. Some computers upload *.xlsx file will make epplus not finding worksheet by Package.Workbook.Wordsheets[0] .

Workaround

Please use foreach to iterate Package.Workbook.Wordsheets then you can successfully get worksheet object

binki commented 6 years ago

@JesseChang Are you able to attach example .xlsx files to this worksheet? It would be nice to have example of these situations:

That would enable other people to reproduce your issue and try to debug EPPlus.

Thanks.

JesseChang commented 6 years ago

Hi @binki , My application is AspDotNet.Core and the funny thing is that the exact same file will work if I upload from different computer. I spent some time and found out that some computers will mess up the UploadFile.ContentType and causing following if statement to be false if (UploadFile.ContentType.ToLower() == "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") , maybe this is the reason making EPPlus couldn't get worksheet from .xlsx.

The only thing I can be sure is if the file content type is correct then everything works.