This works but might be simplified:
- While you have your workbook open, right-click the xlwings task pane > Inspect... In the dev tools, in the JS Console, type the following and hit Enter:
await Office.addin.setStartupBehavior(Office.StartupBehavior.load);
This will cause the Excel workbook to load the add-in automatically.
- In app/static/js/main.js, paste the following code (you will need to adjust it to your needs):
Office.onReady(async () => {
if (await xlwings.getActiveBookName() === "your-workbook-name.xlsx") {
let authResult = await globalThis.getAuth();
await xlwings.runPython({
include: "",
exclude: "",
scriptName: "hello_world",
auth: authResult.token, // older versions of xlwings Server would require authResult instead of authResult.token
errorDisplayMode: "taskpane",
});
}
});
This code is triggered after the add-in has been loaded by the workbook.
This works but might be simplified:
This will cause the Excel workbook to load the add-in automatically.
This code is triggered after the add-in has been loaded by the workbook.