Found code to load Excel data into the DataGridView table:

private void завантажитиToolStripMenuItem_Click_1(object sender, EventArgs e) { { { OpenFileDialog ofd = new OpenFileDialog(); ofd.DefaultExt = "*.xls;*.xlsx"; ofd.Filter = "Microsoft Excel (*.xls*)|*.xls*"; ofd.Title = "Выберите документ для загрузки данных"; if (ofd.ShowDialog() != DialogResult.OK) { MessageBox.Show("Вы не выбрали файл для открытия", "Загрузка данных...", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } String constr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + ofd.FileName + ";Extended Properties='Excel 12.0 XML;HDR=YES;IMEX=1';"; System.Data.OleDb.OleDbConnection con = new System.Data.OleDb.OleDbConnection(constr); con.Open(); DataSet ds = new DataSet(); DataTable schemaTable = con.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" }); string sheet1 = (string)schemaTable.Rows[0].ItemArray[2]; string select = String.Format("SELECT * FROM [{0}]", sheet1); System.Data.OleDb.OleDbDataAdapter ad = new System.Data.OleDb.OleDbDataAdapter(select, con); ad.Fill(ds); DataTable dt = ds.Tables[0]; con.Close(); con.Dispose(); dataGridView1.DataSource = dt; } 

Everything works, but to the already prepared table, DataGridView adds another table with data offset to the right.

Closed due to the fact that off-topic participants 0xdb , Kromster , Andrei NOP , Viktor Tomilov , AK Jan 31 'at 11:52 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • “Questions asking for help with debugging (“ why does this code not work? ”) Should include the desired behavior, a specific problem or error, and a minimum code for playing it right in the question . Questions without an explicit description of the problem are useless for other visitors. See How to create minimal, self-sufficient and reproducible example . " - 0xdb, Kromster, Andrei NOP, Viktor Tomilov, AK
If the question can be reformulated according to the rules set out in the certificate , edit it .

    0