CotalkerPartners / mongo-xlsx

Convert Mongo data into Excel and vice versa @ Node.js. MongoDB Mongoose Dump to excel.
MIT License
99 stars 28 forks source link

Model not being autogenerated from my excel spreadsheet #3

Closed moonweazel closed 8 years ago

moonweazel commented 8 years ago

Morning!

I can't seem to get mongo-xlsx to autogenerate the model. My spreadsheet has a lot of columns that might change so I don't really want to manually create the model myself.

var mongoXlsx = require('mongo-xlsx');

var mongoModel;

mongoXlsx.xlsx2MongoData("avivadotcom.xlsx",mongoModel, function (err, mongoData) {
    console.log('Mongo data:', mongoData);
});

without declaring mongoModel - I get "mongoModel is undefined". If i declare it as null then I get "Cannot read property 'split' of undefined from line 356 (mongo-xlsx.js).

Any pointers?

Cheers!

ghost commented 8 years ago

I did it like


      var data = [];

/* Generate automatic model for processing (A static model should be used) */
var model = mongoXlsx.buildDynamicModel(data);

              mongoXlsx.xlsx2MongoData("./category.xlsx", model, function(err, mongoData) {
                console.log('Mongo data:', mongoData); 
              });
acedward commented 8 years ago

Hi! If the model is defined null, then the library builds the model with the excel first row column names. I will update the readme!

var model = null;
var xlsx  = './file.xlsx';

mongoxlsx.xlsx2MongoData(xlsx, model, function(err, data) {
  console.log(data);
});
acedward commented 8 years ago

Added example. https://github.com/Moblox/mongo-xlsx/commit/a569c408134210c87934d218c41e94dc123bd65f