I need to read the excel file. All the examples that I found either do not work, or are too difficult to understand, as for a beginner.

How to open a file to drive data into a DataGridView ?

Closed due to the fact that the essence of the question is not clear to the participants of Kromster , user194374, Bald , Streletz , user207618 Aug 29 '16 at 18:02 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

    2 answers 2

    Here is the same topic , another example: Import Excel File to DataSet .

     private void button1_Click(object sender, EventArgs e) { OleDbConnection MyConnection; DataSet DtSet; OleDbDataAdapter MyCommand; MyConnection = new OleDbConnection(@"provider=Microsoft.Jet.OLEDB.4.0;Data Source='c:\fileExcel.xls';Extended Properties=Excel 8.0;"); MyCommand = new OleDbDataAdapter("select * from [Sheet1$]", MyConnection); MyCommand.TableMappings.Add("Table", "Net"); DtSet = new DataSet(); MyCommand.Fill(DtSet); dataGridView1.DataSource = DtSet.Tables[0]; MyConnection.Close(); } 
    • An error occurred: The external table has no expected format. - Csharp
    • Everything works. (Win7, Excel 2010. The book is saved in the format 97-2003 (* .xls)). You can have the name of the table not Sheet1. - Murad
    • Now another error: The 'rem $' object was not found by the Microsoft Jet database engine. Check the existence of the object and the correctness of the name and path. Here is the file: rghost.net/41461981 Tell me what's wrong. - Csharp
    • Works with your file dl.dropbox.com/u/37689745/WindowsFormsApplication1.7z (studio 2012) - Murad

    Work through the data source schema. I throw this site from the working code of the project:

     DataTable COL = null; DataTable dtSchema = con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { }); DataTable columns = null; foreach (DataRow row in dtSchema.Rows) { ... COL = con.GetSchema("Columns", restrictions); //колонки ... } 

    and it’s gone, you can describe some select, then use it, for example: (I omitted the initialization of these)

     adapter = new OleDbDataAdapter(select, strConnection); dtExcel = new DataTable("Excel_Table"); 

    good luck

    There is a nuance - which version of Excel is parsed (by default, version 8 is running, it will parse without problems. Perhaps there will be errors with earlier versions)