Python 3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:57:54) [MSC v.1924 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> #coding = utf-8
>>> import win32com
>>> from win32com.client import Dispatch,constants
>>> import os
>>> import re
>>> from datetime import datetime
>>> cells_value = [[0 for i in range(17)]for i in range(1001)]
>>>
>>> def getScriptPath():
... nowpath = os.path.split(os.path.realpath(r"C:\Users\Administrator\AppData\Local\Programs\Python\Python38"))[0]
... return nowpath
...
>>> #表格讀取函式
>>>
>>> def fun3_7_2():
... app = win32com.client.Dispatch("KWPS.Application")
... app.Visible = 0
... app.DisplayAlerts = 0
... WorkBook = app.Workbooks.Open(getScriptPath()+"\\楊林戴溝村.xlsx")
... sheet = WorkBook.Worksheets("Sheet1")
... for x in range(1001):
... for y in range(17):
... cell_value[x][y].append(sheet.Cells(x+1,y+1).Value)
... WorkBook.Close()
... app.Quit()
...
>>> #表格寫入函式
>>>
>>> def xieru(x1,y1):
... app = win32com.client.Dispatch("KWPS.Application")
... app.Visible = 0
... app.DisplayAlerts = 0
... WorkBook = app.Workbooks.Open(getScriptPath()+"\\楊林戴溝村1.xlsx")
... sheet = WorkBook.Worksheets("Sheet1")
... sheet.Cells(x1+1,y1+1).Value = cells_value[x1][y1]
... WorkBook.Close()
... app.Quit()
...
>>> #資料處理函式
>>>
>>> def chuli():
... for x in range(1001):
... if cells_value[x][9] == re.search(r"江蘇省阜寧縣吳灘鎮戴溝村一組.*?號",cells_value[x][9]):
... for y in range(17):
... xieru(x,y)
... for x in range(1001):
... if cells_value[x][9] == re.search(r"江蘇省阜寧縣吳灘鎮戴溝村二組.*?號",cells_value[x][9]):
... for y in range(17):
... xieru(x,y)
... for x in range(1001):
... if cells_value[x][9] == re.search(r"江蘇省阜寧縣吳灘鎮戴溝村三組.*?號",cells_value[x][9]):
... for y in range(17):
... xieru(x,y)
... for x in range(1001):
... if cells_value[x][9] == re.search(r"江蘇省阜寧縣吳灘鎮戴溝村四組.*?號",cells_value[x][9]):
... for y in range(17):
... xieru(x,y)
... for x in range(1001):
... if cells_value[x][9] == re.search(r"江蘇省阜寧縣吳灘鎮戴溝村五組.*?號,cells_value[x][9]"):
... for y in range(17):
... xieru(x,y)
... for x in range(1001):
... if cells_value[x][9] == re.search(r"江蘇省阜寧縣吳灘鎮戴溝村六組.*?號",cells_value[x][9]):
... for y in range(17):
... xieru(x,y)
... for x in range(1001):
... if cells_value[x][9] == re.search(r"江蘇省阜寧縣吳灘鎮戴溝村七組.*?號",cells_value[x][9]):
... for y in range(17):
... xieru(x,y)
... for x in range(1001):
... if cells_value[x][9] == re.search(r"江蘇省阜寧縣吳灘鎮戴溝村八組.*?號",cells_value[x][9]):
... for y in range(17):
... xieru(x,y)
... for x in range(1001):
... if cells_value[x][9] ==re.search(r"江蘇省阜寧縣吳灘鎮戴溝村九組.*?號",cells_value[x][9]):
... for y in range(17):
... xieru(x,y)
... for x in range(1001):
... if cells_value[x][9] == re.search(r"江蘇省阜寧縣吳灘鎮戴溝村十組.*?號",cells_value[x][9]):
... for y in range(17):
... xieru(x,y)
...
>>> if __name__ == "__main__":
... starttime = datetime.now()
... fun3_7_2()
... chuli()
... endtime = datetime.now()
... total_time = (endtime - starttime).seconds
... print(">>>成功錄入資訊{}條,總共耗時{}秒!".format(len(cells_value),total_time))
... os.system("pause")
...
Traceback (most recent call last):
File "<stdin>", line 3, in <module>
File "<stdin>", line 5, in fun3_7_2
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\win32com\client\dynamic.py", line 527, in __getattr__
raise AttributeError("%s.%s" % (self._username_, attr))
AttributeError: KWPS.Application.Workbooks
>>>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/8659.html
上一篇:python腳本運行沒有任何提示
