如何解决在 C# 中找不到的方法?

How to resolve the Method not found in C#?

我正在尝试读取一个 xlsx 文件,我从 This Codeproject Link 那里得到了一个基本的概述
现在,我收到以下异常消息:

与此异常相关的代码段如下:

public static sst SharedStrings;

    /// <summary>
    /// All worksheets in the Excel workbook deserialized
    /// </summary>
    /// <param name="ExcelFileName">Full path and filename of the Excel xlsx-file</param>
    /// <returns></returns>
    public static IEnumerable<worksheet> Worksheets(string ExcelFileName)
    {
        worksheet ws;
        using (ZipArchive zipArchive = ZipFile.Open(ExcelFileName, ZipArchiveMode.Read))
        {
            SharedStrings = DeserializedZipEntry<sst>(GetZipArchiveEntry(zipArchive, @"xl/sharedStrings.xml"));
            foreach (var worksheetEntry in (WorkSheetFileNames(zipArchive)).OrderBy(x => x.FullName))
            {
                ws = DeserializedZipEntry<worksheet>(worksheetEntry);
                ws.NumberOfColumns = worksheet.MaxColumnIndex + 1;
                ws.ExpandRows();
                yield return ws;
            }
        }
    }


经过一番搜索,我发现我需要针对.NET 4.5 或更高版本,(我的目标是 4.6.1,但我也尝试过 4.5,结果仍然相同)。此外,就依赖关系而言,我的参考资料如下所示:

完成所有这些之后,我仍然遇到上述异常,并且不知道为什么会这样。
编辑 1:我经历了 This Whosebug Link,我认为我需要最新的 DLL。我去了 Nuget 包管理器,有 "No Packages Found" 可用于更新。

我试过 .NET 4.6.14.6.2. 都对我有用。

我的Visual StudioCommunity Edition 2017

项目参考:

请注意 System.IO.Compression.ZipFile 被引用。在我的环境中无法引用它。

使用 Workbook.Worksheets() 或将调用 class 声明为 Excel.Workbook 的子 class。

ExcelCodeProject article 源的名称空间,它提供了必要的 classes。

using Excel;
using System;

namespace akExcelAsZipDemo
{
    class Program : Workbook
    {
        //  from
        //  https://www.codeproject.com/tips/801032/csharp-how-to-read-xlsx-excel-file-with-lines-ofthe
        //
        //  inspired:
        //  https://github.com/ahmadalli/ExcelReader

        static void Main(string[] args)
        {
            const string fileName = @"E:\AK\export.xlsx";

            var worksheets = Worksheets(fileName);

            foreach (worksheet ws in worksheets)
            {
                Console.WriteLine($"cols={ws.NumberOfColumns} rows={ws.Rows.Length}");
            }

            Console.WriteLine();
        }
    }
}