[python-win32] Standard Excel add-in does not load?

Blair Hall b.hall@irl.cri.nz
Fri, 21 Mar 2003 16:42:10 +1200


If someone could help me understand what to do here, I
would appreciate it.  I am trying to find a way to write
a complex number into an Excel cell from a Python program.

To write a complex number to an Excel cell one writes :
	=COMPLEX(a,b)
the function is supplied by a standard add-in
'Analysis Toolpak'.

Now here's the problem. I have a simple script:

import win32com.client
import pythoncom
x = win32com.client.Dispatch('Excel.Application')
x.Visible = 1
wb = x.WorkBooks.Add()
x.Cells.Item(1,1).Formula = '=COMPLEX(1,2)'
x.Quit()
x = None

Which gets an instance of Excel and writes '1+2i'
into the first cell and then closes.

This script will only work correctly if the Excel has been opened
BEFORE the script runs (ie by hand). If I let the script
open Excel then the insertion of a complex number fails.

The cell shows '#NAME', which suggets that
the add-in has not been loaded properly.
Furthermore, I cannot use (manually) any of the functions
that belong to that add-in.

A quick check on the Excel menu bar indicates that
the add-in is selected. However, if I unselect the add-in and then 
re-select it,
then I can get the first cell to accept the COMPLEX formula.

To summarize: it appears that the standard add-in 'Analysis Toolpak'
is not loaded correctly when Excel is activated by the script above.

Can anyone tell me why?

I am trying this on Windows95 with Excel97, Python 2.2.2 and have win32all-150