Skip to main content

Reading API

API for reading existing Excel files.

read()

import { read } from "xlmake";

// From file path
const workbook = await read("report.xlsx");

// From Buffer
const workbook = await read(buffer);

WorkbookReader

Represents the entire workbook.

Property/MethodReturnsDescription
sheetNamesstring[]List of sheet names
sheetCountnumberNumber of sheets
sheet(name)SheetReaderGet sheet by name
sheetAt(index)SheetReaderGet sheet by index
const workbook = await read("report.xlsx");

console.log(workbook.sheetNames); // ["Sales", "Stock"]
console.log(workbook.sheetCount); // 2

const sheet = workbook.sheet("Sales");
const firstSheet = workbook.sheetAt(0);

SheetReader

Represents a sheet.

Property/MethodReturnsDescription
namestringSheet name
rowCountnumberRow count
columnCountnumberColumn count
mergedCellsstring[]Merge info ("A1:B2" format)
cell(address)CellReaderGet cell by A1 notation
cellAt(row, col)CellReaderGet cell by row/column number
const sheet = workbook.sheet("Sales");

console.log(sheet.name); // "Sales"
console.log(sheet.rowCount); // 100
console.log(sheet.columnCount); // 5
console.log(sheet.mergedCells); // ["A1:B1", "C1:C2"]

// A1 notation
const cell1 = sheet.cell("A1");

// Row/column numbers (0-indexed)
const cell2 = sheet.cellAt(0, 0); // Same as A1

CellReader

Represents a cell.

PropertyReturnsDescription
valuestring | number | boolean | nullCell value
styleCellStyle | undefinedCell style
borderCellBorder | undefinedCell border info
const cell = sheet.cell("A1");

console.log(cell.value); // "Product"

const style = cell.style;
console.log(style?.bold); // true
console.log(style?.fill); // "#4472C4"

const border = cell.border;
console.log(border?.top); // { style: "thin", color: "#000000" }
console.log(border?.bottom); // { style: "thin", color: "#000000" }

Complete Example

import { read } from "xlmake";

// Read Excel file
const workbook = await read("./report.xlsx");

// Get sheet list
console.log(workbook.sheetNames); // ["Sales", "Stock"]

// Get sheet
const sheet = workbook.sheet("Sales");

// Get cell values
console.log(sheet.cell("A1").value); // "Product"
console.log(sheet.cell("B2").value); // 100

// Get cell styles
const style = sheet.cell("A1").style;
console.log(style?.bold); // true
console.log(style?.fill); // "#4472C4"

// Get merge info
console.log(sheet.mergedCells); // ["A1:B1", "C1:C2"]

// Access by row/column numbers (0-indexed)
console.log(sheet.cellAt(0, 0).value); // A1 value
console.log(sheet.cellAt(1, 1).value); // B2 value