Hello there:
I have a problem between IIS, Python and Excel, I can do everything with the IDE (visual studio) but when i do the same thing with the IIS web app the result is:
IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch) com_error: (-2147024891, 'Access is denied.', None, None)
Step i've already done:
-permission for write and read on C:\inetpub\wwwroot\MyWebSite (subfolders included)
-i checked the DCOM Excel permision,
i have some doubts about the webapp settings on the IIS manager, i have to add a webapplication (path and give a alias, etc?) and grant permissions to this app/folder?
On python i have to change something? the task is very simply: open the Excel Run the macro and that's it.
import os from MyAPP import app from flask import Flask, render_template, request, redirect, url_for, send_from_directory, after_this_request from werkzeug import secure_filename from win32com.client import Dispatch import pythoncom import upload from flask import send_file import StringIO @app.route('/testing') def test(): mc_test= 'Test_macro.Prueba' mc_test_run= r'C:\inetpub\wwwroot\MyWebSite\MyApp\Test.xlsm' run_macro(mc_test, mc_test_run) return 'macro done!' 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()
that's the code in few words, nothing special.
So, i need to allow python to execute the excel macro when the user enter to the webapp site or press the button.
Thanks in advance.
pd: i have Windows 8.1 and using python 2.7