Feature request: Use column header to reference a column

Hi Adrian,

As discussed by email recently, I'd like to enter a wish for a future release of FlexCel.

At the moment, one can only GetCellValue(...) by using row and column numbers. In many use cases, the position of the column is unknown, or is dynamic. For reference for others who might have this use-case, here is the code you suggested I use to create a ColumnMap to get the column position by name:

//Build a dictionary to lookup columns by "name" instead of position
 const int headerRow = 1;
 var ColumnMap = new Dictionary<string, int>();
     for (int cIndex = 1; cIndex <= xlsf.ColCountInRow(headerRow); cIndex++)
         int XF = -1;
         var header = xlsf.GetCellValueIndexed(headerRow, cIndex, ref XF);
         var headerString = TFlxNumberFormat.FormatValue(header, xlsf.GetFormat(XF).Format, xlsf);
         ColumnMap[headerString] = xlsf.ColFromIndex(headerRow, cIndex);

This works perfectly, but if you accept, it would be nice to have a similar functionality built-in.

Thanks for your help and great support.


I've moved this post to the feature requests category, which is the place for it :slight_smile:

To be honest, I am not 100% convinced it makes sense to add this code to the core FlexCel, because while I agree it can be useful, we also try to keep the code as lean as possible (and we aren't doing a great job at this...) There are thousands of little code snippets like this that could be added, but at the end it just makes it more difficult to find anything. I think this could be better done as an example, I'll see if we can add it. Thanks for posting this here, indeed it can be useful for a lot of other people. As said, I'll see if we can add it to the examples.