I am trying to perform some batch operations on IIS using win32com and Microsoft Excel. I want to open an excel file with DCOM, manipulate it and then save it as a pdf. The following code runs fine on my development machine (64 bit windows 7).
# views.py
class ConvertFileView(View):
def get(self,request):
"""Convert the selected file"""
output = "c://docs/somefile.pdf"
input = "c://docs/input.xlsx"
#Open excel and open input.xlsx
excel = win32com.client.gencache.EnsureDispatch('Excel.Application')
excel.DisplayAlerts = False
excel.Visible = False
workbook = excel.Workbooks.Open(input)
# File manipulation here
workbook.ExportAsFixedFormat(Type=0,Filename=output)
excel.Quit()
del excel
return HttpResponse("Done")
However when I load the webpage through IIS get the following error.
com_error at /converter/convert/114/
(-2147024891, 'Access is denied.', None, None)
Traceback:
C:\GoogleDrive\websites\...\python\apps\converter\views.py in get
141. excel = win32com.client.gencache.EnsureDispatch('Excel.Application')
C:\python27\lib\site-packages\win32com\client\__init__.py in Dispatch
95. dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)
C:\python27\lib\site-packages\win32com\client\dynamic.py in _GetGoodDispatchAndUserName
114. return (_GetGoodDispatch(IDispatch, clsctx),
C:\python27\lib\site-packages\win32com\client\dynamic.py in _GetGoodDispatch
IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch)
This works well on my development machine. This error occurs when I load the webpage through IIS on Windows Server 2008. I am assuming that python does not have the adequate permissions to launch excel on IIS. Is there anyway I can give python/DCOM permissions to run excel?