The Creator property of the Workbook object in Excel’s object model is a read-only attribute that returns a 32-bit integer representing the application that originally created the workbook. This value is a unique identifier, often used to distinguish between workbooks created by different versions of Excel or other applications that can generate Excel files, such as older Mac versions or third-party software. In xlwings, this property can be accessed directly from a Workbook instance, providing compatibility information that can be useful for debugging, version control, or conditional logic in automation scripts.
Syntax in xlwings:workbook_instance.creator
This property does not accept any parameters. It returns an integer value. The meaning of specific integer values is not publicly documented by Microsoft in a comprehensive list, but common values include:
1480803660(hex:0x5843454C): Typically indicates the workbook was created by a version of Excel for Windows.1480803660(hex:0x5843434D): Often associated with Excel for Mac.
Other values may correspond to different creation sources.
Example Usage:
Suppose you have an Excel workbook and you want to check its origin before performing specific operations. You can use xlwings to retrieve the Creator value and act accordingly. Here’s a practical code example:
import xlwings as xw
# Open an existing workbook
wb = xw.Book('example.xlsx')
# Access the Creator property
creator_value = wb.creator
# Display the result
print(f"The workbook's creator code is: {creator_value}")
# Conditional logic based on the creator
if creator_value == 1480803660: # Common code for Excel Windows
print("This workbook was likely created by Excel for Windows.")
elif creator_value == 1480803660: # Note: This is an example; actual Mac codes may vary
print("This workbook may have been created by Excel for Mac.")
else:
print("The creator application is unknown or from a different source.")
# You can also use it in automation, e.g., to log workbook origins
with open('workbook_log.txt', 'a') as log_file:
log_file.write(f"Workbook: {wb.name}, Creator Code: {creator_value}\n")
# Close the workbook if needed
wb.close()
Leave a Reply