Excel Functions

Registering modules

To register a Python module for use within Excel you use the RegisterPyModule() function:

RegisterPyModule(PythonModulePath, ExecutablePath=None, ModulePrefix=None, UseBackgroundProcess=None, ExtraModuleSearchLocations=None, ExtraDllSearchLocations=None, FunctionNames=None)

Registers a Python module for use in Excel.

Parameters:
  • PythonModulePath (str) – The full path to the Python module to load.
  • ExecutablePath (str or None) – Optional location of the Python environment to use.
  • ModulePrefix (str or None) – Optional prefix to apply to the function names.
  • UseBackgroundProcess (bool or None) – Should xlSlim Python code run a seperate process?
  • ExtraModuleSearchLocations (str or None) – Extra locations to be added to the Python module search path (sys.path).
  • ExtraDllSearchLocations (str or None) – Extra locations to be added to the Windows DLL search path (PATH).
  • FunctionNames (Excel range or None) – An Excel range specifying which functions to import. By default all functions in a module are imported. A single column range can specify only the functions to import. A two column range can specify the Python functions in the first column and the Excel function names in the second column.

See Python Environments for details of the ExecutablePath parameter. See Passing lists for an example using the ModulePrefix parameter. See Running Python in a background process for an example using the UseBackgroundProcess parameter. See Advanced Module Importing for an example showing the use of the ExtraModuleSearchLocations and FunctionNames parameters.

Viewing cached objects

xlSlim automatically caches Python object. The ViewPyObject() function can be used to view these objects.

ViewPyObject(key)

View a cached Python object.

Parameters:key (str) – An xlSlim cached object handle.
Returns:An error message if the object was not found or an array of objects suitable for display in Excel.
Return type:str or list[object]

Creating ranges

Often xlSlim functions will expect a list to be passed by using a contiguous Excel range. The CreateRange() function takes a set of non-adjacent ranges and creates a new Excel range object suitable for passing to xlSlim functions.

CreateRange(range1, range2, ... rangen)

Creates a new Excel range from non-adjacent cells.

Parameters:
  • range1 (Excel range) – An Excel range, can be a single cell or range.
  • range2 (Excel range) – An Excel range, can be a single cell or range.
  • rangen (Excel range) – An Excel range, can be a single cell or range.
Returns:

A new Excel range object.

Return type:

Excel range

Note

The inputs ranges 1 to n must be the same size for xlSlim to succesfully stitch them together.

Diagnostics

To troubleshoot the Python environment used in Excel you can use the PythonDetails() function:

PythonDetails()

Returns comprehensive details about the Python environment, including the module search paths and loaded packages.

Returns:Details of the Python environment.
Return type:list[str]

Clear Caches

To remove all cached objects you can use the ClearCaches() function:

ClearCaches()

Removes all cached objects from xlSlim’s internal memory caches.

Use the bundled Python

xlSlim has a bundled version of Python 3.10. This bundled Python is used by default. However you can specify another Python environment when registering modules with RegisterPyModule(). The ClearSavedPythonEnv() function will revert back to using the bundled Python.

ClearSavedPythonEnv()

Reverts xlSlim to using the bundled Python environment.

Get the current workbook location

The WorkbookLocation() function can be used to get the current workbook’s location.

WorkbookLocation()

Returns the location of the current Excel workbook. Unlike the standard Excel CELL() function this function is not volatile.

Returns:The path (excluding filename) of the current workbook.
Return type:str

Get the log location

The LogLocation() function can be used to get the location of xlSlim’s log file.

LogLocation()

Returns the location of xlSlim’s log file. The log file is useful for troubleshooting.

Returns:The path (including filename) of the log file
Return type:str

Check the licensing status

The IsPremiumLicensed() function can be used to check if xlSlim has a valid premium licence. See Licensing.

IsPremiumLicensed()

Checks if xlSlim has a premium licence.

Returns:True if a valid premium licence was found, else false.
Return type:bool

Check the licence expiry

The LicenseExpiry() function can be used to check the expiry date of any existing premium licence.

LicenseExpiry()

Gets the expiry of the premium licence.

Returns:The expiry time of any premium licence found.
Return type:datetime

Activate a licence

The ActivatePremiumLicense() function can be used to request a trial licence or activate a premium licence. See Licensing

ActivatePremiumLicense(key)

Gets the expiry of the premium licence.

Parameters:key (str) – A premium licence key purchased from xlslim.com.
Returns:The activation result.
Return type:str

Deactivate a licence

The DeactivatePremiumLicense() function can be used to deactivate a premium licence so it can be used on another PC. See Licensing

DeactivatePremiumLicense()

Deactivates any current premium licence.

Returns:The deactivation result.
Return type:str

Version

To get the version of xlSlim used in Excel you can use the XlSlimVersion() function:

XlSlimVersion()

Returns the version of xlSlim in use.

Returns:The xlSlim version in use.
Return type:str

GetAttr

The GetAttr() function efficiently gets attributes from cached Python objects.

GetAttr(cacheKey, attribute, defaultValue)
Parameters:
  • cacheKey (str) – An xlSlim cached object handle.
  • attribute (str) – The name of the attribute to retrieve.
Returns:

An error message if the object was not found. If the attribute exists it is returned, else if a defaultValue was supplied this is returned, failing which an error message is returned.

Return type:

str or object

GetItem

The GetItem() function efficiently gets items from cached Python dictionaries.

GetItem(cacheKey, dictKey, defaultValue)
Parameters:
  • cacheKey (str) – An xlSlim cached dictionary handle.
  • dictKey (str) – The key of the item to retrieve.
Returns:

An error message if the cached dictionary was not found. If an item is stored against the key then the item is returned, else if a defaultValue was supplied this is returned, failing which an error message is returned.

Return type:

str or object