diff --git a/datagrid.html b/datagrid.html index 5fa77fb..c2f50e1 100644 --- a/datagrid.html +++ b/datagrid.html @@ -71,6 +71,9 @@ var process_wb = (function() { var range = XLSX.utils.decode_range(ws['!ref']); for(var i = range.s.c; i <= range.e.c; ++i) cDg.schema[i - range.s.c].title = XLSX.utils.encode_col(i); + HTMLOUT.style.height = (window.innerHeight - 400) + "px"; + HTMLOUT.style.width = (window.innerWidth - 50) + "px"; + if(typeof console !== 'undefined') console.log("output", new Date()); }; })(); @@ -136,12 +139,6 @@ var export_xlsx = (function() { return out; } - function s2ab(s) { - var b = new ArrayBuffer(s.length), v = new Uint8Array(b); - for (var i=0; i != s.length; ++i) v[i] = s.charCodeAt(i) & 0xFF; - return b; - } - return function export_xlsx() { if(!cDg) return; /* convert canvas-datagrid data to worksheet */ @@ -152,10 +149,10 @@ var export_xlsx = (function() { XLSX.utils.book_append_sheet(new_wb, new_ws, 'SheetJS'); /* write file and trigger a download */ - var wbout = XLSX.write(new_wb, {bookType:'xlsx', bookSST:true, type:'binary'}); + var wbout = XLSX.write(new_wb, {bookType:'xlsx', bookSST:true, type:'array'}); var fname = 'sheetjs.xlsx'; try { - saveAs(new Blob([s2ab(wbout)],{type:"application/octet-stream"}), fname); + saveAs(new Blob([wbout],{type:"application/octet-stream"}), fname); } catch(e) { if(typeof console != 'undefined') console.log(e, wbout); } }; })(); diff --git a/tests/core.js b/tests/core.js index bde5fed..768bea8 100644 --- a/tests/core.js +++ b/tests/core.js @@ -655,6 +655,7 @@ describe('output formats', function() { it('should write binary strings', function() { RT('binary'); }); it('should write base64 strings', function() { RT('base64'); }); it('should write JS strings', function() { RT('string'); }); + if(typeof ArrayBuffer !== 'undefined' && (typeof process == 'undefined' || !process.version.match(/v0.12/))) it('should write array buffers', function() { RT('array'); }); if(!browser) it('should write buffers', function() { RT('buffer'); }); it('should throw if format is unknown', function() { assert.throws(function() { RT('dafuq'); }); }); }); @@ -819,10 +820,10 @@ describe('parse features', function() { var wbs=[]; var bef = (function() { wbs = [ - X.read(fs.readFileSync(paths.cpxlsx), {type:TYPE}), - X.read(fs.readFileSync(paths.cpxlsb), {type:TYPE}), - X.read(fs.readFileSync(paths.cpxls), {type:TYPE}), - X.read(fs.readFileSync(paths.cpxml), {type:TYPE}) + X.read(fs.readFileSync(paths.cpxlsx), {type:TYPE, WTF:1}), + X.read(fs.readFileSync(paths.cpxlsb), {type:TYPE, WTF:1}), + X.read(fs.readFileSync(paths.cpxls), {type:TYPE, WTF:1}), + X.read(fs.readFileSync(paths.cpxml), {type:TYPE, WTF:1}) ]; }); if(typeof before != 'undefined') before(bef); @@ -1319,7 +1320,7 @@ describe('roundtrip features', function() { }); }); describe('should preserve merge cells', function() { - ["xlsx", "xlsb", "xlml", "ods"].forEach(function(f) { it(f, function() { + ["xlsx", "xlsb", "xlml", "ods", "biff8"].forEach(function(f) { it(f, function() { var wb1 = X.read(fs.readFileSync(paths.mcxlsx), {type:TYPE}); var wb2 = X.read(X.write(wb1,{bookType:f,type:'binary'}),{type:'binary'}); var m1 = wb1.Sheets.Merge['!merges'].map(X.utils.encode_range); @@ -1911,8 +1912,15 @@ describe('HTML', function() { it('should generate strings if raw option is passed', function() { plaintext_test(X.utils.table_to_book(get_dom_element(html_str), {raw:true}), true, true); }); it('should handle newlines correctly', function() { var table = get_dom_element("
foo bar | baz |
foo bar | baz qux |
0){if(e.strm.data_type===o){e.strm.data_type=fe(e)}ne(e,e.l_desc);ne(e,e.d_desc);l=oe(e);i=e.opt_len+3+7>>>3;s=e.static_len+3+7>>>3;if(s<=i){i=s}}else{i=s=t+5}if(t+4<=i&&r!==-1){he(e,r,t,a)}else if(e.strategy===n||s===i){G(e,(c<<1)+(a?1:0),3);ae(e,D,O)}else{G(e,(u<<1)+(a?1:0),3);le(e,e.l_desc.max_code+1,e.d_desc.max_code+1,l+1);ae(e,e.dyn_ltree,e.dyn_dtree)}J(e);if(a){q(e)}}function pe(e,r,t){e.pending_buf[e.d_buf+e.last_lit*2]=r>>>8&255;e.pending_buf[e.d_buf+e.last_lit*2+1]=r&255;e.pending_buf[e.l_buf+e.last_lit]=t&255;e.last_lit++;if(r===0){e.dyn_ltree[t*2]++}else{e.matches++;r--;e.dyn_ltree[(P[t]+p+1)*2]++;e.dyn_dtree[V(r)*2]++}return e.last_lit===e.lit_bufsize-1}t._tr_init=ue;t._tr_stored_block=he;t._tr_flush_block=ve;t._tr_tally=pe;t._tr_align=de},{"../utils/common":27}],39:[function(e,r,t){"use strict";function a(){this.input=null;this.next_in=0;this.avail_in=0;this.total_in=0;this.output=null;this.next_out=0;this.avail_out=0;this.total_out=0;this.msg="";this.state=null;this.data_type=2;this.adler=0}r.exports=a},{}]},{},[9])(9)});var XLSX={};(function e(r){r.version="0.11.15";var t=1200;if(typeof module!=="undefined"&&typeof require!=="undefined"){if(typeof cptable==="undefined")global.cptable=undefined}function a(){n(1200)}var n=function(e){t=e};function i(e){var r=[];for(var t=0,a=e.length;t>1;++t)r[t]=String.fromCharCode(e.charCodeAt(2*t)+(e.charCodeAt(2*t+1)<<8));return r.join("")}function o(e){var r=[];for(var t=0;t0&&u!==R)_[u].name="!MiniFAT";_[v[0]].name="!FAT";_.fat_addrs=v;_.ssz=a;var B={},T=[],x=[],I=[];k(s,_,C,T,n,B,x,u);c(x,I,T);T.shift();var A={FileIndex:x,FullPaths:I};if(r&&r.raw)A.raw={header:m,sectors:C};return A}function o(e){e.chk(D,"Header Signature: ");e.chk(F,"CLSID: ");var r=e._R(2,"u");return[e._R(2,"u"),r]}function l(e,r){var t=9;e.l+=2;switch(t=e._R(2)){case 9:if(r!=3)throw new Error("Sector Shift: Expected 9 saw "+t);break;case 12:if(r!=4)throw new Error("Sector Shift: Expected 12 saw "+t);break;default:throw new Error("Sector Shift: Expected 9 or 12 saw "+t);}e.chk("0600","Mini Sector Shift: ");e.chk("000000000000","Reserved: ")}function f(e,r){var t=Math.ceil(e.length/r)-1;var a=[];for(var n=1;na.l)a=a.slice(0,a.l);if(a.length>0)e.push(a);a=null};var i=function c(e){if(a&&e":a.strike=1;break;case"":break;case"":;case"":a.u=1;break;case"":break;case"":;case"":a.b=1;break;case"":break;case"":;case"":a.i=1;break;case"":break;case"");t.push("")}if(i=="superscript")i="sup";else if(i=="subscript")i="sub";if(i!=""){r.push("<"+i+">");t.push(""+i+">")}t.push("");return n};function s(t){var a=[[],"",[]];var s=t.match(e),o=65001;if(!x(s))return"";a[1]=s[1];var l=t.match(r);if(x(l))o=i(l[1],a[0],a[2]);return a[0].join("")+a[1].replace(n,"
")+a[2].join("")}return function l(e){return e.replace(t,"").split(a).map(s).join("")}}();var Ds=/<(?:\w+:)?t[^>]*>([^<]*)<\/(?:\w+:)?t>/g,Os=/<(?:\w+:)?r>/;var Fs=/<(?:\w+:)?rPh.*?>([\s\S]*?)<\/(?:\w+:)?rPh>/g;function Ps(e,r){var t=r?r.cellHTML:true;var a={};if(!e)return null;var n;if(e.match(/^\s*<(?:\w+:)?t[^>]*>/)){a.t=pe(Be(e.slice(e.indexOf(">")+1).split(/<\/(?:\w+:)?t>/)[0]||""));a.r=Be(e);if(t)a.h=we(a.t)}else if(n=e.match(Os)){a.r=Be(e);a.t=pe(Be((e.replace(Fs,"").match(Ds)||[]).join("").replace(le,"")));if(t)a.h=Rs(a.r)}return a}var Ns=/<(?:\w+:)?sst([^>]*)>([\s\S]*)<\/(?:\w+:)?sst>/;var Ls=/<(?:\w+:)?(?:si|sstItem)>/g;var Ms=/<\/(?:\w+:)?(?:si|sstItem)>/;function Us(e,r){var t=[],a="";if(!e)return t;var n=e.match(Ns);if(x(n)){a=n[2].replace(Ls,"").split(Ms);for(var i=0;i!=a.length;++i){var s=Ps(a[i].trim(),r);if(s!=null)t[t.length]=s}n=ue(n[1]);t.Count=n.count;t.Unique=n.uniqueCount}return t}ha.SST="http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings";var Hs=/^\s|\s$|[\t\n\r]/;function Ws(e,r){if(!r.bookSST)return"";var t=[se];t[t.length]=Ue("sst",null,{xmlns:ze.main[0],count:e.Count,uniqueCount:e.Unique});for(var a=0;a!=e.length;++a){if(e[a]==null)continue;var n=e[a];var i="":n.strike=1;break;case""+s+"
");a.push(yv(i,r,e,t));return a.join("")}function Nv(e,r){var t=[];t.push(xv(e,r));t.push(Iv(e,r));t.push(Av(e,r));for(var a=0;a]*>)/i," ");var f=-1,u=0,h=0,d=0;var v={s:{r:1e7,c:1e7},e:{r:0,c:0}};var p=[],b=0;for(s=0;s ";return p+i.join("")+" "}function a(e,r,t){var a=[];return a.join("")+""}var n='
"+f);return c.join("")}return{to_workbook:r,to_sheet:e,_row:t,BEGIN:n,END:i,_preamble:a,from_sheet:s}}();function fp(e,r){var t=r||{};if(c!=null)t.dense=c;var a=t.dense?[]:{};var n=e.getElementsByTagName("tr");var i={s:{r:0,c:0},e:{r:n.length-1,c:0}};var s=[],o=0;var l=0,f=0,u=0,h=0,d=0;for(;l1){o[a++]=65533;continue}if(n<65536){o[a++]=n}else{n-=65536;o[a++]=55296|n>>10&1023;o[a++]=56320|n&1023}}return f(o,a)};t.utf8border=function(e,r){var t;r=r||e.length;if(r>e.length){r=e.length}t=r-1;while(t>=0&&(e[t]&192)===128){t--}if(t<0){return r}if(t===0){return r}return t+l[e[t]]>r?t:r}},{"./common":27}],29:[function(e,r,t){"use strict";function a(e,r,t,a){var n=e&65535|0,i=e>>>16&65535|0,s=0;while(t!==0){s=t>2e3?2e3:t;t-=s;do{n=n+r[a++]|0;i=i+n|0}while(--s);n%=65521;i%=65521}return n|i<<16|0}r.exports=a},{}],30:[function(e,r,t){r.exports={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8}},{}],31:[function(e,r,t){"use strict";function a(){var e,r=[];for(var t=0;t<256;t++){e=t;for(var a=0;a<8;a++){e=e&1?3988292384^e>>>1:e>>>1}r[t]=e}return r}var n=a();function i(e,r,t,a){var i=n,s=a+t;e=e^-1;for(var l=a;l>>8^i[(e^r[l])&255]}return e^-1}r.exports=i},{}],32:[function(e,r,t){"use strict";var a=e("../utils/common");var n=e("./trees");var i=e("./adler32");var s=e("./crc32");var l=e("./messages");var o=0;var f=1;var c=3;var u=4;var h=5;var d=0;var v=1;var p=-2;var b=-3;var m=-5;var g=-1;var E=1;var k=2;var w=3;var S=4;var C=0;var _=2;var B=8;var T=9;var x=15;var I=8;var A=29;var y=256;var R=y+1+A;var D=30;var O=19;var F=2*R+1;var P=15;var N=3;var L=258;var M=L+N+1;var U=32;var H=42;var V=69;var W=73;var z=91;var X=103;var G=113;var j=666;var K=1;var Y=2;var $=3;var Z=4;var Q=3;function J(e,r){e.msg=l[r];return r}function q(e){return(e<<1)-(e>4?9:0)}function ee(e){var r=e.length;while(--r>=0){e[r]=0}}function re(e){var r=e.state;var t=r.pending;if(t>e.avail_out){t=e.avail_out}if(t===0){return}a.arraySet(e.output,r.pending_buf,r.pending_out,t,e.next_out);e.next_out+=t;r.pending_out+=t;e.total_out+=t;e.avail_out-=t;r.pending-=t;if(r.pending===0){r.pending_out=0}}function te(e,r){n._tr_flush_block(e,e.block_start>=0?e.block_start:-1,e.strstart-e.block_start,r);e.block_start=e.strstart;re(e.strm)}function ae(e,r){e.pending_buf[e.pending++]=r}function ne(e,r){e.pending_buf[e.pending++]=r>>>8&255;e.pending_buf[e.pending++]=r&255}function ie(e,r,t,n){var l=e.avail_in;if(l>n){l=n}if(l===0){return 0}e.avail_in-=l;a.arraySet(r,e.input,e.next_in,l,t);if(e.state.wrap===1){e.adler=i(e.adler,r,l,t)}else if(e.state.wrap===2){e.adler=s(e.adler,r,l,t)}e.next_in+=l;e.total_in+=l;return l}function se(e,r){var t=e.max_chain_length;var a=e.strstart;var n;var i;var s=e.prev_length;var l=e.nice_match;var o=e.strstart>e.w_size-M?e.strstart-(e.w_size-M):0;var f=e.window;var c=e.w_mask;var u=e.prev;var h=e.strstart+L;var d=f[a+s-1];var v=f[a+s];if(e.prev_length>=e.good_match){t>>=2}if(l>e.lookahead){l=e.lookahead}do{n=r;if(f[n+s]!==v||f[n+s-1]!==d||f[n]!==f[a]||f[++n]!==f[a+1]){continue}a+=2;n++;do{}while(f[++a]===f[++n]&&f[++a]===f[++n]&&f[++a]===f[++n]&&f[++a]===f[++n]&&f[++a]===f[++n]&&f[++a]===f[++n]&&f[++a]===f[++n]&&f[++a]===f[++n]&&ae.lookahead){e.match_length=e.lookahead}}}if(e.match_length>=N){t=n._tr_tally(e,1,e.match_length-N);e.lookahead-=e.match_length;e.strstart+=e.match_length;e.match_length=0}else{t=n._tr_tally(e,0,e.window[e.strstart]);e.lookahead--;e.strstart++}if(t){te(e,false);if(e.strm.avail_out===0){return K}}}e.insert=0;if(r===u){te(e,true);if(e.strm.avail_out===0){return $}return Z}if(e.last_lit){te(e,false);if(e.strm.avail_out===0){return K}}return Y}function he(e,r){var t;for(;;){if(e.lookahead===0){le(e);if(e.lookahead===0){if(r===o){return K}break}}e.match_length=0;t=n._tr_tally(e,0,e.window[e.strstart]);e.lookahead--;e.strstart++;if(t){te(e,false);if(e.strm.avail_out===0){return K}}}e.insert=0;if(r===u){te(e,true);if(e.strm.avail_out===0){return $}return Z}if(e.last_lit){te(e,false);if(e.strm.avail_out===0){return K}}return Y}var de=function(e,r,t,a,n){this.good_length=e;this.max_lazy=r;this.nice_length=t;this.max_chain=a;this.func=n};var ve;ve=[new de(0,0,0,0,oe),new de(4,4,8,4,fe),new de(4,5,16,8,fe),new de(4,6,32,32,fe),new de(4,4,16,16,ce),new de(8,16,32,32,ce),new de(8,16,128,128,ce),new de(8,32,128,256,ce),new de(32,128,258,1024,ce),new de(32,258,258,4096,ce)];function pe(e){e.window_size=2*e.w_size;ee(e.head);e.max_lazy_match=ve[e.level].max_lazy;e.good_match=ve[e.level].good_length;e.nice_match=ve[e.level].nice_length;e.max_chain_length=ve[e.level].max_chain;e.strstart=0;e.block_start=0;e.lookahead=0;e.insert=0;e.match_length=e.prev_length=N-1;e.match_available=0;e.ins_h=0}function be(){this.strm=null;this.status=0;this.pending_buf=null;this.pending_buf_size=0;this.pending_out=0;this.pending=0;this.wrap=0;this.gzhead=null;this.gzindex=0;this.method=B;this.last_flush=-1;this.w_size=0;this.w_bits=0;this.w_mask=0;this.window=null;this.window_size=0;this.prev=null;this.head=null;this.ins_h=0;this.hash_size=0;this.hash_bits=0;this.hash_mask=0;this.hash_shift=0;this.block_start=0;this.match_length=0;this.prev_match=0;this.match_available=0;this.strstart=0;this.match_start=0;this.lookahead=0;this.prev_length=0;this.max_chain_length=0;this.max_lazy_match=0;this.level=0;this.strategy=0;this.good_match=0;this.nice_match=0;this.dyn_ltree=new a.Buf16(F*2);this.dyn_dtree=new a.Buf16((2*D+1)*2);this.bl_tree=new a.Buf16((2*O+1)*2);ee(this.dyn_ltree);ee(this.dyn_dtree);ee(this.bl_tree);this.l_desc=null;this.d_desc=null;this.bl_desc=null;this.bl_count=new a.Buf16(P+1);this.heap=new a.Buf16(2*R+1);ee(this.heap);this.heap_len=0;this.heap_max=0;this.depth=new a.Buf16(2*R+1);ee(this.depth);this.l_buf=0;this.lit_bufsize=0;this.last_lit=0;this.d_buf=0;this.opt_len=0;this.static_len=0;this.matches=0;this.insert=0;this.bi_buf=0;this.bi_valid=0}function me(e){var r;if(!e||!e.state){return J(e,p)}e.total_in=e.total_out=0;e.data_type=_;r=e.state;r.pending=0;r.pending_out=0;if(r.wrap<0){r.wrap=-r.wrap}r.status=r.wrap?H:G;e.adler=r.wrap===2?0:1;r.last_flush=o;n._tr_init(r);return d}function ge(e){var r=me(e);if(r===d){pe(e.state)}return r}function Ee(e,r){if(!e||!e.state){return p}if(e.state.wrap!==2){return p}e.state.gzhead=r;return d}function ke(e,r,t,n,i,s){if(!e){return p}var l=1;if(r===g){r=6}if(n<0){l=0;n=-n}else if(n>15){l=2;n-=16}if(i<1||i>T||t!==B||n<8||n>15||r<0||r>9||s<0||s>S){return J(e,p)}if(n===8){n=9}var o=new be;e.state=o;o.strm=e;o.wrap=l;o.gzhead=null;o.w_bits=n;o.w_size=1<>>=S;b-=S}if(b<15){p+=x[i++]<>>24;p>>>=S;b-=S;S=w>>>16&255;if(S&16){_=w&65535;S&=15;if(bc){e.msg="invalid distance too far back";t.mode=a;break e}p>>>=S;b-=S;S=l-o;if(_>S){S=_-S;if(S>h){if(t.sane){e.msg="invalid distance too far back";t.mode=a;break e}}B=0;T=v;if(d===0){B+=u-S;if(S>3;i-=C;b-=C<<3;p&=(1<>>24&255)+(e>>>8&65280)+((e&65280)<<8)+((e&255)<<24)}function ie(){this.mode=0;this.last=false;this.wrap=0;this.havedict=false;this.flags=0;this.dmax=0;this.check=0;this.total=0;this.head=null;this.wbits=0;this.wsize=0;this.whave=0;this.wnext=0;this.window=null;this.hold=0;this.bits=0;this.length=0;this.offset=0;this.extra=0;this.lencode=null;this.distcode=null;this.lenbits=0;this.distbits=0;this.ncode=0;this.nlen=0;this.ndist=0;this.have=0;this.next=null;this.lens=new a.Buf16(320);this.work=new a.Buf16(288);this.lendyn=null;this.distdyn=null;this.sane=0;this.back=0;this.was=0}function se(e){var r;if(!e||!e.state){return m}r=e.state;e.total_in=e.total_out=r.total=0;e.msg="";if(r.wrap){e.adler=r.wrap&1}r.mode=S;r.last=0;r.havedict=0;r.dmax=32768;r.head=null;r.hold=0;r.bits=0;r.lencode=r.lendyn=new a.Buf32(ee);r.distcode=r.distdyn=new a.Buf32(re);r.sane=1;r.back=-1;return v}function le(e){var r;if(!e||!e.state){return m}r=e.state;r.wsize=0;r.whave=0;r.wnext=0;return se(e)}function oe(e,r){var t;var a;if(!e||!e.state){return m}a=e.state;if(r<0){t=0;r=-r}else{t=(r>>4)+1;if(r<48){r&=15}}if(r&&(r<8||r>15)){return m}if(a.window!==null&&a.wbits!==r){a.window=null}a.wrap=t;a.wbits=r;return le(e)}function fe(e,r){var t;var a;if(!e){return m}a=new ie;e.state=a;a.window=null;t=oe(e,r);if(t!==v){e.state=null}return t}function ce(e){return fe(e,ae)}var ue=true;var he,de;function ve(e){if(ue){var r;he=new a.Buf32(512);de=new a.Buf32(32);r=0;while(r<144){e.lens[r++]=8}while(r<256){e.lens[r++]=9}while(r<280){e.lens[r++]=7}while(r<288){e.lens[r++]=8}l(f,e.lens,0,288,he,0,e.work,{bits:9});r=0;while(r<32){e.lens[r++]=5}l(c,e.lens,0,32,de,0,e.work,{bits:5});ue=false}e.lencode=he;e.lenbits=9;e.distcode=de;e.distbits=5}function pe(e,r,t,n){var i;var s=e.state;if(s.window===null){s.wsize=1<