3

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?

Max Ferguson
  • 676
  • 1
  • 7
  • 25
  • Same problem here. Did you find the solution? Please let me know if you did. Thanks – Aashiq Hussain Feb 11 '14 at 00:43
  • From memory this was an issue with the access permissions for the Excel.Application DCOM object, as imposed by the operating system. See http://stackoverflow.com/questions/12974576/what-do-the-different-dcom-com-security-settings-mean for more details – Max Ferguson Jan 07 '16 at 03:50

0 Answers0