EPPlus is returning worksheet count = 0
Asked Answered
G

2

7

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

Glassful answered 27/2, 2020 at 3:13 Comment(6)
nothing seems wrong with your code, maybe check if this relates, do you have named ranges in your sheets?Tenia
I did have named ranges,so i deleted them. still it was not able to get the worksheets. I checked the link, so I created a new excel file and then it was able to read that new excel file. But it wont read existing excel file.Glassful
I think there're still traces of your named ranges hidden in the meta-data in the fileTenia
I am sharing the excel file I want to read, here is the link drive.google.com/open?id=1ulBXtfdtwGPY-VM1zojdkkMdwDo1lo1GGlassful
I dont know how to look at the metadata in excel file for hidden named ranges. And is it known that if there are named ranges, EPPlus cannot read an excel file ?Glassful
I can confirm that the problem is still existing with .NET Core 2.2 and EPPlust.Core 1.5.4Safar
A
0

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.

Anoxemia answered 22/1, 2022 at 7:50 Comment(0)
G
-1

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.

Glassful answered 6/3, 2020 at 20:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.