Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Excel delayForCellEdit #62

Merged
merged 1 commit into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/core/defaultSnip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand All @@ -40,6 +75,7 @@ function getHostColor(host: Office.HostType): string {
const color = hostToColor.get(host) || "purple";
return color;
}

`,
},
html: {
Expand Down
6 changes: 5 additions & 1 deletion src/core/embed/embed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ async function callGenericCallbackForHost<T>(callback: GenericCallback<T>): 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);
});
Expand Down
Loading