Skip to content

Add synchronous custom function conditional formatting sample#1204

Open
chandpravandan wants to merge 7 commits into
OfficeDev:mainfrom
chandpravandan:excel-custom-functions-sync-conditional-format
Open

Add synchronous custom function conditional formatting sample#1204
chandpravandan wants to merge 7 commits into
OfficeDev:mainfrom
chandpravandan:excel-custom-functions-sync-conditional-format

Conversation

@chandpravandan

Copy link
Copy Markdown
Contributor
Q A
Bug fix? no
New feature? no
New sample? yes
Related issues? n/a

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.

@chandpravandan chandpravandan marked this pull request as ready for review March 19, 2026 05:48
@chandpravandan chandpravandan force-pushed the excel-custom-functions-sync-conditional-format branch from 899223c to f1a3673 Compare March 19, 2026 06:25
@chandpravandan chandpravandan marked this pull request as draft March 19, 2026 06:54
@alison-mk alison-mk self-requested a review March 23, 2026 23:23
@chandpravandan chandpravandan marked this pull request as ready for review March 26, 2026 03:17
{
"id": "excel-custom-functions-sync-conditional-format",
"onboardDate": "2026-03-19",
"title": "Use synchronous custom functions with conditional formatting in Excel",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread .config/sample-config.json

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +15 to +19
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");

Copilot AI Apr 3, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment thread Samples/excel-custom-functions-sync-conditional-format/src/taskpane/taskpane.html Outdated
Comment thread Samples/excel-custom-functions-sync-conditional-format/src/taskpane/taskpane.html Outdated
Comment thread Samples/excel-custom-functions-sync-conditional-format/RUN_WITH_EXTENSION.md Outdated
Comment thread Samples/excel-custom-functions-sync-conditional-format/RUN_WITH_EXTENSION.md Outdated
Comment thread Samples/excel-custom-functions-sync-conditional-format/README.md Outdated
Comment thread Samples/excel-custom-functions-sync-conditional-format/README.md Outdated

@alison-mk alison-mk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread Samples/excel-custom-functions-sync-conditional-format/assets/sample.json Outdated
Comment thread Samples/excel-custom-functions-sync-conditional-format/src/functions/functions.ts Outdated
"name": "excel-custom-functions-sync-conditional-format",
"reponame": "office-add-in-samples",
"source": "officedev",
"title": "Synchronous custom function - conditional formatting",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"title": "Synchronous custom function - conditional formatting",
"title": "Synchronous custom function with conditional formatting",

Comment thread Samples/excel-custom-functions-sync-conditional-format/assets/sample.json Outdated
Comment thread Samples/excel-custom-functions-sync-conditional-format/src/functions/functions.ts Outdated
Comment thread Samples/excel-custom-functions-sync-conditional-format/README.md
Comment thread Samples/excel-custom-functions-sync-conditional-format/manifest.xml Outdated
Comment thread Samples/excel-custom-functions-sync-conditional-format/manifest.xml Outdated
Comment thread Samples/excel-custom-functions-sync-conditional-format/src/taskpane/taskpane.html Outdated
Comment thread Samples/excel-custom-functions-sync-conditional-format/src/taskpane/taskpane.html Outdated
Co-authored-by: Alison McKay <almckay@microsoft.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Comment thread Samples/excel-custom-functions-sync-conditional-format/src/taskpane/taskpane.html Outdated
Comment thread Samples/excel-custom-functions-sync-conditional-format/src/taskpane/taskpane.html Outdated
Comment thread Samples/excel-custom-functions-sync-conditional-format/src/taskpane/taskpane.html Outdated
Comment thread Samples/excel-custom-functions-sync-conditional-format/src/taskpane/taskpane.html Outdated
Comment thread Samples/excel-custom-functions-sync-conditional-format/src/taskpane/taskpane.html Outdated
Comment thread Samples/excel-custom-functions-sync-conditional-format/src/taskpane/taskpane.html Outdated
Comment thread Samples/excel-custom-functions-sync-conditional-format/src/taskpane/taskpane.html Outdated
Comment thread Samples/excel-custom-functions-sync-conditional-format/src/taskpane/taskpane.js Outdated
Comment thread Samples/excel-custom-functions-sync-conditional-format/src/taskpane/taskpane.js Outdated
Comment thread Samples/excel-custom-functions-sync-conditional-format/src/taskpane/taskpane.js Outdated
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.";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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 alison-mk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@alison-mk alison-mk added the Do Not Merge This PR has additional work or review required before it is ready to merge. label Apr 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Do Not Merge This PR has additional work or review required before it is ready to merge.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants