Introduction
Aspose.Cells FOSS for TypeScript exposes its functionality through a compact set of core
classes: Workbook, WorksheetCollection, Worksheet, Cell, and Style, plus supporting
types for formatting and filtering. This post is a systematic tour of that core API surface –
not a single narrow topic, but the fundamentals every application built on the library ends up
using: opening and saving workbooks, navigating worksheets, reading and writing cell values and
formulas, applying styles, filtering data, and exporting to other formats.
Each section below covers one area of the API with the concrete methods and properties
involved, backed by working TypeScript examples. The goal is to give you a working mental model
of how the pieces fit together, from new Workbook() down to individual Cell properties.
Key Features
Workbook and Worksheet Fundamentals
A Workbook is either created empty with new Workbook() or loaded asynchronously from an
existing file with Workbook.load(filePath, password). Every workbook exposes worksheets, a
WorksheetCollection that supports indexing, iteration, and array-style methods
(map, filter, forEach, find, indexOf) in addition to addWorksheet(name),
removeWorksheet(index), and moveWorksheet(fromIndex, toIndex). Call workbook.save(filePath, options) to persist changes.
const workbook = new Workbook();
const ws1 = workbook.worksheets.addWorksheet();
const ws2 = workbook.worksheets.addWorksheet("CustomSheet1");
console.log("Total worksheets:", workbook.worksheets.length);
workbook.worksheets.removeWorksheet(1);
console.log("After delete:", workbook.worksheets.length);
console.log(
"Names:",
workbook.worksheets.worksheets.map((w) => w.name),
);
await workbook.save("workbook.xlsx");
Cell Access and Values
A Worksheet reads and writes cells through putValue(key, value), getCell2(key) (returns a
Cell, creating it if absent), getCell(row, col) (returns Cell | undefined), and
getCellByRef(ref). Each Cell exposes value, formula, row, col, and ref as
properties, and setFormula() / setStyle() / setHyperlink() as methods.
const workbook = new Workbook();
const sheet = workbook.worksheets[0]!;
sheet.putValue("A1", 42);
sheet.putValue("A2", "Hello World");
const formulaCell = sheet.getCell2("A3");
formulaCell.setFormula("=A1+10");
console.log("A1 value:", sheet.getCell(0, 0)?.value);
console.log("A3 formula:", sheet.getCell(2, 0)?.formula);
const byRef = sheet.getCellByRef("A1");
console.log("Ref:", byRef?.ref, "Row:", byRef?.row, "Col:", byRef?.col);
await workbook.save("cells.xlsx");
Style, Font, Border, and Alignment
Style groups font, fill, border, alignment, and number-format settings for a cell. Read or
replace whole sub-objects with getFont()/setFont(), getBorder()/setBorder(), and
getAlignment()/setAlignment(), or use the convenience setters directly on Style, such as
setFontName(), setFontSize(), setBold(), setHorizontalAlignment(), and
setNumberFormat(). Apply the finished Style to a cell with Cell.setStyle().
const workbook = new Workbook();
const sheet = workbook.worksheets[0]!;
const style = new Style();
style.setFontName("Arial");
style.setFontSize(14);
style.setBold(true);
style.setNumberFormat("0.00");
style.getBorder().bottom = { style: "thin", color: "000000" };
style.setHorizontalAlignment("center");
style.setVerticalAlignment("center");
style.setWrapText(true);
const cell = sheet.getCell2("B2");
cell.putValue(1234.5);
cell.setStyle(style);
console.log("Bold:", style.isBold(), "Format:", style.getNumberFormat());
await workbook.save("styled.xlsx");
Auto-Filtering with the AutoFilter Class
Worksheet.setAutoFilter(range) is a shortcut for the common case, but the underlying
AutoFilter class can also be used directly: construct it with a range, then call
addFilterColumn(col, filters, blank) per column to define which values should remain
visible, or removeFilterColumn(col) / clear() to undo filtering.
const workbook = new Workbook();
const sheet = workbook.worksheets[0]!;
sheet.putValue("A1", "Name");
sheet.putValue("B1", "City");
sheet.putValue("A2", "Alice");
sheet.putValue("B2", "New York");
sheet.putValue("A3", "Bob");
sheet.putValue("B3", "London");
const filter = new AutoFilter("A1:B3");
filter.addFilterColumn(1, ["New York"], false);
console.log("Filter range:", filter.range);
console.log("Filter columns:", filter.columns.length);
await workbook.save("filtered.xlsx");
Exporting to HTML, CSV, JSON, and Markdown
Beyond .xlsx, a Workbook can render itself directly as text with toHtml(), toCsv(),
toJson(), and toMarkdown(), or be saved to a file whose extension selects the format via the
SaveFormat enum (XLSX, CSV, JSON, MARKDOWN, HTML).
const workbook = new Workbook();
const sheet = workbook.worksheets[0]!;
sheet.putValue("A1", "Name");
sheet.putValue("B1", "Age");
sheet.putValue("A2", "Alice");
sheet.putValue("B2", 25);
sheet.putValue("A3", "Bob");
sheet.putValue("B3", 30);
console.log("JSON:", workbook.toJson());
console.log("Markdown:\n", workbook.toMarkdown());
await workbook.save("report.csv");
await workbook.save("report.html");
Quick Start
git clone https://github.com/aspose-cells-foss/Aspose.Cells-FOSS-for-TypeScript.git
cd Aspose.Cells-FOSS-for-TypeScript
npm install
npm run buildimport { Workbook, Style } from "excel-cells";
const workbook = new Workbook();
const sheet = workbook.worksheets.get(0)!;
sheet.name = "Summary";
sheet.putValue("A1", "Item");
sheet.putValue("B1", "Count");
sheet.putValue("A2", "Widgets");
sheet.putValue("B2", 12);
sheet.putValue("A3", "Gadgets");
sheet.putValue("B3", 7);
const totalCell = sheet.getCell2("B4");
totalCell.setFormula("=SUM(B2:B3)");
const numberStyle = new Style();
numberStyle.setNumberFormat("0");
sheet.getCell2("B2").setStyle(numberStyle);
sheet.getCell2("B3").setStyle(numberStyle);
sheet.getCell2("B4").setStyle(numberStyle);
const detail = workbook.worksheets.addWorksheet("Detail");
detail.putValue("A1", "Raw Data");
await workbook.save("summary.xlsx");
const reloaded = await Workbook.load("summary.xlsx");
console.log("Worksheets:", reloaded.worksheets.length);
console.log("B4 formula:", reloaded.worksheets.get(0)!.getCell(3, 1)?.formula);
Supported Formats
| Format | Extension | Read | Write |
|---|---|---|---|
| XLSX | .xlsx | ✓ | ✓ |
| HTML | .html | ✓ | ✓ |
| CSV | .csv | — | ✓ |
| JSON | .json | — | ✓ |
| Markdown | .md | — | ✓ |
Open Source & Licensing
Aspose.Cells FOSS for TypeScript is released under the MIT license. The source code is available on GitHub. Commercial use is permitted under the MIT license terms.