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

feat(sheet): add auto filter support #152

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
13 changes: 13 additions & 0 deletions xlsx.js
Original file line number Diff line number Diff line change
Expand Up @@ -7558,6 +7558,11 @@ function parse_ws_xml(data, opts, rels) {
if (ref != null) parse_ws_xml_dim(s, ref[1]);
}

/* 18.3.1.2 autoFilter CT_AutoFilter */
var afregex = /<(?:\w:)?autoFilter[^>]*([\/]|>([\s\S]*)<\/(?:\w:)?autoFilter)>/g;
var afilter = data.match(afregex);
if(afilter) s['!autofilter'] = parse_ws_xml_autofilter(afilter[0]);

/* 18.3.1.55 mergeCells CT_MergeCells */
var mergecells = [];
if (data.indexOf("</mergeCells>") !== -1) {
Expand Down Expand Up @@ -7943,6 +7948,7 @@ function write_ws_xml(idx, opts, wb) {
if (ws['!pageSetup'] !== undefined) o[o.length] = write_ws_xml_pagesetup(ws['!pageSetup']);
if (ws['!rowBreaks'] !== undefined) o[o.length] = write_ws_xml_row_breaks(ws['!rowBreaks']);
if (ws['!colBreaks'] !== undefined) o[o.length] = write_ws_xml_col_breaks(ws['!colBreaks']);
if (ws['!autofilter'] !== undefined) o[o.length] = write_ws_xml_autofilter(ws['!autofilter']);

if (o.length > 2) {
o[o.length] = ('</worksheet>');
Expand All @@ -7969,6 +7975,13 @@ function write_ws_xml_col_breaks(breaks) {
}
return writextag('colBreaks', brk.join(' '), {count: brk.length, manualBreakCount: brk.length})
}
function parse_ws_xml_autofilter(data) {
var o = { ref: (data.match(/ref="([^"]*)"/)||[])[1]};
return o;
}
function write_ws_xml_autofilter(data) {
return writextag('autoFilter', null, {ref:data.ref});
}

/* [MS-XLSB] 2.4.718 BrtRowHdr */
function parse_BrtRowHdr(data, length) {
Expand Down