XlsxWriter
XlsxWriter copied to clipboard
feature request: adding customUI to an Excel file
Feature Request
This is a follow-up to #282
We've been using this feature on our own fork for ~9 years now and would like to merge it to the project so we can update to the newest version easier. For now, I have moved our additions to a fresh fork and a separate branch: https://github.com/infranaut/XlsxWriter/tree/feature-ribbons
Example
A customUI adds another Ribbon to the file with additional buttons that can call VBA functions. They allow for user friendly access to Macros provided by the tool that created the Excel file.
The corresponding XML to define this Ribbon looks like this:
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">
<ribbon startFromScratch="false">
<tabs>
<tab id="Tab1" label="Metadata Tools">
<group id="Group1" label="Validate">
<button id="But1"
label="Active Sheet"
imageMso="ZoomToSelection"
size="large"
onAction="validateActiveSheet_Ribbon" />
<button id="But2"
label="All Sheets"
imageMso="DatasheetColumnLookup"
size="large"
onAction="validateAllSheets_Ribbon" />
</group>
<group id="Group3" label="Update">
<button id="But3"
label="Shared Member in Active Sheet"
imageMso="RecurrenceEditSeries"
size="large"
onAction="correctSharedMembersActiveSheet_Ribbon" />
<button id="But4"
label="Parent Column in Active Sheet"
imageMso="AccessRefreshAllLists"
size="large"
onAction="updateParentColumnActiveSheet_Ribbon" />
</group>
<group id="Group2" label="Settings">
<checkBox id="CheckBox1"
label="Validate Descriptions"
onAction="getCheckBox1_Ribbon" />
</group>
</tab>
</tabs>
</ribbon>
</customUI>
The older version uses a difference namespace:
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
...
</customUI>
API changes
In order to add the customUI, you have to add the file to the workbook via a new add_custom_ui
method.
workbook.add_custom_ui("/path/to/customUI.xml", version=2006)
workbook.add_custom_ui("/path/to/customUI14.xml", version=2007)