Add synchronous custom function conditional formatting sample#1204
Add synchronous custom function conditional formatting sample#1204chandpravandan wants to merge 7 commits into
Conversation
899223c to
f1a3673
Compare
| { | ||
| "id": "excel-custom-functions-sync-conditional-format", | ||
| "onboardDate": "2026-03-19", | ||
| "title": "Use synchronous custom functions with conditional formatting in Excel", |
There was a problem hiding this comment.
Its never a custom function which is either in sync mode or async mode. So i think right title should be "Use sync supported custom function in conditional formatting scenario in excel"
something like that which tells that custom function supports sync scenario as well.
There was a problem hiding this comment.
yes, but keeping it in the current state to be it in sync with the public docs - https://learn.microsoft.com/en-us/office/dev/add-ins/excel/custom-functions-synchronous
There was a problem hiding this comment.
Pull request overview
Adds a new Excel sample demonstrating how to use a synchronous custom function (@supportSync) inside a conditional formatting rule so formatting updates live as a target value changes.
Changes:
- Introduces a new sample project (
excel-custom-functions-sync-conditional-format) with task pane UI + synchronous custom function and a conditional format rule that calls it. - Adds build/tooling/config files for the sample (webpack/TypeScript/Babel/ESLint) plus required manifest and assets.
- Registers the sample in the repo-level sample list (
README.md) and.config/sample-config.json.
Reviewed changes
Copilot reviewed 15 out of 24 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| Samples/excel-custom-functions-sync-conditional-format/webpack.config.js | Webpack build/dev-server config for the new sample. |
| Samples/excel-custom-functions-sync-conditional-format/tsconfig.json | TypeScript compiler configuration for the sample. |
| Samples/excel-custom-functions-sync-conditional-format/src/taskpane/taskpane.js | Populates the worksheet and applies conditional formatting using the custom function. |
| Samples/excel-custom-functions-sync-conditional-format/src/taskpane/taskpane.html | Task pane UI for running the sample setup. |
| Samples/excel-custom-functions-sync-conditional-format/src/functions/functions.ts | Implements the synchronous custom function used by the conditional format rule. |
| Samples/excel-custom-functions-sync-conditional-format/RUN_WITH_EXTENSION.md | Instructions for running the sample via the Office Add-ins Development Kit. |
| Samples/excel-custom-functions-sync-conditional-format/README.md | Main documentation for the sample scenario and usage steps. |
| Samples/excel-custom-functions-sync-conditional-format/package.json | Sample dependencies and scripts. |
| Samples/excel-custom-functions-sync-conditional-format/manifest.xml | Office Add-in manifest wiring task pane + custom functions metadata/script. |
| Samples/excel-custom-functions-sync-conditional-format/babel.config.json | Babel preset configuration. |
| Samples/excel-custom-functions-sync-conditional-format/.gitignore | Sample-local ignore rules. |
| Samples/excel-custom-functions-sync-conditional-format/.eslintrc.json | Sample ESLint configuration. |
| Samples/excel-custom-functions-sync-conditional-format/assets/sample.json | Sample gallery metadata for the new sample. |
| Samples/excel-custom-functions-sync-conditional-format/assets/logo-filled.png | Task pane logo asset. |
| Samples/excel-custom-functions-sync-conditional-format/assets/icon-80.png | Add-in icon asset. |
| Samples/excel-custom-functions-sync-conditional-format/assets/icon-64.png | Add-in icon asset. |
| Samples/excel-custom-functions-sync-conditional-format/assets/icon-32.png | Add-in icon asset. |
| Samples/excel-custom-functions-sync-conditional-format/assets/icon-16.png | Add-in icon asset. |
| Samples/excel-custom-functions-sync-conditional-format/assets/icon-128.png | Add-in icon asset. |
| Samples/excel-custom-functions-sync-conditional-format/assets/Icon_Office_Add-ins_Development_Kit.png | Doc asset used in run instructions. |
| README.md | Adds the new sample to the repository’s sample index table. |
| .config/sample-config.json | Registers the new sample in the repo’s sample configuration. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const context = new Excel.RequestContext(); | ||
| context.setInvocation(invocation); // The invocation object must be passed in the setInvocation method for synchronous functions. | ||
|
|
||
| const range = context.workbook.worksheets.getActiveWorksheet().getRange(address); | ||
| range.load("values"); |
There was a problem hiding this comment.
getCellValue uses getActiveWorksheet(), which can read from the wrong sheet if the user activates a different worksheet while the conditional format is recalculating. Use the worksheet from invocation.address (parse sheet name) or otherwise bind the lookup to the sheet where the CF formula is evaluated so A2 is read from the correct worksheet.
alison-mk
left a comment
There was a problem hiding this comment.
Thanks for adding this sample! Here's my first round of suggestions, mostly minor grammatical adjustments to align with Microsoft writing style guide. I'll incorporate my suggestions now, and then finalize and merge your sample tomorrow.
| "name": "excel-custom-functions-sync-conditional-format", | ||
| "reponame": "office-add-in-samples", | ||
| "source": "officedev", | ||
| "title": "Synchronous custom function - conditional formatting", |
There was a problem hiding this comment.
| "title": "Synchronous custom function - conditional formatting", | |
| "title": "Synchronous custom function with conditional formatting", |
Co-authored-by: Alison McKay <almckay@microsoft.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Alison McKay <almckay@microsoft.com>
| await context.sync(); | ||
|
|
||
| document.getElementById("status").textContent = | ||
| "Status: Done. Scores in B2:B8 that exceed the target in A2 are highlighted. Change A2 to see the conditional format update live."; |
There was a problem hiding this comment.
@chandpravandan Could you take another look at this sample? In my testing, nothing is highlighted on start (even though this status suggests that some values should be highliuthed), and nothing happens when I change A2.
Hopefully my additions didn't accidentally break the sample!
alison-mk
left a comment
There was a problem hiding this comment.
This sample seems broken. It doesn't work in my testing, and the screenshot in the PR does not show the sample working—Values in the score column that exceed 70 should be highlighted. Nothing is highlighted in the screenshot. Please test the sample and then update the screenshot, or provide more information about how the sample is intended to work.
What's in this Pull Request?
A new Excel sample that uses a synchronous custom function (
@supportSync) inside a conditional format rule to highlight cells that exceed a target value. The conditional format updates live when the target changes.