Click here to Skip to main content
13,350,289 members (45,505 online)
Rate this:
Please Sign up or sign in to vote.
See more:
if we select an Excel sheet then how do we get the Excel Column Headers name
Posted 12-Aug-11 4:33am
Updated 24-Sep-17 21:58pm
Mika Wendelius 12-Aug-11 9:39am
What do you mean by column header names? Columns are named A, B, C... Could you elaborate more.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

public static Dictionary<string,int> GetColumnMapping(Excel.Worksheet ExcelSheet, int HeaderRowIndex , List<string> Headers, Dictionary<string,int> HeaderMapping)
            if (HeaderMapping != null)

            object misValue = System.Reflection.Missing.Value;

            Excel.Range HeaderRange = ExcelSheet.Rows[HeaderRowIndex , misValue];
            Excel.Range currentFind = null;

            foreach (string Header in Headers)
                currentFind = HeaderRange.Find(Header, misValue, Excel.XlFindLookIn.xlValues, Excel.XlLookAt.xlPart, Excel.XlSearchOrder.xlByColumns, Excel.XlSearchDirection.xlNext, false, misValue, misValue);
                if(currentFind != null)
                    HeaderMapping.Add(Header, currentFind.Column);

            return HeaderMapping;

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.180111.1 | Last Updated 25 Sep 2017
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100