EPPlus is returning worksheet count = 0

Viewed 2254

I am getting 0 worksheet count when the excel file (.xls) has 4 worksheets. I dont know why its not working for me. Please help.

Excel file last in Excel Version 1908 Office 365
EPPlus Version : 4.5.3.3
C# .Net Framework Version : 4.7

public static void readXLS(string FilePath)
{
    FileInfo existingFile = new FileInfo(FilePath);
    using (ExcelPackage package = new ExcelPackage(existingFile))
    {
        int count = package.Workbook.Worksheets.Count;
    }
}

I am sharing the excel file I want to read, here is the link

2 Answers

It doesn't look like it was your case but it may happen to other people so I'll leave it as an answer but in my case the file extension was .xlsx so no issue on this side. However, the file was located on a network location (even if I was accessing it via a network drive defined in Windows).

So if you face this issue, you might want to have your code to copy the file first to a temporary local destination, and then access it from there with EPPlus. Once you're done you can clean after self the local copy.

In my case credentials to access the network location were also different from those I use in Windows so your mileage may vary a bit based on this too.

I figured out that EPPlus works fine if the file is saved as in extension .xlsx I am fine using .xlsx, so for me this is not an issue anymore.

Related