How can i get the Cell address from excel

后端 未结 6 1130
遇见更好的自我
遇见更好的自我 2020-12-03 18:20

How can i get the Cell address from excel given a row and column number for example

row 2 and col 3 should return C2... Please help

6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-03 18:50

    Just an improvement, the col-- was in the wrong place

    static string GetCellAddress(int row, int col)
        {
            StringBuilder sb = new StringBuilder();
    
           do
            {
                col--;
                sb.Insert(0, (char)('A' + (col % 26)));
                col /= 26;
            } while (col > 0);
            sb.Append(row);
            return sb.ToString();
        }
    

提交回复
热议问题