Open JesseChang opened 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:
Package.Workbook.Worksheets[0]
works OK.Package.Workbook.Worksheets[0]
fails with position out of range.That would enable other people to reproduce your issue and try to debug EPPlus.
Thanks.
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.
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