即使定义了属性,NoneType 错误?

我在第 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.")

Inny_Outy()


繁星淼淼
浏览 109回答 1
1回答

慕神8447489

        inb=xl.Workbooks.Open('C:/Users/tyler/Desktop/Beef Web/Export.xlsx')我猜这是返回 None 因为文件不存在,或者目录搞砸了。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python