Get the Column Index of a Cell in Excel using OpenXML C#

前端 未结 8 1838
北恋
北恋 2020-12-03 17:32

I\'ve been looking around for a while now and cannot seem to find out how to do this. I\'ve got an excel sheet, which I\'m reading using OpenXML. Now the normal thing would

8条回答
  •  执念已碎
    2020-12-03 18:07

    Small is beautifull

    int ColumnIndex(string reference)
    {
      int ci=0;
      reference=reference.ToUpper();
      for (int ix = 0; ix < reference.Length && reference[ix] >= 'A';ix++ ) 
           ci = (ci * 26) + ((int)reference[ix] - 64);
      return ci;
    }
    

提交回复
热议问题