| page_type | sample | |||||||
|---|---|---|---|---|---|---|---|---|
| urlFragment | excel-add-in-create-spreadsheet-from-web-page | |||||||
| products |
|
|||||||
| languages |
|
|||||||
| extensions |
|
|||||||
| description | Learn how to create a spreadsheet from your web page, populate it with data, and embed a custom Office Add-in that auto-opens. |
This sample demonstrates how to create an Excel workbook from web site data using Node.js, and configure it so that a custom Office Add-in task pane automatically opens when the document is opened. This approach combines server-side workbook generation with the auto-open task pane feature.
- Create Excel workbooks programmatically using ExcelJS.
- Populate worksheets with data from a web source.
- Upload generated workbooks to OneDrive using Microsoft Graph API.
- Embed a custom Office Add-in into the workbook.
- Configure the add-in to automatically open when the workbook is opened.
- Use Office.js to control auto-open behavior.
- Excel on Windows
- Excel on Mac
- Excel on the web
- Node.js version 16 or higher
- npm (included with Node.js)
- Microsoft 365 account with OneDrive - Get a free developer sandbox that provides a renewable 90-day Microsoft 365 E5 developer subscription.
| Solution | Authors |
|---|---|
| Create Excel worksheet from web site | Microsoft |
| Version | Date | Comments |
|---|---|---|
| 1.0 | January 2023 | Initial release |
| 2.0 | January 2026 | Refactored to Node.js with custom add-in and auto-open |
- Go to the Azure portal - App registrations to register your app.
- Sign in with your Microsoft 365 administrator credentials.
- Select New registration.
- Enter a name for your application (for example, "Excel Worksheet from Website").
- For Supported account types, choose Accounts in any organizational directory (Any Microsoft Entra ID tenant - Multitenant) and personal Microsoft accounts (e.g. Skype, Xbox).
- Under Redirect URI, select Single-page application (SPA) and enter
https://localhost:3000/redirect. - Select Register.
- On the application's overview page, copy the Application (client) ID - you need this value.
- Select API permissions > Add a permission > Microsoft Graph > Delegated permissions.
- Add the following permissions:
User.ReadFiles.ReadWrite
- Select Add permissions.
- Select Grant admin consent for [your organization] to grant consent for all users in your organization.
- Clone or download this repository.
- Navigate to the
Samples/excel-create-worksheet-from-web-sitefolder. - Run
npm installto install dependencies. - Open
WebApplication/App/authConfig.jsand update the following values:- Replace
YOUR_CLIENT_IDwith your Application (client) ID from Microsoft Entra ID - Replace
YOUR_TENANT_IDwith your tenant ID (or usecommonfor multitenant)
- Replace
Office Add-ins require HTTPS. You need to generate and trust self-signed certificates for local development.
-
If you haven't already installed
office-addin-dev-certs, install it globally with the following command:npm install --global office-addin-dev-certs
-
Run the following command to generate a self-signed certificate:
npx office-addin-dev-certs install
This command will display the folder location where it generated the certificate files.
- On Windows, you might be prompted to trust the certificate - select Yes.
- On Mac, you might need to add the certificate to your keychain and mark it as trusted.
-
Copy the localhost.crt and localhost.key files from the certificate folder (typically
~/.office-addin-dev-certs/or%USERPROFILE%\.office-addin-dev-certs\on Windows) to the root folder of this sample. -
The server automatically uses the certificate files when you run
npm start.
npm startThe server starts on https://localhost:3000.
Before the auto-open feature works, sideload the add-in:
- Open Excel and create a new blank workbook.
- Go to Home > Add-ins > My Add-ins.
- On the Office Add-ins dialog, select the MY ADD-INS tab.
- Choose Manage My Add-ins > Upload My Add-in.
- Browse to and select the
manifest.xmlfile in the sample folder. - Select Upload.
- Open Office on the web.
- Choose Excel and create a new blank workbook.
- On the ribbon, select Add-ins.
- In the My Add-ins panel on the right, scroll to the bottom.
- Select Advanced....
- Select Upload My Add-in.
- Browse to and select the
manifest.xmlfile in the sample folder. - Select Upload.
After sideloading, you see a Show Task Pane button on the Home ribbon.
- Open a web browser and go to
https://localhost:3000. - Select Sign in with Microsoft and sign in by using your Microsoft 365 account.
- Select Open in Excel to generate a workbook with sample data.
- The app uploads the workbook to OneDrive and opens it in Excel.
- Because you previously sideloaded the add-in, the task pane opens automatically.
- The task pane contains controls to turn auto-open on or off for subsequent opens.
If you prefer not to use OneDrive:
- After signing in, select Download Directly instead of Open in Excel.
- The app downloads the file to your computer.
- Open the downloaded file in Excel.
- Because you previously sideloaded the add-in, the task pane opens automatically.
- The task pane contains controls to turn auto-open on or off for subsequent opens.
The Node.js server uses ExcelJS to create a workbook programmatically.
const workbook = new ExcelJS.Workbook();
const worksheet = workbook.addWorksheet('Web Data');
// Add data to the worksheet
tableData.rows.forEach((row, rowIndex) => {
const excelRow = worksheet.getRow(rowIndex + 1);
row.columns.forEach((column, colIndex) => {
excelRow.getCell(colIndex + 1).value = column.value;
});
});After creating the workbook, the server embeds a reference to the custom add-in by manipulating the Office Open XML (OOXML) structure.
- Generate buffer: Convert the ExcelJS workbook to a buffer.
- Load ZIP: Load the buffer into JSZip (Excel files are ZIP archives).
- Add webextension files: Add XML files to the
xl/webextensions/folder:webextension1.xml- Defines the add-in referencetaskpanes.xml- Configures the task pane (visibility, position, size)_rels/taskpanes.xml.rels- Links the taskpane to the webextension
- Update Content Types: Modify
[Content_Types].xmlto register the new file types. - Update relationships: Modify
xl/_rels/workbook.xml.relsto link the workbook to the taskpanes.
Configure the auto-open feature through Office.js in the task pane.
function setAutoOpenOn() {
Office.context.document.settings.set(
'Office.AutoShowTaskpaneWithDocument',
true
);
Office.context.document.settings.saveAsync();
}Save this setting in the document to tell Office to automatically open this specific task pane when the document is opened.
-
Install the add-in first: The auto-open feature works only if you sideload or install the add-in. If you don't install the add-in, the embedded reference is ignored.
-
Auto-open requires user consent: For security, Office Add-ins can't force themselves to open without user interaction on the first load. The expected workflow is:
- Open the downloaded file for the first time
- Manually select the Show Task Pane button on the ribbon
- Select Set auto-open ON in the task pane
- Save and close the file
- Subsequent opens: The task pane now auto-opens automatically
This is standard Office Add-in behavior.
-
Production considerations:
- Replace the self-signed certificate with a proper SSL certificate.
- Host the add-in on a public HTTPS server.
- Update the manifest.xml URLs to point to your production server.
- Add proper authentication and authorization to the API endpoints.
- Consider distributing the add-in through AppSource instead of sideloading.
Expected behavior: The task pane doesn't auto-open when you first download and open a file. This behavior is by design for security reasons. You must:
- Open the file
- Manually click the Show Task Pane button on the ribbon (next to the add-in name)
- Click Set auto-open ON in the task pane
- Save and close the file
- Reopen the file - the task pane now auto-opens automatically
If auto-open still doesn't work after following these steps:
- Check that the manifest ID in manifest.xml matches the ID in server.js (
createWebExtensionXml()function) - Ensure the add-in is properly sideloaded (visible on the ribbon)
- Try removing and re-sideloading the manifest
- Make sure you trust the self-signed certificate.
- Try running
npm startagain and accept the certificate prompt. - On Windows, you might need to run PowerShell as Administrator.
- Verify your Microsoft Entra ID app registration has
Files.ReadWritepermission. - Check that admin consent was granted for the permissions.
- Ensure the redirect URI is set to
https://localhost:3000/redirect. - Check the browser console for specific error messages.
- Verify the manifest.xml was successfully sideloaded.
- Try restarting Excel.
- Check that the server is running on https://localhost:3000.
- Look in Home > Add-ins > My Add-ins to see if the add-in is listed.
- Automatically open a task pane with a document
- Office Add-ins manifest
- ExcelJS documentation
- JSZip documentation
- Microsoft Graph API
- Office JavaScript API
- Did you experience any problems with the sample? Create an issue and we'll help you out.
- We'd love to get your feedback about this sample. Go to our Office samples survey to give feedback and suggest improvements.
- For general questions about developing Office Add-ins, go to Microsoft Q&A using the office-js-dev tag.
Copyright (c) 2026 Microsoft Corporation. All rights reserved.
This project has adopted the Microsoft Open Source Code of Conduct. For more information, see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.
