Finding column by column header

Posted by: stylish16 on 8 September 2017, 2:53 pm EST

  • Posted 8 September 2017, 2:53 pm EST

    Hello all,

    I want to find column index in a spreadsheet by giving column header.

    How can i do that ? 

    I don't want hard coded column indexes such as 1, 2,....

    Please Help me.

    Thanks in advance.

     

  • Replied 8 September 2017, 2:53 pm EST

    Hello,


    You can define your own method to get the ColumnIndex from the ColumnName, in which you would need to loop through all the columns in the sheet and compare the labels of the columns to find the appropriate column index. Later, you can call this method by passing the ColumnName and the sheet in which to look for the ColumnIndex. Here is the code to implement the same:


          public int GetColumnIndexFromColumnName(string ColumnName, FarPoint.Win.Spread.SheetView sv)
            {
                int colindex =0;
                for (int c = 0; c < sv.ColumnCount; c++)
                {
                    if (sv.ColumnsCoffee.Label == ColumnName)
                    {
                        colindex = c;
                        break;
                    }
                }
                return colindex;
            }


    Hope it will help you. Please let me know if you have any queries further.


    Thanks,


    Manpreet Kaur

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels