This project has moved and is read-only. For the latest updates, please go here.

xl.Workbook() (pyvot) doesn't open an excell workbook

Apr 28, 2012 at 10:44 AM


I would like to create an excell workbook with pyvot as in this tutorial ( 
Pyvot is installed correctly because I can import it without an error. But when I do:

import xl

I  get this error:

Traceback (most recent call last):
  File "", line 1, in 
AttributeError: 'module' object has no attribute 'workbook'
>>> xl.Workbook()
Traceback (most recent call last):
  File "", line 1, in 
  File "C:\Python27\lib\site-packages\pyvot-0.1.2-py2.7.egg\xl\", line 91, in __init__
    excel = win32.gencache.EnsureDispatch('Excel.Application')
  File "C:\Python27\lib\site-packages\win32com\client\", line 529, in EnsureDispatch
    disp = win32com.client.Dispatch(prog_id)
  File "C:\Python27\lib\site-packages\win32com\client\", line 95, in Dispatch
    dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)
  File "C:\Python27\lib\site-packages\win32com\client\", line 108, in _GetGoodDispatchAndUserName
    return (_GetGoodDispatch(IDispatch, clsctx), userName)
  File "C:\Python27\lib\site-packages\win32com\client\", line 85, in _GetGoodDispatch
    IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch)
com_error: (-2147221005, 'Invalid class string', None, None)

I don't have Python tools for visual studio installed though. 
1. Do I need PTVS to work with pyvot?
2. Could lower versions of excell then excell 2010(e.g. excell 2007) work with pyvot?
3. Do I need to set anything up in excell to make it work with pyvot?
If the answer of one of the questions above did not explain why I couldn't make that code snippet work, what should I do to get it working correctly? 

Thank you!

Apr 30, 2012 at 6:45 PM

Unfortunately, you will need Excel 2010 for Pyvot to work.

May 3, 2012 at 3:49 PM
Edited May 3, 2012 at 3:52 PM

I installed Excel 2010. When I input the following in pythonwin32:

import xl

I get this NameError:

Traceback (most recent call last):
    File "<interactive input>", line 1, in <module>
NameError: name 'xl' is not defined

Any clue why?

Jan 11, 2013 at 12:15 PM
Edited Jan 11, 2013 at 12:56 PM

number 1: Restart the Python shell !

Number 2:


Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> from win32com.client import Dispatch
>>> excel = Dispatch("Excel.Application")
>>> excel.Visible=1
>>> wb = excel.Workbooks.Add()
>>> range = wb.Sheets[0].Range("A1")
>>> wb.ActiveSheet.Cells(1,1).value = "Skills Grow When Pride Is Swallowed!"

PS. This works fine with 2007. You don't need 2010.