PyXLL The Python Excel Add-In
  • Product
    • Features
    • Get Started
    • Request Demo
    • Download
  • Pricing
  • Resources
    • Documentation
    • Blog
    • Videos
    • FAQ
    • Learn Python
    • Customer Portal
    • About Us
  • Support
    • Documentation
    • Videos
    • FAQ
    • Contact Us
  • Contact Us
Table of Contents
  • PyXLL Documentation
  • Introduction to PyXLL
  • User Guide
    • Installing PyXLL
    • Configuring PyXLL
    • Worksheet Functions
      • Introduction
      • Argument and Return Types
      • Cached Objects
      • Array Functions
      • NumPy Array Types
      • Pandas Types
      • Polars DataFrames
      • Asynchronous Functions
      • Function Documentation
      • Variable and Keyword Arguments
      • Recalculating On Open
      • Recalculating On Reload
      • Interrupting Functions
    • Macro Functions
    • Real Time Data
    • Cell Formatting
    • Charts and Plotting
    • Custom Task Panes
    • ActiveX Controls
    • Using Pandas in Excel
    • Customizing the Ribbon
    • Context Menu Functions
    • Working with Tables
    • Python as a VBA Replacement
    • Menu Functions
    • Reloading and Rebinding
    • Error Handling
    • Deploying your add-in
    • Workbook Metadata
  • Video Guides and Tutorials
  • API Reference
  • What’s new in PyXLL 5
  • Changelog
Close

Recalculating On Reload¶

New in PyXLL 5.10

It can be useful to have worksheet functions (UDFs) that are automatically called whenevner the PyXLL add-in is reloaded.

One instance where this is useful is for functions returning objects. When reloading the PyXLL add-in any cached objects that have been returned from functions previously are cleared (unless the clear_object_cache_on_reload = 0 option is used). These functions need to be recalculated to recreate those objects, and so recalculating on reload can be helpful in that instance.

PyXLL functions can be made to automatically recalculate after the PyXLL add-in is reloaded by passing recalc_on_reload=True to xl_func.

  • Example

  • Default Behaviour

  • Disabling Completely

Example¶

The below function uses the recalc_on_reload=True option to tell PyXLL that it should be recalculated whenever the add-in is reloaded.

This function must be called at least once first (which happened either when entering the formula, or recalculating the workbook). Then, the next time the add-in is reloaded the cell containing the function will be marked as dirty and if automatic calculations are enabled it will be recalculated.

from pyxll import xl_func

@xl_func(recalc_on_reload=True)
def recalc_on_reload_func():
    print("recalc_on_reload_func called!")
    return "OK!"

Default Behaviour¶

The default behaviour for non-volatile worksheet functions is not to recalculate on reload unless the recalc_on_reload option is set in xl_func.

The recalc_on_reload feature is especially useful for RTD functions and for functions returning Python objects. The default behaviour for these two types of functions can be modified such that the recalc_on_reload feature applies by default.

  • Real Time Data (RTD) Functions

    For RTD functions the option recalc_rtd_on_reload can be set in the PYXLL section of the pyxll.cfg config file. If set, all RTD functions will recalculate on reloading unless specifically disabled by setting recalc_on_reload=False in the xl_func decorator.

    [PYXLL]
    ; Enable recalc on reload for all RTD functions
    recalc_rtd_on_reload = 1
    
  • Functions Returning Objects

    Similarly, any worksheet function that explicitly returns an object can be set to recalculate on reloading via the config setting recalc_cached_objects_on_reload.

    To enable recalculating all object functions on reload set recalc_cached_objects_on_reload to 1.

    [PYXLL]
    ; Eenable recalc on reload for all functions returning objects
    recalc_cached_objects_on_reload = 1
    

    With this setting enabled the following function would be recalculated when a workbook using it was opened, without needing to explicitly set recalc_on_reload=True in xl_func.

    from pyxll import xl_func
    
    @xl_func("int x: object")
    def create_object(x)
        obj = SomeClass(x)
        return obj
    

    This can be overridden for individual functions by passing recalc_on_reload=False to xl_func.

Disabling Completely¶

If you do not want any functions to be recalculated when reloading set disable_recalc_on_reload = 1 in your pyxll.cfg file.

This setting prevents any cells marked by PyXLL as needing to be recalculated when reloading the PyXLL add-in, regardles of any other settings or the recalc_on_reload option to xl_func.

[PYXLL]
disable_recalc_on_reload = 1
« Recalculating On Open
Interrupting Functions »
  • Home
  • Product
  • Features
  • Documentation
  • Download
  • Pricing
  • Support
  • Documentation
  • Videos
  • FAQ
  • Learn Python
  • Contact Us
  • About
  • About Us
  • Legal
  • Blog
© Copyright PyXLL Ltd