xlsx-rw

Utility over xlsx npm package that reads/writes excel workbooks

Usage no npm install needed!

<script type="module">
  import xlsxRw from 'https://cdn.skypack.dev/xlsx-rw';
</script>

README

Excel Read/Write utilities
License NPM version NPM downloads

Utility to read, write and update excels using xlsx

RoadMap

This is a finished library with docs missing:

[x] Write typescript documentation [ ] Update docs ExcelReader [ ] Write ExcelWriter docs

ExcelReader

A class to read excel sheet

import { ExcelReader } from 'xlsx-rw';

const excelPath = 'excel.xlsx';
const excel = new ExcelReader(excelPath);

// Read from excel 3 colums (A, B, C) starting from first row
// until a row with no content in the columns (A, B, C) is found
const reader = excel.readRows('Seet1', 3);
let nextRow = reader.next();
while (!nextRow.done) {
    const [, b, c] = nextRow.value;
    const month = new Date(dTo.w).getMonth();
    // See more cell fields in https://www.npmjs.com/package/xlsx#cell-object
    console.log(b.t); // Cell type
    console.log(b.v); // Value
    console.log(b.w); // Text
    console.log(b.z); // Format
    console.log(b.f); // Formula
    nextRow = reader.next();
}

// Read from excel columns C, D, K, read rows 1-10
const reader = excel.readRows('Seet1', ['C', 'D', 'K'], 10);

// Read from excel columns C, D, K, starting on row 2 (skip headers row)
// until an empty row in C, D, K is found
const reader = excel.readRows('Seet1', ['C', 'D', 'K'], undefined, 2);

ExcelWritter

import { Workbook } from 'xlsx-rw';

const strText = `This text contains
multiple lines`;

// Generate excel sheet with some rows
const arrOfArrs = [
    ['Header text', 'Header long text', 'Header boolean', 'Header date'],
    ['value1', strText.replace(/[\r\n]+/g, '\r\n'), 2, false, new Date()],
];

const wb = new Workbook().writeData('sheet name', arrOfArrs);
const excelLocation = 'excel.xlsx';
wb.save(excelLocation);