# -*- coding: utf8 -*-
import os
import sys
import re
def fix_excel():
from openpyxl import load_workbook
try:
wb = load_workbook("new.xlsx")#xls名字
except Exception, e:
print "[wzy] read_excel", str(e)
return
print "-----------------start----------------"
ws = wb.get_sheet_by_name("Sheet1")#分页
count = 0
for rownum, row_value in enumerate(ws.rows):#只统计A列
if rownum>=5854 and ws.cell(row = rownum + 1, column=1).value:
print 'rownum',rownum
a = ws.cell(row = rownum + 1, column=1).value.encode('utf-8')
a = a.decode('utf8')
results = re.findall(u'[\u4e00-\u9fa5]', a)
print "-----------------row-count1----------------",len(results)
count = count+len(results)
print "-----------------all-count----------------",count
if __name__ == '__main__':
fix_excel()
python统计excel某一列中文字数
于 2022-03-10 16:05:26 首次发布