Python Excel 列名转换
2013-05-08 13:05
225 查看
def colname_to_num(colname):
if type(colname) is not str:
return colname
col = 0
power = 1
print len(colname)
for i in xrange(len(colname) - 1, -1, -1):
ch = colname[i]
print ch
col += (ord(ch) - ord('A') + 1 ) * power
power *= 26
print col-1
return col - 1
def colnum_to_name(colnum):
if type(colnum) != int:
return colnum
if colnum > 25:
ch1 = chr(colnum % 26 + 65)
ch2 = chr(colnum / 26 + 64)
print ch2+ch1
return ch2 + ch1
else:
print chr(colnum % 26 + 65)
return chr(colnum % 26 + 65)
if __name__ == "__main__":
colname_to_num("CU")
colnum_to_name(26)
if type(colname) is not str:
return colname
col = 0
power = 1
print len(colname)
for i in xrange(len(colname) - 1, -1, -1):
ch = colname[i]
print ch
col += (ord(ch) - ord('A') + 1 ) * power
power *= 26
print col-1
return col - 1
def colnum_to_name(colnum):
if type(colnum) != int:
return colnum
if colnum > 25:
ch1 = chr(colnum % 26 + 65)
ch2 = chr(colnum / 26 + 64)
print ch2+ch1
return ch2 + ch1
else:
print chr(colnum % 26 + 65)
return chr(colnum % 26 + 65)
if __name__ == "__main__":
colname_to_num("CU")
colnum_to_name(26)
相关文章推荐
- 数值转换成Excel列名
- python实现文本与Excel内容相互转换
- python 将txt文件转换为excel
- 将Excel中的字母列名转换成数字的算法
- 用Python3 编写excel和txt的转换工具
- 数值转换成Excel列名
- Excel列名 字母和数字的转换
- -------------------------数字转换成EXCEL列名---------------------------------
- python csv/txt转换成excel
- python将字符串格式日期转换为excel的日期格式
- python把Teslink导出的xml格式转换为excel
- EXCEL-横向数据转换成纵向数据-python脚本实现
- java中将数字转换成excel中列名
- Python实现将Excel转换成xml的方法示例
- Excel列名与数字的相互转换
- 保存一个将Excel里面的列名(A,B,C...)转换为索引号(1,2,3...)的方法
- excel列名和序列之间的转换
- LeetCode--Excel Sheet Column Number(Excel表格的列名转数字)Python
- Python 文本(txt) 转换成 EXCEL(xls)
- python 从excel中读取数据转换成json字符串