Keep in Touch!

Contents

C# 9 and .NET 5

ExcelDataReader – No data is available for encoding 1252

Contents

During the last month, I had to convert an xlsx file to csv in a netcore Azure Function, and I discovered how it should have been simple!

In theory, I only have to read the file with ExcelDataReader and after write the file as text.

It should have been an easy thing to do, but suddenly I recognized that some file worked and other not.

What was the error? A message “NotSupportedException: No data is available for encoding 1252” appeared. How could I solve it?

The solution has been very simple to find.

  • Add “System.Text.Encoding.CodePages” NuGet package to solution
  • Open the file Startup.cs > ConfigureServices and change as in the snippet

Startup - ConfigureServices

1
2
3
4
5
6
7
public void ConfigureServices(IServiceCollection services)
{
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
// Or Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
 
    // your code ...
}

That’s the easiest way to read an excel file without problem from netcore code.

Links