Last active
May 24, 2021 13:15
-
-
Save losophy/d336f71f1c582e0c8fa73ad8d9aba074 to your computer and use it in GitHub Desktop.
实现A1引用样式
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
#-*- coding: UTF-8 -*- | |
def getA1Notation(num): | |
if num == 0 : | |
print('A') | |
notations = [] | |
alphabetNum = 26 | |
while num != 0: | |
notation = (num-1) % alphabetNum | |
num = (num-1)/alphabetNum | |
notations.append(chr(notation+ord('A'))) | |
A1Notation = "" | |
for notation in reversed(notations): | |
A1Notation = A1Notation + notation | |
return A1Notation | |
if __name__ == "__main__": | |
print(getA1Notation(703)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment