0
我遇到了一个问题,从一个Excel与python/flask运行一个宏。使用python运行宏Win32com,文件名Excel空间问题
当文件的名称上没有空格时,可以运行宏,如果文件中有空格,我不能运行它。
这里的PY文件
app.route('/process_done', methods=['POST'])
def runmacros():
run_macro("Main System FIndx.xlsm!Test_macro.Prueba","..\System\Main Test.xlsm")
return render_template('main.jade')
和函数的代码
def run_macro(macroname, filetorun):
pythoncom.CoInitialize()
xlApp = Dispatch('Excel.Application')
xlWb = xlApp.Workbooks.Open(filetorun)
xlSht = xlWb.WorkSheets(1)
xlApp.visible = True
xlApp.Application.Run(macroname)
xlWb.Saved = 0
xlWb.Save()
xlWb.Close(SaveChanges=True)
xlApp.application.Quit()
因此,如果文件重命名为“MainTest”当按下按钮模板的宏运行,但如果我所谓的“主测试”不起作用。
也许解决方案非常简单,但我可以找到它。
在此先感谢。
pd:当我尝试运行宏时显示问题,文件确实没有问题地打开。
编辑:
在xlApp.Application.Run蟒蛇解决
不需要全名,所以我改变主系统FIndx.xlsm Test_macro.Prueba为“Test_macro.Prueba”和作品! ! :d