Skip to content

Instantly share code, notes, and snippets.

@losophy
Last active May 24, 2021 13:15
Show Gist options
  • Save losophy/d336f71f1c582e0c8fa73ad8d9aba074 to your computer and use it in GitHub Desktop.
Save losophy/d336f71f1c582e0c8fa73ad8d9aba074 to your computer and use it in GitHub Desktop.
实现A1引用样式
#!/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