Excel get values and header name RRS feed

  • Question

  • hi,i'm writing Excel add-in and i need to get values and header name of columns which contain value.

    Thank you

    Sunday, September 7, 2014 11:21 AM


  • Hi,

    Welcome to MSDN forum.

    Do you develop an Excel application level add-in through Visual Studio?

    Which language are you using?

    Suppose you are using Office Primary Interop Assemblies to work with Excel.

    If so, you need to loop all cells in all columns and check the value of every cell.

    I assume the first row means header, here is a sample for your reference:

    Excel.Worksheet ws = Globals.ThisAddIn.Application.ActiveSheet;
                for (int i = 2; i <= ws.UsedRange.Rows.Count;i++ )
                    for (int j = 2; j <= ws.UsedRange.Columns.Count; j++)
                        Excel.Range range = ws.Cells[i, j];
                        if (range.Value != null && Convert.ToString(range.Value).Trim().Length > 0)
                            //get first cell of this column as header name 
                            Excel.Range columnname = ws.Cells[1, j];



    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, September 10, 2014 2:09 AM