I have an Excel wherein i want to get the column number for eg the below image :
In the above image , i know that the records will appear on the 1st row , but i am unsure of the Column number. In above example the column value : "Quantity" appears on "D1". I know the row number how can i find the column number ("D" in the above case) using OPEN XML, as the column name quantity might appear anywhere in the excel and i need to find the corresponding values of only quantity.
Best Answer
Unfortunately there's not a single method you can call to find the correct cell. Instead you'll need to iterate over the cells to find the matching text. To complicate things slightly, the value in the cell is not always the actual text. Instead strings can be stored in the
SharedStringTablePart
and the value of the cell is an index into the contents of that table.Something like the following should do what you're after:
This can then be called like this:
If you just want
D
rather thanD1
you can use a simpleregex
to remove the numbers:And then use it like this: