Skip to content

Commit

Permalink
Merge pull request #1259 from ayatkyo/fix-hidden
Browse files Browse the repository at this point in the history
Fix hidden
  • Loading branch information
Siemienik committed May 27, 2020
2 parents 406c18d + a91dcef commit 2ffe624
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/xlsx/xform/sheet/col-xform.js
Expand Up @@ -48,7 +48,7 @@ class ColXform extends BaseXform {
if (node.attributes.style) {
model.styleId = parseInt(node.attributes.style, 10);
}
if (node.attributes.hidden) {
if (node.attributes.hidden === true || node.attributes.hidden === 'true' || node.attributes.hidden === 1 || node.attributes.hidden === '1') {
model.hidden = true;
}
if (node.attributes.bestFit) {
Expand Down
2 changes: 1 addition & 1 deletion lib/xlsx/xform/sheet/row-xform.js
Expand Up @@ -77,7 +77,7 @@ class RowXform extends BaseXform {
if (node.attributes.s) {
model.styleId = parseInt(node.attributes.s, 10);
}
if (node.attributes.hidden) {
if (node.attributes.hidden === true || node.attributes.hidden === 'true' || node.attributes.hidden === 1 || node.attributes.hidden === '1') {
model.hidden = true;
}
if (node.attributes.bestFit) {
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
42 changes: 41 additions & 1 deletion spec/integration/worksheet.spec.js
@@ -1,6 +1,6 @@
const path = require('path');

const testutils = require('./../utils/index');
const testutils = require('../utils/index');

const ExcelJS = verquire('exceljs');
const Range = verquire('doc/range');
Expand Down Expand Up @@ -812,4 +812,44 @@ describe('Worksheet', () => {
expect(workbook).to.have.property('worksheets');
expect(workbook.worksheets).to.have.length(1);
}));

describe('Hidden', () => {
const fileList = [
'google-sheets',
'libre-calc-as-excel-2007-365',
'libre-calc-as-office-open-xml-spreadsheet',
];

for (const file of fileList) {
it(`Should set hidden attribute correctly (${file})`, done => {
const wb = new ExcelJS.Workbook();
wb.xlsx
.readFile(
path.resolve(__dirname, 'data', 'hidden-test', `${file}.xlsx`)
)
.then(() => {
const ws = wb.getWorksheet(1);

// Check rows
expect(ws.getRow(1).hidden, `${file} : Row 1`).to.equal(false);
expect(ws.getRow(2).hidden, `${file} : Row 2`).to.equal(true);
expect(ws.getRow(3).hidden, `${file} : Row 3`).to.equal(false);

// Check columns
expect(ws.getColumn(1).hidden, `${file} : Column 1`).to.equal(
false
);
expect(ws.getColumn(2).hidden, `${file} : Column 2`).to.equal(true);
expect(ws.getColumn(3).hidden, `${file} : Column 3`).to.equal(
false
);

done();
})
.catch(error => {
done(error);
});
});
}
});
});

0 comments on commit 2ffe624

Please sign in to comment.