如何从Cell Reference获取索引?

时间:2019-06-27 15:25:40

标签: c# excel

下面的代码对于A-Z列非常适用。但是不适用于从a-z到aa,ab,...的excel,当z col再次超过时,它会从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;
}

0 个答案:

没有答案
相关问题