Note: SDK packages will be published at launch. This tutorial previews the API.
Process XLSX Files Server-Side
Use @mog-sdk/node to read, modify, and write Excel files in TypeScript -- no Excel installation required. The native Rust engine handles parsing, formula evaluation, and serialization.
1Install the SDK
The Node.js SDK ships prebuilt native binaries for macOS, Linux, and Windows. No Rust toolchain needed.
npm install @mog-sdk/node2Read an XLSX file
Open a workbook from disk and iterate over sheets and cells.
import { openWorkbook } from "@mog-sdk/node";
const wb = await openWorkbook("sales-report.xlsx");
// List all sheet names
for (const sheet of wb.getSheets()) {
console.log("Sheet:", sheet.name);
}
// Read cells from the first sheet
const ws = wb.getActiveSheet();
const rows = await ws.getUsedRange();
for (const row of rows) {
for (const cell of row) {
console.log(`${cell.ref}: ${cell.value} (type: ${cell.type})`);
}
}3Evaluate formulas
The Rust compute engine evaluates 500+ Excel-compatible functions. Call calculate() to recalculate the entire workbook, then read computed values.
import { openWorkbook } from "@mog-sdk/node";
const wb = await openWorkbook("budget.xlsx");
const ws = wb.getActiveSheet();
// Trigger full recalculation
await wb.calculate();
// Read a formula cell's computed value
const total = await ws.getValue("D10"); // =SUM(D2:D9)
console.log("Total:", total);
// Read the formula text itself
const formula = await ws.getFormula("D10");
console.log("Formula:", formula); // "=SUM(D2:D9)"4Modify cells and write back
Set cell values, add formulas, and save the workbook back to XLSX.
import { openWorkbook, save } from "@mog-sdk/node";
const wb = await openWorkbook("template.xlsx");
const ws = wb.getActiveSheet();
// Update values
await ws.setCell("A1", "Product");
await ws.setCell("B1", "Revenue");
await ws.setCell("A2", "Widget A");
await ws.setCell("B2", 45000);
await ws.setCell("A3", "Widget B");
await ws.setCell("B3", 62000);
// Add a formula
await ws.setCell("B4", "=SUM(B2:B3)");
// Recalculate and save
await wb.calculate();
await save(wb, "output.xlsx");
console.log("Saved output.xlsx");5Batch processing multiple files
Process an entire directory of XLSX files. Each workbook is independent, so you can parallelize with Promise.all.
import { openWorkbook, save } from "@mog-sdk/node";
import { readdir } from "node:fs/promises";
import { join } from "node:path";
async function addSummaryRow(filePath: string) {
const wb = await openWorkbook(filePath);
const ws = wb.getActiveSheet();
const lastRow = (await ws.getUsedRange()).length + 1;
await ws.setCell(`A${lastRow}`, "TOTAL");
await ws.setCell(`B${lastRow}`, `=SUM(B2:B${lastRow - 1})`);
await wb.calculate();
await save(wb, filePath.replace(".xlsx", "-with-totals.xlsx"));
}
const dir = "./reports";
const files = (await readdir(dir)).filter((f) => f.endsWith(".xlsx"));
await Promise.all(files.map((f) => addSummaryRow(join(dir, f))));
console.log(`Processed ${files.length} files`);Next steps
Embed a Spreadsheet in Next.js
Render an interactive spreadsheet in the browser with the embed component.
Use Mog from Python
Work with Mog workbooks in Python and convert to pandas DataFrames.
API Reference
Full reference for Workbook, Worksheet, and all SDK methods.
Getting Started
Install the SDK, create a workbook, and learn the basics.