How to use Workbooks.Creator in the xlwings API way

The Creator property of the Workbooks object in Excel’s object model is a read-only property that returns a Long value representing the creator code for the application that created the file. This is particularly useful for identifying the original application when dealing with files that may have been created in different versions of Excel or other spreadsheet programs. In xlwings, this property can be accessed through the api property, which provides direct access to the underlying Excel object model.

Functionality:
The Creator property helps in determining the application that originally created the workbook. It returns a four-character code (as a Long integer) that corresponds to the creator. For example, Microsoft Excel typically uses the code “XCEL”. This can be useful in scenarios where you need to verify file origins or handle compatibility issues.

Syntax:
In xlwings, the syntax to access the Creator property is:

workbook.api.Creator

Here, workbook refers to an xlwings Book object. The property does not take any parameters and returns a Long value.

Example:
Below is a practical example of how to use the Creator property in xlwings to check the creator of an open workbook. This code opens a workbook, retrieves the creator code, and prints it along with a descriptive message.

import xlwings as xw

# Open an existing workbook or connect to an open one
wb = xw.Book('example.xlsx') # Replace with your file path

# Access the Creator property via the api
creator_code = wb.api.Creator

# Convert the Long code to a readable string (optional)
# Typically, you might map known codes to application names
if creator_code == 1480803660: # This is 'XCEL' in decimal for Excel
    creator_name = "Microsoft Excel"
else:
    creator_name = "Unknown Application"

# Output the result
print(f"The workbook creator code is: {creator_code}")
print(f"This corresponds to: {creator_name}")

# Close the workbook if needed (optional)
wb.close()

August 11, 2026 (0)


Leave a Reply

Your email address will not be published. Required fields are marked *