VS Code C# - System.NotSupportedException: 没有可用于编码 1252 的数据
VS Code C# - System.NotSupportedException: No data is available for encoding 1252
我正在尝试使用 ExcelDataReader 读取 Ubuntu 上的 .xls 文件。我在 C# 中使用 VS Code。这是代码:
var stream = File.Open(filePath, mode: FileMode.Open, access: FileAccess.Read);
var reader = ExcelReaderFactory.CreateReader(stream);
我也试过这个:
var reader = ExcelDataReader.ExcelReaderFactory.CreateBinaryReader(stream);
当我 运行 时,出现以下异常:
Unhandled Exception: System.NotSupportedException: No data is available for encoding 1252. For information on defining a custom encoding, see the documentation for the Encoding.RegisterProvider method.
at System.Text.Encoding.GetEncoding(Int32 codepage)
我已经安装了 libmono-i18n-west4.0-cil
(也尝试过 libmono-i18n4.0-all
),因为我发现有人推荐这个,但问题仍然存在。还安装了软件包 System.Text.Encoding.CodePages
但没有成功。
谁能帮忙解决这个问题?
我在 .net Core 应用程序中遇到了同样的问题。我在 ExcelReaderFactory.CreateReader(stream)
之前添加了 System.Text.Encoding.CodePages
nuget 包并注册了编码提供程序,这解决了问题。
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
//open file and returns as Stream
using (var stream = File.Open(fileName, FileMode.Open, FileAccess.Read))
{
using (var reader = ExcelReaderFactory.CreateReader(stream))
{
}
}
我正在尝试使用 ExcelDataReader 读取 Ubuntu 上的 .xls 文件。我在 C# 中使用 VS Code。这是代码:
var stream = File.Open(filePath, mode: FileMode.Open, access: FileAccess.Read);
var reader = ExcelReaderFactory.CreateReader(stream);
我也试过这个:
var reader = ExcelDataReader.ExcelReaderFactory.CreateBinaryReader(stream);
当我 运行 时,出现以下异常:
Unhandled Exception: System.NotSupportedException: No data is available for encoding 1252. For information on defining a custom encoding, see the documentation for the Encoding.RegisterProvider method. at System.Text.Encoding.GetEncoding(Int32 codepage)
我已经安装了 libmono-i18n-west4.0-cil
(也尝试过 libmono-i18n4.0-all
),因为我发现有人推荐这个,但问题仍然存在。还安装了软件包 System.Text.Encoding.CodePages
但没有成功。
谁能帮忙解决这个问题?
我在 .net Core 应用程序中遇到了同样的问题。我在 ExcelReaderFactory.CreateReader(stream)
之前添加了 System.Text.Encoding.CodePages
nuget 包并注册了编码提供程序,这解决了问题。
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
//open file and returns as Stream
using (var stream = File.Open(fileName, FileMode.Open, FileAccess.Read))
{
using (var reader = ExcelReaderFactory.CreateReader(stream))
{
}
}