From fb97bf17688104f3ad7cb7f19c24897982aa91cc Mon Sep 17 00:00:00 2001 From: Maxim Kukhtenkov Date: Sun, 4 Feb 2018 18:58:00 -0500 Subject: [PATCH] VBA CFB test [ci skip] --- bits/59_vba.js | 1 + bits/85_parsezip.js | 2 +- test.js | 5 ++++- tests/core.js | 5 ++++- xlsx.flow.js | 3 ++- xlsx.js | 3 ++- 6 files changed, 14 insertions(+), 5 deletions(-) diff --git a/bits/59_vba.js b/bits/59_vba.js index cb0fdec..6ffe2e3 100644 --- a/bits/59_vba.js +++ b/bits/59_vba.js @@ -1,3 +1,4 @@ +var CT_VBA = "application/vnd.ms-office.vbaProject"; function make_vba_xls(cfb/*:CFBContainer*/) { var newcfb = CFB.utils.cfb_new({root:"R"}); cfb.FullPaths.forEach(function(p, i) { diff --git a/bits/85_parsezip.js b/bits/85_parsezip.js index fea21e7..686e8ed 100644 --- a/bits/85_parsezip.js +++ b/bits/85_parsezip.js @@ -169,7 +169,7 @@ function parse_zip(zip/*:ZIP*/, opts/*:?ParseOpts*/)/*:Workbook*/ { } if(opts.bookVBA) { if(dir.vba.length > 0) out.vbaraw = getzipdata(zip,strip_front_slash(dir.vba[0]),true); - else if(dir.defaults && dir.defaults.bin === 'application/vnd.ms-office.vbaProject') out.vbaraw = getzipdata(zip,'xl/vbaProject.bin',true); + else if(dir.defaults && dir.defaults.bin === CT_VBA) out.vbaraw = getzipdata(zip, 'xl/vbaProject.bin',true); } return out; } diff --git a/test.js b/test.js index 4ce885d..816a9d3 100644 --- a/test.js +++ b/test.js @@ -591,7 +591,10 @@ describe('parse options', function() { var wb = X.read(fs.readFileSync(p), {type:TYPE}); assert(typeof wb.vbaraw === 'undefined'); }); }); it('bookVBA should generate vbaraw', function() { NFVBA.forEach(function(p) { - var wb = X.read(fs.readFileSync(p),{type:TYPE, bookVBA:true}); assert(wb.vbaraw); + var wb = X.read(fs.readFileSync(p),{type: TYPE, bookVBA: true}); + assert(wb.vbaraw); + var cfb = X.CFB.read(wb.vbaraw, {type: 'array'}); + assert(X.CFB.find(cfb, '/VBA/ThisWorkbook')); }); }); }); }); diff --git a/tests/core.js b/tests/core.js index 4ce885d..816a9d3 100644 --- a/tests/core.js +++ b/tests/core.js @@ -591,7 +591,10 @@ describe('parse options', function() { var wb = X.read(fs.readFileSync(p), {type:TYPE}); assert(typeof wb.vbaraw === 'undefined'); }); }); it('bookVBA should generate vbaraw', function() { NFVBA.forEach(function(p) { - var wb = X.read(fs.readFileSync(p),{type:TYPE, bookVBA:true}); assert(wb.vbaraw); + var wb = X.read(fs.readFileSync(p),{type: TYPE, bookVBA: true}); + assert(wb.vbaraw); + var cfb = X.CFB.read(wb.vbaraw, {type: 'array'}); + assert(X.CFB.find(cfb, '/VBA/ThisWorkbook')); }); }); }); }); diff --git a/xlsx.flow.js b/xlsx.flow.js index 01894f0..027a016 100644 --- a/xlsx.flow.js +++ b/xlsx.flow.js @@ -9175,6 +9175,7 @@ function write_comments_bin(data/*::, opts*/) { write_record(ba, "BrtEndComments"); return ba.end(); } +var CT_VBA = "application/vnd.ms-office.vbaProject"; function make_vba_xls(cfb/*:CFBContainer*/) { var newcfb = CFB.utils.cfb_new({root:"R"}); cfb.FullPaths.forEach(function(p, i) { @@ -18775,7 +18776,7 @@ function parse_zip(zip/*:ZIP*/, opts/*:?ParseOpts*/)/*:Workbook*/ { } if(opts.bookVBA) { if(dir.vba.length > 0) out.vbaraw = getzipdata(zip,strip_front_slash(dir.vba[0]),true); - else if(dir.defaults && dir.defaults.bin === 'application/vnd.ms-office.vbaProject') out.vbaraw = getzipdata(zip,'xl/vbaProject.bin',true); + else if(dir.defaults && dir.defaults.bin === CT_VBA) out.vbaraw = getzipdata(zip, 'xl/vbaProject.bin',true); } return out; } diff --git a/xlsx.js b/xlsx.js index 893da3f..3ed6fb1 100644 --- a/xlsx.js +++ b/xlsx.js @@ -9081,6 +9081,7 @@ function write_comments_bin(data) { write_record(ba, "BrtEndComments"); return ba.end(); } +var CT_VBA = "application/vnd.ms-office.vbaProject"; function make_vba_xls(cfb) { var newcfb = CFB.utils.cfb_new({root:"R"}); cfb.FullPaths.forEach(function(p, i) { @@ -18665,7 +18666,7 @@ function parse_zip(zip, opts) { } if(opts.bookVBA) { if(dir.vba.length > 0) out.vbaraw = getzipdata(zip,strip_front_slash(dir.vba[0]),true); - else if(dir.defaults && dir.defaults.bin === 'application/vnd.ms-office.vbaProject') out.vbaraw = getzipdata(zip,'xl/vbaProject.bin',true); + else if(dir.defaults && dir.defaults.bin === CT_VBA) out.vbaraw = getzipdata(zip, 'xl/vbaProject.bin',true); } return out; }