Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not parse all workbooks #18

Open
lsborg opened this issue Aug 8, 2014 · 4 comments
Open

Does not parse all workbooks #18

lsborg opened this issue Aug 8, 2014 · 4 comments

Comments

@lsborg
Copy link

lsborg commented Aug 8, 2014

I'm parsing the worksheets in a loop and the second parse is giving the result of the first.

The code:

var excelParser = require('excel-parser');

var loadWorksheet = function(id, path){
    excelParser.parse({
        inFile: path, 
        skipEmpty: true,
        worksheet: id
    }, function(err, result){
        if(err) {
            console.error(err);
            return;
        }

        console.log(result[0][0]);
    });
};


var loadExcel = function() {
    var worksheetpath = 'master.xls';

    excelParser.worksheets({
        inFile: worksheetpath, 
        skipEmpty: true
    }, function(err, worksheets){
        if(err) console.error(err);

        for(var i = 0; i < worksheets.length; i++){
            console.log(worksheets[i]);
            loadWorksheet(worksheets[i].id, worksheetpath);
        }
    });
};

loadExcel();

The output:

{ name: 'a1', id: 1 }
{ name: 'a2', id: 2 }
211.0
211.0

The workbook:

worksheet a1: [ [111;112], [121, 122] ]
worksheet a2: [ [211;212], [221, 222] ]
]``
@lsborg
Copy link
Author

lsborg commented Aug 8, 2014

Found the bug, around util.js:18.

It is:

var _CRCsv = function(args, cb) {
  temp.mkdir('temp', function(err, dirPath) {
    if(err) return cb(err);
    csvFile = path.join(dirPath, 'convert.csv');
    args.push('-c', csvFile);
    utils.execute(args, function(err, stdout) {
      if(err) return cb(err);
      fs.readFile(csvFile, 'utf-8', function(err, csv_data) {
        if(err) return cb(err);
        cb(null, csv_data);
      });
    });
  });
};

Should be:

var _CRCsv = function(args, cb) {
  temp.mkdir('temp', function(err, dirPath) {
    if(err) return cb(err);
    csvFile = path.join(dirPath, 'convert.csv');
    args.push('-c', csvFile);
    !function(f){
      utils.execute(args, function(err, stdout) {
        if(err) return cb(err);
        fs.readFile(f, 'utf-8', function(err, csv_data) {
          if(err) return cb(err);
          cb(null, csv_data);
        });
      });
    }(csvFile);
  });
};

lsborg pushed a commit to lsborg/excel-parser that referenced this issue Aug 8, 2014
@detj
Copy link
Member

detj commented Aug 8, 2014

@lsborg send a PR please

@detj
Copy link
Member

detj commented Aug 8, 2014

Thanks for the PR 👍

@ryanm2000
Copy link

ryanm2000 commented Aug 7, 2016

@detj / @leftshifters Any chance of getting the PR merged?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants