Quantitative Analysis
Parallel Processing
Numerical Analysis
C++ Multithreading
Python for Excel
Python Utilities
Services
Author

I. Motivation and design (PFE).
II. Installation of the Python for Excel.
III. Tutorial introduction into the Python for Excel.
IV. PFE Programmer's reference.
1. Direct access to Excel API.
2. Lower level access to Excel API.
3. Event trapping (PFE).
4. Configuration files (PFE).
A. Controlling individual workbook.
B. ThisWorkbook (PFE).
C. Initialization of add-in namespace.
D. Implementation of ExcelListener.
E. Script execution in response to activation of the ControlShell.
F. Finalization of the add-in.
Index. Contents.

Controlling individual workbook.


given workbook MyTestWorkbook.xls needs some dynamic functionality.


Figure

If the PFE is installed then such functionality may be provided by placing a Python script file MyTestWorkbook.pfe into the same directory.


Figure

Note that the script file MyTestWorkbook.pfe has the same name and the "pfe" extension.

If the Excel application opens the MyTestWorkbook.xls then the Python for Excel would execute the MyTestWorkbook.pfe. The execution would happen in-process with Excel. The vba module and the predefined objects Application and ExcelListener would be accessible in the script. The script might allocate some global variables, alter contents of the workbook and install event handlers. Such organization permits imposing arbitrary functionality on the workbook. It also closely resembles the VBA for Excel's way of controlling the Excel workbooks.

If the "pfe" scripts does not allow any exceptions to propagate to the highest Python level then the ControlShell does not have to activate. However, it does pop up in the event of exception. At that moment the pdb module is already imported. Hence, the user may switch to the add-in shell and execute the command "pdb.pm()" to start the postmortem debugging. If the programmer wishes to override such behavior then the sys.stderr should be replaced.

All local variables allocated in the "pfe" script disappear after the pfe script finishes. The programmer may use the "global" keyword to hold the data that should persist after the script finishes. The "import" directives should be placed inside function bodies.





Index. Contents.


















Copyright 2007