How to Export Real Excel Workbooks in JavaScript Using Connected Workbooks

Published: (December 30, 2025 at 09:03 AM EST)
3 min read
Source: Dev.to

Source: Dev.to

Cover image for How to Export Real Excel Workbooks in JavaScript Using Connected Workbooks

If you’re exporting data to Excel today, chances are you’re generating CSV files or using a basic XLSX utility. Those approaches work—but they hit limits quickly:

  • CSV can’t preserve data types
  • No formulas, formatting, or tables
  • No Power Query or refresh logic
  • No way to integrate with Excel Online

When developers want actual Excel behavior, not just a file with .xlsx at the end, CSV falls short. That’s where Connected Workbooks comes in.

This guide walks you through what the library is, how it works, and how to use it to export real Excel workbooks directly from your JavaScript or TypeScript application.

Introduction

CSV exports are simple but limited. They can’t express:

  • Rich tables
  • Metadata
  • Styling
  • Reusable worksheets
  • Query connections
  • Real Excel structures

For teams building dashboards, admin tools, or analytics views, CSV‑only exports become frustrating. What you really want is an Excel workbook that behaves like something produced by Excel—tables, queries, refresh logic, templates. Connected Workbooks gives you that with a few lines of code.

What Is Connected Workbooks?

Connected Workbooks is an open‑source JavaScript/TypeScript library maintained by Microsoft.

Repository:

Its purpose is simple: take data in your web or backend application and generate a real Excel (.xlsx) workbook—complete with tables, queries, or templates.

It acts as a bridge between your app and Excel:

  • Your app provides HTML tables, arrays, grid data, and Power Query queries
  • Connected Workbooks turns that into structured Excel tables
  • Produces a Blob (or Buffer)
  • You can download it or open it instantly in Excel Online

This makes exporting Excel files feel like generating PDFs—simple, declarative, reliable.

How Connected Workbooks Works

Mental model

Your Application → Connected Workbooks → Excel Workbook (.xlsx)

Data sources you can provide

  • HTML <table> elements
  • Grid or array data
  • Power Query mashups
  • Excel templates with named tables

What the library produces

  • Excel tables (not static pasted values)
  • Workbooks with sheets, metadata, and table definitions
  • Optional Power Query connections
  • A final .xlsx Blob/Buffer

Comparison

FeatureCSV / Basic XLSXConnected Workbooks
Raw values only❌ (real tables)
No metadata❌ (column types, names, formats)
No refresh logic❌ (optional Power Query refresh)
No structural awareness❌ (template, table injection)

Installation

npm install @microsoft/connected-workbooks

Practical Walkthrough: Exporting an HTML Table

HTML table example

<table id="salesTable">
  <thead>
    <tr>
      <th>Product</th>
      <th>Units</th>
      <th>Revenue</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Keyboard</td>
      <td>124</td>
      <td>80</td>
    </tr>
    <tr>
      <td>Mouse</td>
      <td>183</td>
      <td>60</td>
    </tr>
  </tbody>
</table>

JavaScript/TypeScript code

import { WorkbookManager } from "@microsoft/connected-workbooks";

const workbookManager = new WorkbookManager();

async function exportTable() {
  const tableElement = document.getElementById("salesTable");

  const blob = await workbookManager.generateTableWorkbookFromHtml(tableElement);

  // Option 1 — download locally
  workbookManager.download(blob, "sales.xlsx");

  // Option 2 — open directly in Excel Online
  workbookManager.openInExcelWeb(blob, "sales.xlsx", true);
}

Running exportTable() instantly gives your users a professional, Excel‑native export—without building any XLSX structures by hand.

Real‑World Use Cases

  • Analytics dashboards – Export charts, tables, and raw data into a workbook analysts can modify.
  • Reporting tools – Monthly or weekly reports based on templates with pre‑built formulas.
  • Admin / internal systems – Simple “Export to Excel” buttons that create real Excel tables—not plain CSVs.

These scenarios benefit from structure, formatting, Power Query, or templates.

Conclusion

If you’ve outgrown CSV exports or want to give your users a native Excel experience, Connected Workbooks is a practical, developer‑friendly option. It keeps your code simple while producing real, structured Excel workbooks that users can trust.

Explore more patterns, examples, and utility functions in the repository.

Back to Blog

Related posts

Read more »

React Summit 2026

!Cover image for React Summit 2026https://media2.dev.to/dynamic/image/width=1000,height=420,fit=cover,gravity=auto,format=auto/https%3A%2F%2Fdev-to-uploads.s3.a...