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

Hidden columns #60

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,24 @@ let buildExport = (params, options) => {
value: specification[col].displayName,
style: specification[col].headerStyle || ''
})
let columnSpec = {}

if (typeof specification[col].hidden !== 'undefined') {
delete specification[col].width
columnSpec.hidden = specification[col].hidden
}

if (specification[col].width) {
if (Number.isInteger(specification[col].width)) {
config.cols.push({ wpx: specification[col].width })
columnSpec.wpx = specification[col].width
} else if (Number.isInteger(parseInt(specification[col].width))) {
config.cols.push({ wch: specification[col].width })
columnSpec.wch = specification[col].width
} else {
throw 'Provide column width as a number'
}
} else {
config.cols.push({})
}
}

config.cols.push(columnSpec)

}
data.push(header) //Inject the header at 0
Expand Down
2 changes: 1 addition & 1 deletion lib/excel.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ module.exports = {
wb.SheetNames.push(name);
wb.Sheets[name] = data;

if(worksheet.config.cols) {
if (worksheet.config.cols) {
wb.Sheets[name]['!cols'] = worksheet.config.cols
}

Expand Down
1 change: 1 addition & 0 deletions lib/node-excel-export.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ declare module 'node-excel-export' {
cellStyle?: ((value: TRowData[CellName], row: TRowData) => CellStyle) | CellStyle;
cellFormat?: (value: TRowData[CellName], row: TRowData) => string;
width: string | number;
hidden?: boolean;
}
}

Expand Down
Loading