Take the 2-minute tour ×

I have a functionality which reads excel using OLEDB. I have captions on first 7 rows , then headers on 8th row, then data. So my requirement is to skip first three rows then consider 8th row as header and remaining as data.

I have tried ways for implementing this, but could not succeed, Can anyone provide a solution?

Regards Arus

share|improve this question
In my work I have written a method that shifts a datatable up, replacing column names with corresponding row values. I can post this if this solution suits you. –  Taosique Jan 3 at 8:49
add comment

1 Answer

public static void ShiftUp(DataTable Source, int Offset)
    if ((Offset <= 0) || (Offset > Source.Rows.Count))

    if (Offset > Source.Rows.Count)
        throw new Exception("Cannot shift DataTable up for more rows than it has.");

    string[] ColumnNames = new string[Source.Columns.Count];
    for (int i = 0; i < Source.Columns.Count; i++)
        object RowValue = Source.Rows[Offset - 1][i];
        if (RowValue != null)
            ColumnNames[i] = RowValue.ToString();
            ColumnNames[i] = String.Empty;
        Source.Columns[i].ColumnName = "F" + (i + 1).ToString();
        if (ColumnNames[i] != String.Empty)
            string NewColumnName = ColumnNames[i];
            if (Source.Columns.Contains(NewColumnName))
                int j = 0;
                    NewColumnName = ColumnNames[i] + j.ToString();
                while (Source.Columns.Contains(NewColumnName));
            Source.Columns[i].ColumnName = NewColumnName;
    for (int i = 0; i < Offset; i++)
share|improve this answer
add comment

Your Answer


