Add-in Expert logo
  • About
  • Portfolio
  • Blog
  • FAQs
Book a CallGet in Touch
Add-in Expert logo
  • About
  • Portfolio
  • Blog
  • FAQs
Book a CallGet in Touch
Add-in Expert logo
  • About
  • Portfolio
  • Blog
  • FAQs
Book a CallGet in Touch
  1. Home
  2. Blog
  3. Excel Add-ins
  4. Create Custom Functions in Excel with Office.js
Excel Add-ins

Create Custom Functions in Excel with Office.js

Extend Excel’s formula language with your own functions — fetch live data, run custom logic, and stream results straight into cells.

AUBy Adeel Umar
|December 3, 2025|8 min read
Share:
Create Custom Functions in Excel with Office.js

Introduction

Excel users live in the formula bar. Custom functions let you put your own logic right there alongside SUM and VLOOKUP — so users call your code the way they already call any built-in function.

What Are Custom Functions?

Custom functions are JavaScript (or TypeScript) functions that Excel exposes as worksheet formulas under a namespace you choose, for example =CONTOSO.GETPRICE("MSFT"). They can accept arguments, return values, ranges, and even update asynchronously.

Custom functions run in a lightweight JavaScript runtime separate from the task pane, which is why they can stay fast and recalculate efficiently.

How They Differ from Task Panes

A task pane is a UI surface the user opens; a custom function is invoked silently by the calculation engine whenever its inputs change. The two complement each other — many add-ins ship both.

Defining Your First Function

Functions are written as plain JS with a JSDoc comment that the build tooling turns into metadata Excel reads.

functions.js
/**
 * Adds two numbers.
 * @customfunction
 * @param {number} first First number.
 * @param {number} second Second number.
 * @returns {number} The sum.
 */
function add(first, second) {
  return first + second;
}

CustomFunctions.associate('ADD', add);

Fetching Live Data

Because custom functions can be asynchronous, they are perfect for pulling live data — exchange rates, stock prices, inventory — directly into a cell. Just return a Promise.

functions.js
/**
 * Gets the latest price for a ticker.
 * @customfunction
 * @param {string} ticker The stock symbol.
 * @returns {Promise<number>}
 */
async function getPrice(ticker) {
  const res = await fetch(`https://api.example.com/price/${ticker}`);
  const data = await res.json();
  return data.price;
}

CustomFunctions.associate('GETPRICE', getPrice);

CORS & HTTPS apply

Custom functions are still web code. Your data endpoints must be served over HTTPS and send the correct CORS headers, or the fetch will fail silently in the cell.

Streaming Functions

For values that change over time, a streaming function pushes updates to the cell using an invocation handler instead of returning once.

functions.js
/**
 * Streams a counter every second.
 * @customfunction
 * @param {CustomFunctions.StreamingInvocation<number>} invocation
 */
function clock(invocation) {
  let count = 0;
  const timer = setInterval(() => {
    invocation.setResult(count++);
  }, 1000);

  invocation.onCanceled = () => clearInterval(timer);
}

CustomFunctions.associate('CLOCK', clock);

Performance & Limits

  • Keep functions pure and fast — they may be called thousands of times on recalc.
  • Batch network requests where possible to avoid rate limits.
  • Always clean up timers and subscriptions in onCanceled for streaming functions.
  • Return errors with CustomFunctions.Error so users see a proper #VALUE! state.

Conclusion

Custom functions meet users exactly where they work — in the formula bar. Whether you are surfacing live data or encapsulating complex business math, they make your add-in feel like a native part of Excel.

#Excel#Custom Functions#Office.js#JavaScript#Tutorial
PreviousCentralized Deployment of Office Add-ins: A Complete GuideNext Build Word Add-ins to Automate Document Workflows

Related Articles

Build Powerful Excel Add-ins with Office.js: A Complete GuideExcel Add-insBuild Powerful Excel Add-ins with Office.js: A Complete GuideMarch 12, 2024 · 8 min readIntegrate Xero with Excel: Build a Custom Add-in for Live Accounting Data & ReportsExcel Add-insIntegrate Xero with Excel: Build a Custom Add-in for Live Accounting Data & ReportsMarch 15, 2026 · 9 min readOutlook Add-ins for Business Automation: Use Cases & ExamplesOutlook Add-insOutlook Add-ins for Business Automation: Use Cases & ExamplesJune 20, 2024 · 6 min read

Table of Contents

  1. 1.What Are Custom Functions?
  2. 2.How They Differ from Task Panes
  3. 3.Defining Your First Function
  4. 4.Fetching Live Data
  5. 5.Streaming Functions
  6. 6.Performance & Limits
  7. 7.Conclusion

Need Help Building Custom Office Add-ins?

We build secure, scalable, and user-friendly Office solutions that drive real business impact.

Contact Our Experts

Categories

  • Excel Add-ins3
  • Outlook Add-ins4
  • Word Add-ins2
  • PowerPoint Add-ins1
  • Google Workspace5
  • Best Practices6
View all categories

Popular Posts

  • How to Build an Excel Add-in That Stands OutHow to Build an Excel Add-in That Stands OutApr 10, 2024
  • Top 10 Outlook Add-ins Use Cases for BusinessesTop 10 Outlook Add-ins Use Cases for BusinessesMar 28, 2024
  • Google Workspace Add-ons vs Macros: What to Choose?Google Workspace Add-ons vs Macros: What to Choose?Mar 15, 2024
View all posts

Stay Updated

Subscribe to get the latest tutorials, insights, and product updates.

No spam. Unsubscribe anytime.

Add-in Expert logo
Addin Expert specializes in developing custom Office add-ins and Google add-ons, empowering businesses to enhance productivity and streamline workflows with tailored, innovative solutions

Office 365 Add-ins

  • Outlook add-ins
  • Word add-ins
  • Excel add-ins
  • Powerpoint add-ins

Google addons

  • Gmail Addon
  • Google Docs Addon
  • Google Sheets Addon
  • Google forms Addon

More Services

  • VSTO Add-ins
  • VSTO Migration
  • Cross-Platform
  • Deployment

Company

  • About Us
  • Portfolio
  • Blog
  • Privacy Policy
Copyright © 2026. All rights reserved by Addin Expert.