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

Function "eachCell" does not work as expected #15

Closed
VanDalkvist opened this issue Mar 19, 2015 · 4 comments
Closed

Function "eachCell" does not work as expected #15

VanDalkvist opened this issue Mar 19, 2015 · 4 comments

Comments

@VanDalkvist
Copy link

When I try use eachCell function it works strange. It seems that it dismiss null/undefined value or something like that.

// ...
var parsedRow = {};
row.eachCell(function (cell, col) {
       parsedRow[columnsRow.getCell(col).value] = cell.value;
});

For example, if I have 30 columns and some of them equals ""(empty string in the file) then Object.keys(parsedRow).length expression can return 26.

@VanDalkvist
Copy link
Author

I just saw your sources files and see next:

eachRow: function(iteratee) {
        this._rows.forEach(function(row) {
            if (row.hasValues) {
                iteratee(row, row.number);
            }
        });
    },

For me, it is not expected behaviour, because if we have strong order of properties it will be wrong in the output.
Instead of your function eachRow I have to use this construction:

var parsedRow = {};
// here counting starts from 1
for (var col = 1; col < row.values.length; col++) {
      var cell = row.getCell(col);
      parsedRow[columnsRow.getCell(col).value] = cell.value;
}

@guyonroche
Copy link
Collaborator

I guess the "each" functions could take an optional boolean argument like "includeEmpty" that would behave more like you want. I'll add it to the next release.

@guyonroche
Copy link
Collaborator

The eachRow and eachCell functions now support an optional options argument that will git you the behaviour you need...

worksheet.eachRow({ includeEmpty: true }, function(row, rowNumber) {
    row.eachCell{ includeEmpty: true }, function(cell, colNumber) {
        console.log("Cell " + colNumber + " on Row " + rowNumber + " = " + cell.value);
    });
});

@VanDalkvist
Copy link
Author

Great, Thank you!

Elecweb added a commit to getnuvo/exceljs that referenced this issue Sep 25, 2023
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

2 participants