diff --git a/src/core/defaultSnip.tsx b/src/core/defaultSnip.tsx index 06b4ae8..e05bfb1 100644 --- a/src/core/defaultSnip.tsx +++ b/src/core/defaultSnip.tsx @@ -12,8 +12,43 @@ export const defaultSnip: ExportSnip = { function ready() { console.log('Hello world!'); + + // runExcel(); + // runWord(); + // runPowerPoint(); +} + +async function runExcel() { + await Excel.run({ delayForCellEdit: true }, async (context) => { + const range = context.workbook.getSelectedRange(); + range.format.fill.color = "yellow"; + range.load("value"); + await context.sync(); + console.log(\`The range address was "\${range.value}".\`); + }); +} + +async function runWord() { + await Word.run(async (context) => { + const range: Word.Range = context.document.getSelection(); + range.font.color = "yellow"; + range.load("text"); + await context.sync(); + console.log(\`The selected text was "\${range.text}".\`); + }); } +async function runPowerPoint() { + await PowerPoint.run(async (context) => { + const range = context.presentation.getSelection(); + range.font.color = "yellow"; + range.load("text"); + await context.sync(); + console.log(\`The selected text was "\${range.text}".\`); + }); +} + + Office.onReady(({host, platform})=> { console.log("READY"); @@ -40,6 +75,7 @@ function getHostColor(host: Office.HostType): string { const color = hostToColor.get(host) || "purple"; return color; } + `, }, html: { diff --git a/src/core/embed/embed.ts b/src/core/embed/embed.ts index c254c8f..23bf0f6 100644 --- a/src/core/embed/embed.ts +++ b/src/core/embed/embed.ts @@ -13,7 +13,11 @@ async function callGenericCallbackForHost(callback: GenericCallback): Prom const host = getHost(); switch (host) { case Office.HostType.Excel: - return await Excel.run(async (context) => { + // delayForCellEdit + // https://learn.microsoft.com/en-us/office/dev/add-ins/excel/excel-add-ins-delay-in-cell-edit + // Delay for cell edit so the call does not fail due to cell edit mode. + // In practice this should only be called when already in the editor so it should be rare. + return await Excel.run({ delayForCellEdit: true }, async (context) => { const customXmlParts = context.workbook.customXmlParts; return callback(context, customXmlParts); });