代码上
#
-*- coding: gbk -*-
# 对应参考excel(obj)
# 提供访问excel 参考 sql 访问接口
# excelAction.py "G:\Documents and Settings\ch\桌面\非四大总计.xls" "A,C,B" "|"
from pyExcelerator import *
import sys
txls = parse_xls(sys.argv[ 1 ])
findcols = sys.argv[ 2 ].split( ' , ' )
tsplit = " %s " % (sys.argv[ 3 ])
bmug = lambda str : unicode(str).encode( " utf8 " )
def cfsize(cha):
if len(cha) == 1 :
return ord(cha) - ord( ' A ' )
else :
fsize = 0
fnum = cfsize( ' Z ' ) + 1
cc = list(cha)
for tnum in range(len(cc)):
fsize += fnum * tnum + cfsize(cc[tnum])
return fsize
for tnum in range(len(txls)) :
try :
sheetname = txls[tnum][0]
sheetdata = txls[tnum][ 1 ]
for tnum in range(max([tmp[0] for tmp in sheetdata])):
try :
stmp = str(tnum + 1 ) + tsplit
for tmp in findcols :
stmp += sheetdata[(tnum,cfsize(tmp))] + tsplit
print stmp
except :
print sys.exc_info()[0]
pass
except :
print sys.exc_info()[0]
pass
print ' close '
本文转自博客园刘凯毅的博客,原文链接:py excel 文本化,如需转载请自行联系原博主。
# 对应参考excel(obj)
# 提供访问excel 参考 sql 访问接口
# excelAction.py "G:\Documents and Settings\ch\桌面\非四大总计.xls" "A,C,B" "|"
from pyExcelerator import *
import sys
txls = parse_xls(sys.argv[ 1 ])
findcols = sys.argv[ 2 ].split( ' , ' )
tsplit = " %s " % (sys.argv[ 3 ])
bmug = lambda str : unicode(str).encode( " utf8 " )
def cfsize(cha):
if len(cha) == 1 :
return ord(cha) - ord( ' A ' )
else :
fsize = 0
fnum = cfsize( ' Z ' ) + 1
cc = list(cha)
for tnum in range(len(cc)):
fsize += fnum * tnum + cfsize(cc[tnum])
return fsize
for tnum in range(len(txls)) :
try :
sheetname = txls[tnum][0]
sheetdata = txls[tnum][ 1 ]
for tnum in range(max([tmp[0] for tmp in sheetdata])):
try :
stmp = str(tnum + 1 ) + tsplit
for tmp in findcols :
stmp += sheetdata[(tnum,cfsize(tmp))] + tsplit
print stmp
except :
print sys.exc_info()[0]
pass
except :
print sys.exc_info()[0]
pass
print ' close '