【问题标题】:Getting "Could not find an implementation of the query pattern for source type 'ExcelQueryable<T>'. " Error获取“找不到源类型'ExcelQueryable<T>'的查询模式的实现。”错误
【发布时间】:2017-11-28 15:52:35
【问题描述】:

我正在使用 LinqToExcel Nuget 包来读取 excel 文件。

下面是我的代码

            var excelFile = new ExcelQueryFactory("DeployQueues");

        var tableData = from z in excelFile.Worksheet<AllQueues>("Data")
                        select z;

但是我遇到了编译器错误。

Could not find an implementation of the query pattern for source type 
'ExcelQueryable<AllQueues>

class for AllQueues

 public class AllQueues 
 {
    [ExcelColumn("Company Title")] 
    public string Name { get; set; }

    [ExcelColumn("Providence")] 
    public string State { get; set; }

    [ExcelColumn("Employee Count")] 
    public string Employees { get; set; }

 }

【问题讨论】:

    标签: c# excel linq linq-to-entities linq-to-excel


    【解决方案1】:

    添加引用Remotion.Data.Linq.dll。你可以在 Nuget 中找到它;

    https://staging.nuget.org/packages/Remotion.Data.Linq/

    【讨论】:

    • 现在,错误已被删除,但我又遇到了另一个错误。 “类型 'QueryableBase' 是在未引用的程序集中定义的。您必须添加对程序集 'Remotion.Data.Linq 的引用”我已添加此引用但我仍然收到此错误
    【解决方案2】:

    我认为使用 LINQToExcel 的文档不好。

    我使用了下面的代码。

            string fileName = @"YouPath";
            string conn = string.Empty;
            DataTable dtexcel = new DataTable();
            conn = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileName 
            + ";Extended Properties='Excel 12.0;HDR=NO';"; //for above excel 
            2007 
    
            using (OleDbConnection con = new OleDbConnection(conn))
            {
                con.Open();
                DataTable Sheets = 
                con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
    
                try
                {
                    OleDbDataAdapter oleAdpt = new OleDbDataAdapter("select * 
                    from [WorksheetName$]", con); //here we read data from 
                    sheet1  
                    oleAdpt.Fill(dtexcel); //fill excel data into dataTable  
                }
                catch (Exception ex)
                {
                }
            }
            return dtexcel;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-09-23
      • 2010-11-10
      • 1970-01-01
      • 2012-04-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多