How can i get the Cell address from excel

后端 未结 6 1133
遇见更好的自我
遇见更好的自我 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条回答
  •  被撕碎了的回忆
    2020-12-03 18:55

    I'm using zero-based row and column index. So I had to adapt the code of prior answers to the following. It took some trial and error to get this right for all possible addresses i.E. A1, Z2, AA2, ZZ10, ...

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

提交回复
热议问题