Giter VIP home page Giter VIP logo

excelmapper's Introduction

excelmapper

excelmapper is a Excel trasformation utility library for converting / mapping XLSX files into Array of Objects (AoO) by an column attribute definition.

The purpose of module is convert the (node-xlsx) Excel spreadsheet internal format to the more usable Array of Objects (AoO) format, that is more likely to be used in various contexts (as output of a REST service, format to pass to a view template, or format from which to do bulk imports to a database using an ORM toolkit).

Usage

var emapper = require('./excelmapper');
// opts from command line has "file" for filename, "sheet" for sheet addressing

var emap = new emapper.ExcelMapper(opts.file, { debug: 1 });
var sheets = emap.listsheets();
console.log("List of sheets: " + JSON.stringify(sheets));
console.log("Set Sheet to: " + opts.sheet);
// Set "active" sheet (by name or 0-based sheet index)
// Ok, we are storing return value and doing low level access to sheet here, but only
// for testing, I promise :-)
// This *must* be called to select the "active" sheet.
var sheet = emap.sheet(opts.sheet);
// Sheet has properties of node-xlsx single sheet ...
if (sheet.data && sheet.name) {console.log("Sheet looks cool, has name and data.");}
else {console.log("Something wrong with sheet ?!?");process.exit(1);}
var aoo = emap.to_aoh();
// Dump the AoO (Array of Objects)
console.log(JSON.stringify(aoo, null, 2));
// .. Put AoH into real use ...

DB Import Usage with Sequelize:

// ... map to AoO
var aoo = emap.to_aoh();
// Bulk insert to DB
products.bulkCreate(aoo, {validate: true})
.then(function () {
   ...
});

Notes and Warnings

Data import, especially from spreadsheet is always a "dirty job" and you will most likely be doing various massaging operations, cleanup and data transformations plus validation before ending up with a viewable / importable format. These processing steps are not the focus of excelmapper. Try the good-ol' Javascript and maybe underscore library for these ops.

Further Examples

See script xltest.js in GitHub distribution. Try running it with command line options (e.g. similar to...):

./xltest.js  --file /tmp/excel-test.xlsx --sheet mySheetName

Converting Embedded Docs with JSDoc

jsdoc excelmapper.js -R README.md -c jsdoc.conf.json

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.