【环境】
Windows 10 下,Python 3.6,使用第三方包 openpyxl。
【config.ini】[config]
; Excel 文件名
XlFile=D:\test\test.xlsx
; 需处理的表单名
SheetName=Sheet1
【trim_cell_for_excel.py】# encoding: utf-8
# author: walker
# date: 2018-09-26
# summary: 去除 Excel 单元格内字符串前后的空白
import os
import sys
import time
import openpyxl
from configparser import ConfigParser
StartTime = time.time()
cur_dir_fullpath = os.path.dirname(os.path.abspath(__file__))
XlFile = r''
SheetName = r''
def ReadConfig():
r""" 读取配置文件 """
global XlFile, SheetName
cfg = ConfigParser()
cfgFile = os.path.join(cur_dir_fullpath, r'config.ini')
if not os.path.exists(cfgFile):
input(cfgFile + ' not found')
sys.exit(-1)
with open(cf