0

This code below works perfectly fine for column A-Z. but it does not work for excel that exceeds a-z to aa,ab,... when z col exceed again it returns index from 0....

private static int CellReferenceToIndex(Cell cell)
{
    int index = 0;
    string reference = cell.CellReference.ToString().ToUpper();
    foreach (char ch in reference)
    {
        if (Char.IsLetter(ch))
        {
            int value = (int)ch - (int)'A';
            index = (index == 0) ? value : ((index + 1) * 26) + value;
        }
        else
            return index;
    }
        return index;
}
  • 1
    https://stackoverflow.com/questions/667802/what-is-the-algorithm-to-convert-an-excel-column-letter-into-its-number – EylM Jun 27 '19 at 15:34
  • 4
    Possible duplicate of [What is the algorithm to convert an Excel Column Letter into its Number?](https://stackoverflow.com/questions/667802/what-is-the-algorithm-to-convert-an-excel-column-letter-into-its-number) – cybernetic.nomad Jun 27 '19 at 15:36

0 Answers0