Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
210
Access cell value based on column name instead of index on a worksheetrow object
posted

Using Infragistics.Documents.Excel.V16.1 Workbook, where in need to read a cell value based on the column name instead of the index value.

Currently, getting the cell values as below:

row.Cells[2].GetText()l

is there any way i could get in row.Cells["<ColName>"].GetText(), have gone through  the documentation , but couldn't find any. 

Other thing is get all the cell values of a particular row, i.e, on a worksheetrow object  in a single statement , instead of processing it through cell by cell using a loop.

Parents
No Data
Reply
  • 34810
    Offline posted

    Hello Sowmya,

    There does not exist an overload on the WorksheetRow.Cells collection that will allow you to index the value by anything other than the index of the cell at the moment. The best alternative I can recommend in this case is to utilize the GetCell method of the Worksheet object that owns the row/cell. This method accepts a cell address and will return the cell at that address. You will also need the index of the row, which you can get from its “Index” property. You can use code like the following to use this, where “sheet” is the Worksheet:

                WorksheetRow row = sheet.Rows[14];
                int index = row.Index;                       
    
                var value = sheet.GetCell("B" + index).Value;   

    As for getting all of the values from the row, there is nothing better than looping through the Cells collection in this case. If you would like to see a method implemented that returns a collection of the cell values or allows you to index the WorksheetRow.Cells collection by column name instead of index, I would recommend suggesting a new product idea for this. You can do this at the WPF Ideas Site, here. This will place you in direct communication with our product management teams who plan and prioritize upcoming features and development based on community and user feedback.

    Please let me know if you have any other questions or concerns on this matter.

Children