gpt4 book ai didi

python - NoneType 即使定义了属性也会出错?

转载 作者:行者123 更新时间:2023-12-01 06:27:07 24 4
gpt4 key购买 nike

我在第 15 行收到此错误,但我不明白为什么。有任何想法吗?看来属性已经明确定义了,所以我完全不知所措。任何帮助将非常感激。AttributeError:“NoneType”对象没有属性“Sheets”

import win32com.client
import openpyxl
import shutil
import os, subprocess

def 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.")
print("Exporting BeefCake Data....")
FIN=xl.Workbooks.Open('C:/Users/tyler/Desktop/Beef Web/Finish.xlsx')
BC.Sheets('E1 Final').Range('A1:T100000').Copy()
FIN.Sheets('E1').Paste(FIN.Sheets('E1').Range('A1'))
BC.Sheets('BIMgen 2.0').Range('A1:H100000').Copy()
FIN.Sheets('BIMgen').Paste(FIN.Sheets('BIMgen').Range('A1'))
BC.Sheets('Goodall Build').Range('A1:AG100000').Copy()
FIN.Sheets('231').Paste(FIN.Sheets('231').Range('A1'))
FIN.Close(True)
print("Complete.")
del xl

Inny_Outy()

最佳答案

        inb=xl.Workbooks.Open('C:/Users/tyler/Desktop/Beef Web/Export.xlsx')

我猜这会返回 None,因为该文件不存在,或者目录中出现了一些困惑。

关于python - NoneType 即使定义了属性也会出错?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60082229/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com