【查找excel里面所有汉字的内容】

如题

import openpyxl
import os
import sys

from const import source_path
from const import target_path
from const import configList_path

from const import out_path

def creatXml():

    fileContent = ''
    #遍历所有xlsx
    for dir in os.listdir(source_path):
        child = os.path.join(source_path, dir)
        if(child.find('~') != -1): continue
        if os.path.isfile(child):
            #打开一个workbook
            workbook = openpyxl.load_workbook(child)
            #print(dir.split(".")[0])
            #拿到所有sheet
            sheets = workbook.sheetnames
            #print(sheets)
            
            for i in range(len(sheets)):
                #针对每一个sheet做操作
                if(str(sheets[i]).find('#') != -1):
                    continue
                sheet = workbook[sheets[i]]
                #print("表名:%s" % sheet)
                #print("列数:%d" % sheet.max_column)
                #print("行数:%d" % sheet.max_row)
                
                for r in range(1, sheet.max_column + 1):
                    for s in range(4, sheet.max_row + 1):
                        cell = sheet.cell(row=s,column=r).value
                        if(cell is None): continue
                        if(isinstance(cell,str)):
                            if(cell.find('#') != -1): continue
                            #print(cell)
                            for ch in cell:
                                if ch >=  '一' and ch <= '龥':
                                    print(ch)
                                    fileContent += ch
    fo = open(out_path, "wb")
    fo.write(fileContent.encode('utf-8'))
    fo.close()
                    
            

你可能感兴趣的:(【查找excel里面所有汉字的内容】)