npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@dictadata/xlsx-junction

v0.9.13

Published

dictadata Storage Junction for .xlsx, .xls and .ods files.

Downloads

169

Readme

@dictadata/xlsx-junction 0.9.x

A Storage Junction for Excel .xlsx and .xls files. XlsxJunction implements a junction for reading tabular data from Excel .xlsx, .xls, .ods files. XlsxJunction is a storage plugin for use with @dictadata/storage-junctions and related projects @dictadata/storage-tracts ETL command line utility and @dictadata/storage-node API Server.

The plugin uses the SheetJS XLSX module to parse the XLSX documents.

Installation

npm install @dictadata/storage-junctions @dictadata/xlsx-junction

Using the Plugin

Register the junction when initializing the app. Import the Storage Junctions library and the XLSX Junction plugin. Then register XLSX Junction with the Storage Junctions' Storage module. This will register XLSX Junction for use with storage model "xlsx".

const { Storage } = require("@dictadata/storage-junctions");
const { XlsxJunction } = require("@dictadata/xlsx-junction");

Storage.Junctions.use("xlsx", XlsxJunction);
Storage.Junctions.use('xls', XlsxJunction);
Storage.Junctions.use('ods', XlsxJunction);

Creating an instance of PDFJunction

Create an instance of XLSXJunction class. Then a junction can be created as needed in the app using an SMT definition.

const Storage = require("@dictadata/storage-junctions");

var junction = Storage.activate("xlsx|file:folderpath/workbook.xlsx|sheet name|*", options);

// or

var junction = Storage.activate({
    model:"xlsx",
    locus: "file:folderpath/workbook.xlsx",
    schema: "sheet name",
    key: "column name"
  }, options);

Supported Storage Junction Methods

  • list() - list sheets
  • createSchema() - create a new sheet
  • dullSchema() - delete a sheet
  • getEngram() - *use codify transform to generate schema encoding
  • createReader() - read rows from sheet
  • createWriter() - save constructs to sheet

Supported FileSystems

Supported filesystem are those built into the storage-junctions library. Currently the supported file systems types are:

  • file: - the spreadsheet file must be located on a local file system

Storage Junction Objects


XlsxJunction Options

/**
 * @param {String|Object} SMT 'xlsx|file:filename|sheetname|key' or an Engram object
 * @param {object} options
 * @param {boolean} [raw] - output all raw in worksheet with cell properties
 * @param {string}  [range] - A1-style range, e.g. "A3:M24"
 * @param {boolean} [overwrite] - overwrite/create workbook file
 * @param {string}  [sheetName] - sheet name to use instead of SMT.schema, default none
 * @param {boolean} [cellDates] - default true, format date cell values as UTC strings
 *
 * XLSX.readFile()
 * read workbook options:
 *   "cellFormula", "cellHTML", "cellNF", "cellStyles", "cellText", "cellDates"
 *   https://docs.sheetjs.com/docs/api/parse-options
 *
 * XLSX.writeFile()
 * write workbook options:
 *   "cellDates", "type", "bookSST", "bookType", "sheet", "compression", "Props", "themeXLSX", "ignoreEC"
 *   https://docs.sheetjs.com/docs/api/write-options
 */

XlsxReader Options

/**
 * @param {object} junction - parent XlsxJunction
 * @param {object}   [options]
 * @param {number}   [options.count] - maximum rows to read
 * @param {boolean}  [options.raw] - output all raw in worksheet with cell properties
 * @param {string}   [options.range] - A1-style range, e.g. "A3:M24"
 * @param {string}   [options.heading] PDF section heading where data is located, default: none
 * @param {string}   [options.stopHeading] PDF section heading after data table, default: none
 * @param {number}   [options.cells] minimum number of cells in a row, default: 1
 * @param {boolean}  [options.repeating] indicates if table headers are repeated on each page, default: false
 * @param {string[]} [options.headers] - RowAsObject: array of column names for data, default none, first table row contains names.
 * @param {number}   [options.column] - RepeatCellTransform: column index of cell to repeat, default 0
 * @param {string}   [options.header] - RepeatHeadingTransform: column name for the repeating heading field
 *
 * sheet_to_json() read options:
 *   "raw", "range", "header", "dateNF", "defval", "blankrows", "skipHidden", "UTC"
 *   https://docs.sheetjs.com/docs/api/utilities/array#array-output
 */

XlsxWriter Options

/**
 * @param {object}  junction - parent XlsxJunction
 * @param {object}  [options]
 * @param {boolean} [raw] - constructs are worksheet cells with cell properties
 *
 * json_to_sheet() write options:
 *   "cellDates", "origin", "header", "dateNF", "skipHeader"
 *   https://docs.sheetjs.com/docs/api/utilities/array#array-of-objects-input
 */

Examples


The following examples use the State_Voter_Registration_2024_PPE.xlsx file found in the project's test/data/input folder. Examples use Storage Tracts CLI options format to define a tract fiber.

Output Raw Cell Properties

{
  origin: {
    smt: "xlsx|./test/data/input/State_Voter_Registration_2024_PPE.xlsx|in|*",
    options: {
      raw: true,
      cellDates: false
    }
  },
  terminal: {
    smt: "json|./test/data/output/xlsx/|svr_all_rows.json|*"
  }
}

Normalize a Missing Cell Value

{
  origin: {
    smt: "xlsx|./test/data/input/State_Voter_Registration_2024_PPE.xlsx|in|*",
    options: {
      heading: "Active",
      cells: 9,
      column: 0
    }
  },
  terminal: {
    smt: "json|./test/data/output/xlsx/|svr_heading.json|*"
  }
}

Parsing a Worksheet Range

Retrieves the same data table as previous example.

{
  origin: {
    smt: "xlsx|./test/data/input/State_Voter_Registration_2024_PPE.xlsx|in|*",
    options: {
      range: "A6:R70",
      column: 0
    }
  },
  terminal: {
    smt: "json|./test/data/output/xlsx/|svr_range.json|*"
  }
}

Normalizing a Worksheet with Subsection Headings

{
  origin: {
    smt: "xlsx|./test/data/input/State_Voter_Registration_2024_PPE.xlsx|in|*",
    options: {
      range: "A77:S134",
      header: "County:1"
    }
  },
  terminal: {
    smt: "json|./test/data/output/xlsx/|svr_repeat.json|*"
  }
}