Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
路径存在于Excel Python代码中_Python_Excel_Python 2.7 - Fatal编程技术网

路径存在于Excel Python代码中

路径存在于Excel Python代码中,python,excel,python-2.7,Python,Excel,Python 2.7,我正在处理一个目录代码,如果文件存在于指定的路径中,它将在excel上运行一个宏。对于我的else,如果路径不存在,则文件将从I驱动器的主副本保存到F驱动器,然后运行代码。我该怎么做 import os import os.path PATH='F:\Ten Year Load Forecasts 2017-2026.xlsm' Master_Copy='I:\Ten Year Load Forecasts 2017-2026.xlsm' if os.path.isfile(PATH) an

我正在处理一个目录代码,如果文件存在于指定的路径中,它将在excel上运行一个宏。对于我的else,如果路径不存在,则文件将从I驱动器的
主副本保存到
F
驱动器,然后运行代码。我该怎么做

import os
import os.path

PATH='F:\Ten Year Load Forecasts 2017-2026.xlsm'
Master_Copy='I:\Ten Year Load Forecasts 2017-2026.xlsm'

if os.path.isfile(PATH) and os.access(PATH, os.R_OK):
    print "File exists and is readable"
    xlApp = win32com.client.DispatchEx('Excel.Application') # Running Excel
    xlsPath = os.path.expanduser('F:\Ten Year Load Forecats\Ten Year Load Forecasts 2017-2026.xlsm)# Reading xlsm file
    wb = xlApp.Workbooks.Open(Filename=xlsPath) # Opening file
    xlApp.Run('csvfile3')# Running macro---- csvfile3 is the macro name. It is under the "csv" module in the VBA editor
    wb.Save()
    xlApp.Quit()

else:
    "Save Master_Copy to Path"
    "Repeat Function From above with running macro"                         

所以你问“我怎么复制文件?”?看一看,我尝试使用该方法,但我总是收到“权限被拒绝”消息。请确保您使用的是原始字符串,否则由于转义序列,此代码将在某个时候中断:@Danny,好吧。也许这会很有用:所以你在问“如何复制文件?”?看一看,我尝试使用该方法,但我总是收到“权限被拒绝”消息。请确保您使用的是原始字符串,否则由于转义序列,此代码将在某个时候中断:@Danny,好吧。也许这会有用: