2

I am using LinqToExcel Nuget package to read excel file.

Below is my code

            var excelFile = new ExcelQueryFactory("DeployQueues");

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

But I am getting below compiler error.

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; }

 }
Ashutosh B Bodake
  • 1,304
  • 1
  • 19
  • 31

2 Answers2

0

Add references Remotion.Data.Linq.dll. You can find it in Nuget;

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

lucky
  • 12,734
  • 4
  • 24
  • 46
  • Now, the error is removed but and I am getting another error. "The type 'QueryableBase<>' is defined in an assembly that is not referenced. You must add a reference to assembly 'Remotion.Data.Linq" I have added this refernce but still I am getting this error – Ashutosh B Bodake Nov 28 '17 at 19:02
0

I think the documentation for using LINQToExcel is not good.

I have used below code.

        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;
Ashutosh B Bodake
  • 1,304
  • 1
  • 19
  • 31