首页 > 代码库 > 统计excel表格的py
统计excel表格的py
# -*- coding: utf-8 -*-
import xlrd
import xlwt
import os
import sys
reload(sys)
sys.setdefaultencoding(‘utf8‘)
xlrd.Book.encoding = "gbk"
type=sys.getfilesystemencoding()
s = os.sep
counter = 0
chipan = "e:"
wenjianjia = "hh"
wenjianjia = wenjianjia.decode(‘utf-8‘).encode(type)
root = chipan + s + wenjianjia + s
for root,dirs,files in os.walk(root):
for dir in dirs:
os.path.join(root,dir).decode(‘gbk‘).encode(‘utf-8‘)
for file in files:
filename = os.path.join(root,file).decode(‘gbk‘).encode(‘utf-8‘)
if (os.path.splitext(filename)[1] == ‘.xls‘)or(os.path.splitext(filename)[1] == ‘.xlsx‘):
try:
print filename.decode(‘utf-8‘).encode(type)
uipath = unicode(filename, "utf8")
data = http://www.mamicode.com/xlrd.open_workbook(uipath)
table = data.sheets()[0]
assert isinstance(table.nrows, object)
nrows = table.nrows
counter += nrows
print counter
except:
print "error"
统计excel表格的py