In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
[environment]
Windows 10, Python 3.6, using third-party package openpyxl.
[config.ini]
[config]; Excel file name XlFile=D:\ test\ test.xlsx; form name SheetName=Sheet1 to be processed
[trim_cell_for_excel.py]
# encoding: utf-8# author: walker# date: 2018-09-2 blank summary: blank import osimport sysimport timeimport openpyxlfrom configparser import ConfigParserStartTime = time.time () cur_dir_fullpath = os.path.dirname (os.path.abspath (_ _ file__)) XlFile = r''SheetName = r''def ReadConfig (): r "read configuration file"global XlFile" before and after removing the string in the Excel cell SheetName cfg = ConfigParser () cfgFile = os.path.join (cur_dir_fullpath, ringing config.ini') if not os.path.exists (cfgFile): input (cfgFile + 'not found') sys.exit (- 1) with open (cfgFile) Mode='rb') as f: content = f.read () if content.startswith (b'\ xef\ xbb\ xbf'): # remove the utf8 bom header content = content [3:] cfg.read_string (content.decode ('utf8')) if not cfg.sections (): input (' Read config.ini failed...') Sys.exit (- 1) XlFile = cfg.get ('config',' XlFile'). Strip () if not os.path.exists (XlFile): print ('Error: not exists% s'% XlFile) sys.exit (- 1) print ('XlFile:% s'% XlFile) SheetName = cfg.get ('config' 'SheetName') .strip () print (' SheetName:% s'% SheetName) print ('Read config.ini succeeded') def Main (): print ('Load% s...'% XlFile) wb = openpyxl.load_workbook (XlFile) print ('Load% s successors'% XlFile) sheet = wb [SheetName] for i in range (1, sheet.max_row + 1): for j in range (1) Sheet.max_column + 1): rawVal = sheet.cell (I, j). Value if not isinstance (rawVal, str): continue sheet.cell (I J). Value = rawVal.strip () print ('Save% s...'% XlFile) wb.save (XlFile) print ('Save% s clients'% XlFile) if _ _ name__ = ='_ main__': ReadConfig () Main () print ('Time total:% .2fs'% (time.time ()-StartTime)) print ('Current time:% s'% time.strftime ( '% Y-%m-%d% HRV% MRV% S' Time.localtime (time.time ()
[related reading]
Working with Excel Files in Python
* walker * *
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.