我在第 15 行收到此错误,我不知道为什么。有任何想法吗?似乎属性定义明确,所以我完全不知所措。任何帮助将非常感激。AttributeError:“NoneType”对象没有属性“Sheets”import win32com.clientimport openpyxlimport shutilimport os, subprocessdef Inny_Outy(): input = 'C:/Users/tyler/Desktop/Beef web/Queue' output = 'C:/Users/tyler/Desktop/Beef web/Finished' for filename in os.listdir(input): xl=win32com.client.Dispatch('Excel.Application') ini=xl.Workbooks.Open(input + '/' + filename) inb=xl.Workbooks.Open('C:/Users/tyler/Desktop/Beef Web/Export.xlsx') ini.Sheets('Sheet1').Range('A2:K100000').Copy() inb.Sheets('Export').Paste(inb.Sheets('Export').Range('A2')) inb.Close(True) ini.Close(True) CopyIn_run_macros() Out=xl.Workbooks.Open('C:/Users/tyler/Desktop/Beef Web/Finish.xlsx') add = ini.Sheets.Add(Before = None , After = ini.Sheets(ini.Sheets.count)) add.Name = "E1" add.Name = "231" add.Name = "BIMgen" Out.Sheets('E1').Range('A1:T100000').Copy() ini.Sheets('E1').Paste(ini.Sheets('E1').Range('A1')) Out.Sheets('BIMgen').Range('A1:H100000').Copy() ini.Sheets('BIMgen').Paste(ini.Sheets('BIMgen').Range('A1')) Out.Sheets('231').Range('A1:AG100000').Copy() ini.Sheets('231').Paste(ini.Sheets('231').Range('A1')) ini.Close(True) Out.Close(True) shutil.move(input + '/' + filename, output)def CopyIn_run_macros(): #Run macros xl=win32com.client.Dispatch('Excel.Application') BC=xl.Workbooks.Open('C:/Users/tyler/Desktop/Beef Web/Wall Types Live.xlsm') xl.Application.Run('Python2') EXP=xl.Workbooks.Open('C:/Users/tyler/Desktop/Beef Web/Export.xlsx') print("Importing Export To BeefCake....") EXP.Sheets('Export').Range('A2:K100000').Copy() BC.Sheets('Raw Export').Paste(BC.Sheets('Raw Export').Range('A12')) EXP.Close(True) print("Complete.") print("Running Macros....") xl.Application.Run('Python') print("Complete.")Inny_Outy()
1 回答
慕神8447489
TA贡献1780条经验 获得超1个赞
inb=xl.Workbooks.Open('C:/Users/tyler/Desktop/Beef Web/Export.xlsx')我猜这是返回 None 因为文件不存在,或者目录搞砸了。
添加回答
举报
0/150
提交
取消
