How to delete the first records of an excel in c #?

0

I am trying to load the data from an excel to datagridview, and this is my result of the load.

my question is how to eliminate those Column1, Column2, Column3 .. etc .. and that my result is the same as product id, unit of measure, key, etc. be the names of the datagridview columns.

this is the excel .. original

I await your answer .. thank you ..

This is the code, it should be mentioned that I have not done any logic, I have only made the load to the grid.

private void btnExaminar_Click(object sender, EventArgs e)
        {
            using (OpenFileDialog ofd = new OpenFileDialog() { Filter = "Excel WorkBooks|*xlsx|Excel WorkBooks 1997-2003|*xls", ValidateNames = true })
            {
                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    try
                    {
                        FileStream fs = File.Open(ofd.FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                        IExcelDataReader reader;
                        if (ofd.FilterIndex == 1)
                        {
                            reader = ExcelReaderFactory.CreateOpenXmlReader(fs);// leer archivos excel xlsx
                        }
                        else
                        {
                            reader = ExcelReaderFactory.CreateBinaryReader(fs);// leer archivos excel xls

                        }
                        result = reader.AsDataSet(new ExcelDataSetConfiguration()
                        {
                            UseColumnDataType = true,
                            ConfigureDataTable = (tableReader) => new ExcelDataTableConfiguration()
                            {
                                UseHeaderRow = true
                            }
                        });//**
                           //  cbCarga.Items.Clear();
                          dgvExcel.DataSource = result.Tables[1];
                    }
                    catch (Exception ex)
                    {
                        if (!(ex is FileNotFoundException || ex is ArgumentException))
                        {
                            throw;
                        }
                        Console.WriteLine(ex.Message);
                        return;
                    }
                }

            }
        }
    
asked by JuanL 02.05.2018 в 18:34
source

1 answer

1

What I think you have is that you have already defined a header in your datagridview then when you insert the other information leaves it there, c# has a property called ColumnHeaderVisible place it in false

    
answered by 02.05.2018 / 19:39
source