In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-19 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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.