Skip to content

Commit

Permalink
Supporting skipping hidden columns and rows in sheet_to_json
Browse files Browse the repository at this point in the history
  • Loading branch information
geniejhang committed Jan 12, 2022
1 parent 0ddeba4 commit 6bff8db
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
13 changes: 12 additions & 1 deletion bits/90_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,24 @@ function sheet_to_json(sheet/*:Worksheet*/, opts/*:?Sheet2JSONOpts*/) {
default: r = range;
}
if(header > 0) offset = 0;
var rr = encode_row(r.s.r);
var cols/*:Array<string>*/ = [];
var out/*:Array<any>*/ = [];
var outi = 0, counter = 0;
var dense = Array.isArray(sheet);
var R = r.s.r, C = 0, CC = 0;
var rowinfo/*:Array<ColInfo>*/ = o.skipHidden && sheet["!rows"] || [];
for (R = r.s.r + offset; R <= r.e.r; ++R) {
if (((rowinfo[R]||{}).hidden)) {
offset++;
continue;
}
break;
}
var rr = encode_row(R);
if(dense && !sheet[R]) sheet[R] = [];
var colinfo/*:Array<ColInfo>*/ = o.skipHidden && sheet["!cols"] || [];
for(C = r.s.c; C <= r.e.c; ++C) {
if (((colinfo[C]||{}).hidden)) continue;
cols[C] = encode_col(C);
val = dense ? sheet[R][C] : sheet[cols[C] + rr];
switch(header) {
Expand All @@ -82,6 +92,7 @@ function sheet_to_json(sheet/*:Worksheet*/, opts/*:?Sheet2JSONOpts*/) {
}
}
for (R = r.s.r + offset; R <= r.e.r; ++R) {
if (((rowinfo[R]||{}).hidden)) continue;
var row = make_json_row(sheet, r, R, cols, header, hdr, dense, o);
if((row.isempty === false) || (header === 1 ? o.blankrows !== false : !!o.blankrows)) out[outi++] = row.row;
}
Expand Down
3 changes: 3 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,9 @@ export interface Sheet2JSONOpts extends DateNFOption {

/** if true, return raw numbers; if false, return formatted numbers */
rawNumbers?: boolean;

/** Skip hidden rows and columns; must be used with cellStyles:true in XLSX.read or XLSX.readFile */
skipHidden?: boolean;
}

export interface AOA2SheetOpts extends CommonOptions, DateNFOption {
Expand Down

0 comments on commit 6bff8db

Please sign in to comment.