Skip to content

Commit 2ffe624

Browse files
authored
Merge pull request #1259 from ayatkyo/fix-hidden
Fix hidden
2 parents 406c18d + a91dcef commit 2ffe624

File tree

6 files changed

+43
-3
lines changed

6 files changed

+43
-3
lines changed

lib/xlsx/xform/sheet/col-xform.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class ColXform extends BaseXform {
4848
if (node.attributes.style) {
4949
model.styleId = parseInt(node.attributes.style, 10);
5050
}
51-
if (node.attributes.hidden) {
51+
if (node.attributes.hidden === true || node.attributes.hidden === 'true' || node.attributes.hidden === 1 || node.attributes.hidden === '1') {
5252
model.hidden = true;
5353
}
5454
if (node.attributes.bestFit) {

lib/xlsx/xform/sheet/row-xform.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class RowXform extends BaseXform {
7777
if (node.attributes.s) {
7878
model.styleId = parseInt(node.attributes.s, 10);
7979
}
80-
if (node.attributes.hidden) {
80+
if (node.attributes.hidden === true || node.attributes.hidden === 'true' || node.attributes.hidden === 1 || node.attributes.hidden === '1') {
8181
model.hidden = true;
8282
}
8383
if (node.attributes.bestFit) {
Binary file not shown.
Binary file not shown.
Binary file not shown.

spec/integration/worksheet.spec.js

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const path = require('path');
22

3-
const testutils = require('./../utils/index');
3+
const testutils = require('../utils/index');
44

55
const ExcelJS = verquire('exceljs');
66
const Range = verquire('doc/range');
@@ -812,4 +812,44 @@ describe('Worksheet', () => {
812812
expect(workbook).to.have.property('worksheets');
813813
expect(workbook.worksheets).to.have.length(1);
814814
}));
815+
816+
describe('Hidden', () => {
817+
const fileList = [
818+
'google-sheets',
819+
'libre-calc-as-excel-2007-365',
820+
'libre-calc-as-office-open-xml-spreadsheet',
821+
];
822+
823+
for (const file of fileList) {
824+
it(`Should set hidden attribute correctly (${file})`, done => {
825+
const wb = new ExcelJS.Workbook();
826+
wb.xlsx
827+
.readFile(
828+
path.resolve(__dirname, 'data', 'hidden-test', `${file}.xlsx`)
829+
)
830+
.then(() => {
831+
const ws = wb.getWorksheet(1);
832+
833+
// Check rows
834+
expect(ws.getRow(1).hidden, `${file} : Row 1`).to.equal(false);
835+
expect(ws.getRow(2).hidden, `${file} : Row 2`).to.equal(true);
836+
expect(ws.getRow(3).hidden, `${file} : Row 3`).to.equal(false);
837+
838+
// Check columns
839+
expect(ws.getColumn(1).hidden, `${file} : Column 1`).to.equal(
840+
false
841+
);
842+
expect(ws.getColumn(2).hidden, `${file} : Column 2`).to.equal(true);
843+
expect(ws.getColumn(3).hidden, `${file} : Column 3`).to.equal(
844+
false
845+
);
846+
847+
done();
848+
})
849+
.catch(error => {
850+
done(error);
851+
});
852+
});
853+
}
854+
});
815855
});

0 commit comments

Comments
 (0)