Documenting a real-world requirement, most now use the XLRD\XLWT module, but their functionality does not meet my needs, so the combination of xlwings and win32com modules is used.
# -*- coding: utf-8 -*- import xlwings as xwfrom Win32com.client import dispatchimport rexl = dispatch ("Excel.Application") XL. Visible = truewb = xl. Workbooks.Open ("D:\MyConfiguration\Desktop\ Computational Manpower. xlsx") sh = wb. Sheets ("Sheet1") Wbv = xw. Book ("D:\MyConfiguration\Desktop\ Computational Manpower. xlsx") Def printvalue (test,i): if ' human ' in test: a = test.split (' Human ') [1:][0] if a == ': b = test.split (' Human ') [0] if '. ' in b[-2:]: return b[-3:] elif '. ' in b[-3:]: return b[-4:] else: return re.findall (R "\d+\.? \d* ", a) [0] elif '. ' in test[-2:]: return test[-3:] elif '. ' in test[-3:]: return test[-4:] elif (Sh. Cells (i,2). value== ' rest '): return 0 else: if ': ' in test: returnlist = [' woring ', Test.split (': ') [1:][0]] return returnlist else: returnlist = [' woring ', test] return returnlistfor i In range (2,100): try: comment = sh. Cells (i,2). Comment.text () valuetype = r "<class ' list ' > " if STR (Type (Printvalue (comment,i)))!=valuetype: xw. Range (' C ' +str (i)). Value = printvalue (Comment,i). Strip () else: xw. Range (' C ' +str (i)) .color = (255,0,0) xw. Range (' C ' +str (i)). Value = printvalue (Comment,i) [1].strip () except exception as e: if (Sh. Cells (i,2). value== ' rest '): xw. Range (' C ' +str (i)) .value = ' 0 ' continue elif (Sh. Cells (i,1). Value==none and sh. Cells (i,2). Value==none): break elif (Sh. Cells (i,2). Value==none): xw. Range (' C ' +str (i)) .value = ' 0 ' continue else: xw. Range (' C ' +str (i)) .value = ' 1 ' continue wbv.save ()
Read the contents of the Excel callout, write it in the following cell, and filter the contents to a certain extent
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/8B/92/wKiom1hRIDKwyPklAABWoolh9O0163.png "style=" float: Left; "title=" QQ picture 20161214183359.png "alt=" Wkiom1hridkwypklaabwoolh9o0163.png "/>
This article is from my blog blog, so be sure to keep this source http://10552290.blog.51cto.com/10542290/1882777
Python operations Excel