@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);
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
- getEncoding() - *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
XlsxReader Options
XlsxWriter Options
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|*"
}
}