updating to 0.8.5

This commit is contained in:
SheetJS 2017-02-21 23:48:52 -08:00
parent 91f1aa5dd5
commit f8858276e7
6 changed files with 203 additions and 83 deletions

11
.gitignore vendored

@ -1,5 +1,14 @@
test_files/
node_modules/
*.[cC][sS][vV]
*.[dD][iI][fF]
*.[pP][rR][nN]
*.[sS][lL][kK]
*.socialcalc
*.[xX][lL][sSwW]
*.[xX][lL][sS][xXmMbB]
*.[xX][lL][sS]
*.[oO][dD][sS]
*.[fF][oO][dD][sS]
*.[xX][mM][lL]
*.[uU][oO][sS]
*.sheetjs

2
dist/ods.js vendored

File diff suppressed because one or more lines are too long

112
ods.js

@ -65,7 +65,7 @@ if (typeof exports !== 'undefined') {
_fs = require('f'+'s');
}
}
var attregexg=/\b[\w:-]+=["'][^"]*['"]/g;
var attregexg=/[^\s?>\/]+=["'][^"]*['"]/g;
var tagregex=/<[^>]*>/g;
var nsregex=/<\w*:/, nsregex2 = /<(\/?)\w+:/;
function parsexmltag(tag, skip_root) {
@ -80,8 +80,15 @@ function parsexmltag(tag, skip_root) {
for(c=0; c != cc.length; ++c) if(cc.charCodeAt(c) === 61) break;
q = cc.substr(0,c); v = cc.substring(c+2, cc.length-1);
for(j=0;j!=q.length;++j) if(q.charCodeAt(j) === 58) break;
if(j===q.length) z[q] = v;
else z[(j===5 && q.substr(0,5)==="xmlns"?"xmlns":"")+q.substr(j+1)] = v;
if(j===q.length) {
if(q.indexOf("_") > 0) q = q.substr(0, q.indexOf("_"));
z[q] = v;
}
else {
var k = (j===5 && q.substr(0,5)==="xmlns"?"xmlns":"")+q.substr(j+1);
if(z[k] && q.substr(j-3,3) == "ext") continue;
z[k] = v;
}
}
return z;
}
@ -163,7 +170,8 @@ function xlml_normalize(d) {
throw "badf";
}
var xlmlregex = /<(\/?)([a-z0-9]*:|)([\w-]+)[^>]*>/mg;
/* UOS uses CJK in tags, original regex /<(\/?)([a-z0-9]*:|)([\w-]+)[^>]*>/ */
var xlmlregex = /<(\/?)([^\s?>\/:]*:|)([^\s?>]*[^\s?>\/])[^>]*>/mg;
/* Part 3 Section 4 Manifest File */
var CT_ODS = "application/vnd.oasis.opendocument.spreadsheet";
function parse_manifest(d, opts) {
@ -220,7 +228,7 @@ function write_rdf(rdf, opts) {
return o.join("");
}
var parse_text_p = function(text, tag) {
return unescapexml(utf8read(text.replace(/<text:s\/>/g," ").replace(/<[^>]*>/g,"")));
return unescapexml(text.replace(/<text:s\/>/g," ").replace(/<[^>]*>/g,""));
};
var utf8read = function utf8reada(orig) {
@ -270,6 +278,7 @@ var parse_content_xml = (function() {
var tag;
var NFtag = {name:""}, NF = "", pidx = 0;
var sheetag;
var rowtag;
var Sheets = {}, SheetNames = [], ws = {};
var Rn, q;
var ctag = {value:""};
@ -281,13 +290,13 @@ var parse_content_xml = (function() {
var rept = 1, isstub = false;
var i = 0;
xlmlregex.lastIndex = 0;
while((Rn = xlmlregex.exec(str))) switch(Rn[3]) {
while((Rn = xlmlregex.exec(str))) switch(Rn[3]=Rn[3].replace(/_.*$/,"")) {
case 'table': // 9.1.2 <table:table>
case 'table': case '工作表': // 9.1.2 <table:table>
if(Rn[1]==='/') {
if(range.e.c >= range.s.c && range.e.r >= range.s.r) ws['!ref'] = get_utils().encode_range(range);
if(merges.length) ws['!merges'] = merges;
sheetag.name = utf8read(sheetag.name);
sheetag.name = utf8read(sheetag['名称'] || sheetag.name);
SheetNames.push(sheetag.name);
Sheets[sheetag.name] = ws;
}
@ -299,12 +308,14 @@ var parse_content_xml = (function() {
}
break;
case 'table-row': // 9.1.3 <table:table-row>
case 'table-row': case '行': // 9.1.3 <table:table-row>
if(Rn[1] === '/') break;
++R; C = -1; break;
rowtag = parsexmltag(Rn[0], false);
if(rowtag['行号']) R = rowtag['行号'] - 1; else ++R;
C = -1; break;
case 'covered-table-cell': // 9.1.5 table:covered-table-cell
++C; break; /* stub */
case 'table-cell':
case 'table-cell': case '数据':
if(Rn[0].charAt(Rn[0].length-2) === '/') {
ctag = parsexmltag(Rn[0], false);
if(ctag['number-columns-repeated']) C+= parseInt(ctag['number-columns-repeated'], 10);
@ -318,7 +329,7 @@ var parse_content_xml = (function() {
if(C < range.s.c) range.s.c = C;
if(R < range.s.r) range.s.r = R;
ctag = parsexmltag(Rn[0], false);
q = ({t:ctag['value-type'], v:null});
q = ({t:ctag['数据类型'] || ctag['value-type'], v:null});
if(opts.cellFormula) {
if(ctag['number-matrix-columns-spanned'] && ctag['number-matrix-rows-spanned']) {
mR = parseInt(ctag['number-matrix-rows-spanned'],10) || 0;
@ -351,8 +362,9 @@ var parse_content_xml = (function() {
case 'currency': q.t = 'n'; q.v = parseFloat(ctag.value); break;
case 'date': q.t = 'n'; q.v = datenum(ctag['date-value']); q.z = 'm/d/yy'; break;
case 'time': q.t = 'n'; q.v = parse_isodur(ctag['time-value'])/86400; break;
case 'number': q.t = 'n'; q.v = parseFloat(ctag['数据数值']); break;
default:
if(q.t === 'string' || !q.t) {
if(q.t === 'string' || q.t === 'text' || !q.t) {
q.t = 's';
if(ctag['string-value'] != null) textp = ctag['string-value'];
} else throw new Error('Unsupported value type ' + q.t);
@ -377,15 +389,23 @@ var parse_content_xml = (function() {
break; // 9.1.4 <table:table-cell>
/* pure state */
case 'document-content': // 3.1.3.2 <office:document-content>
case 'spreadsheet': // 3.7 <office:spreadsheet>
case 'document': // TODO: <office:document> is the root for FODS
case 'document-content': case '电子表格文档': // 3.1.3.2 <office:document-content>
case 'spreadsheet': case '主体': // 3.7 <office:spreadsheet>
case 'scripts': // 3.12 <office:scripts>
case 'styles': // TODO <office:styles>
case 'font-face-decls': // 3.14 <office:font-face-decls>
if(Rn[1]==='/'){if((tmp=state.pop())[0]!==Rn[3]) throw "Bad state: "+tmp;}
else if(Rn[0].charAt(Rn[0].length-2) !== '/') state.push([Rn[3], true]);
break;
/* ignore state */
case 'meta': case '元数据': // TODO: <office:meta> <uof:元数据> FODS/UOF
case 'settings': // TODO: <office:settings>
case 'config-item-set': // TODO: <office:config-item-set>
case 'config-item-map-indexed': // TODO: <office:config-item-map-indexed>
case 'config-item-map-entry': // TODO: <office:config-item-map-entry>
case 'config-item-map-named': // TODO: <office:config-item-map-entry>
case 'shapes': // 9.2.8 <table:shapes>
case 'frame': // 10.4.2 <draw:frame>
case 'text-box': // 10.4.3 <draw:text-box>
@ -395,11 +415,18 @@ var parse_content_xml = (function() {
case 'form': // 13.13 <form:form>
case 'dde-links': // 9.8 <table:dde-links>
case 'annotation': // 14.1 <office:annotation>
case 'event-listeners': // TODO
if(Rn[1]==='/'){if((tmp=state.pop())[0]!==Rn[3]) throw "Bad state: "+tmp;}
else if(Rn[0].charAt(Rn[0].length-2) !== '/') state.push([Rn[3], false]);
textp = ""; textpidx = 0;
break;
case 'scientific-number': // TODO: <number:scientific-number>
break;
case 'currency-symbol': // TODO: <number:currency-symbol>
break;
case 'currency-style': // TODO: <number:currency-style>
break;
case 'number-style': // 16.27.2 <number:number-style>
case 'percentage-style': // 16.27.9 <number:percentage-style>
case 'date-style': // 16.27.10 <number:date-style>
@ -414,8 +441,12 @@ var parse_content_xml = (function() {
} break;
case 'script': break; // 3.13 <office:script>
case 'libraries': break; // TODO: <ooo:libraries>
case 'automatic-styles': break; // 3.15.3 <office:automatic-styles>
case 'master-styles': break; // TODO: <office:automatic-styles>
case 'default-style': // TODO: <style:default-style>
case 'page-layout': break; // TODO: <style:page-layout>
case 'style': break; // 16.2 <style:style>
case 'map': break; // 16.3 <style:map>
case 'font-face': break; // 16.21 <style:font-face>
@ -458,7 +489,7 @@ var parse_content_xml = (function() {
case 'boolean': break; // 16.27.24 <number:boolean>
case 'text-style': break; // 16.27.25 <number:text-style>
case 'text': // 16.27.26 <number:text>
if(Rn[0].substr(-2) === "/>") break;
if(Rn[0].slice(-2) === "/>") break;
else if(Rn[1]==="/") switch(state[state.length-1][0]) {
case 'number-style':
case 'date-style':
@ -471,7 +502,7 @@ var parse_content_xml = (function() {
case 'text-content': break; // 16.27.27 <number:text-content>
case 'text-properties': break; // 16.27.27 <style:text-properties>
case 'body': break; // 3.3 16.9.6 19.726.3
case 'body': case '电子表格': break; // 3.3 16.9.6 19.726.3
case 'forms': break; // 12.25.2 13.2
case 'table-column': break; // 9.1.6 <table:table-column>
@ -489,7 +520,7 @@ var parse_content_xml = (function() {
case 'span': break; // <text:span>
case 'line-break': break; // 6.1.5 <text:line-break>
case 'p':
case 'p': case '文本串':
if(Rn[1]==='/') textp = parse_text_p(str.slice(textpidx,Rn.index), textptag);
else { textptag = parsexmltag(Rn[0], false); textpidx = Rn.index + Rn[0].length; }
break; // <text:p>
@ -497,7 +528,7 @@ var parse_content_xml = (function() {
case 'date': break; // <*:date>
case 'object': break; // 10.4.6.2 <draw:object>
case 'title': break; // <*:title>
case 'title': case '标题': break; // <*:title> OR <uof:标题>
case 'desc': break; // <*:desc>
case 'table-source': break; // 9.2.6
@ -541,6 +572,25 @@ var parse_content_xml = (function() {
case 'sheet-name': // 7.3.9
break;
case 'event-listener': // TODO
/* TODO: FODS Properties */
case 'initial-creator':
case 'creator':
case 'creation-date':
case 'generator':
case 'document-statistic':
case 'user-defined':
break;
/* TODO: FODS Config */
case 'config-item':
break;
/* TODO: style tokens */
case 'page-number': break; // TODO <text:page-number>
case 'page-count': break; // TODO <text:page-count>
case 'time': break; // TODO <text:time>
/* 9.6 Data Pilot Tables <table: */
case 'data-pilot-table': // 9.6.3
case 'source-cell-range': // 9.6.5
@ -582,7 +632,12 @@ var parse_content_xml = (function() {
default:
if(Rn[2] === 'dc:') break; // TODO: properties
if(Rn[2] === 'draw:') break; // TODO: drawing
if(Rn[2] === 'style:') break; // TODO: styles
if(Rn[2] === 'calcext:') break; // ignore undocumented extensions
if(Rn[2] === 'loext:') break; // ignore undocumented extensions
if(Rn[2] === 'uof:') break; // TODO: uof
if(Rn[2] === '表:') break; // TODO: uof
if(Rn[2] === '字:') break; // TODO: uof
if(opts.WTF) throw Rn;
}
var out = {
@ -623,23 +678,33 @@ var write_content_xml = (function() {
return function wcx(wb, opts) {
var o = [XML_HEADER];
/* 3.1.3.2 */
o.push('<office:document-content office:version="1.2" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0">\n'); // TODO
if(opts.bookType == "fods") o.push('<office:document xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:presentation="urn:oasis:names:tc:opendocument:xmlns:presentation:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0" xmlns:ooo="http://openoffice.org/2004/office" xmlns:ooow="http://openoffice.org/2004/writer" xmlns:oooc="http://openoffice.org/2004/calc" xmlns:dom="http://www.w3.org/2001/xml-events" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:rpt="http://openoffice.org/2005/report" xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:grddl="http://www.w3.org/2003/g/data-view#" xmlns:tableooo="http://openoffice.org/2009/table" xmlns:drawooo="http://openoffice.org/2010/draw" xmlns:calcext="urn:org:documentfoundation:names:experimental:calc:xmlns:calcext:1.0" xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0" xmlns:field="urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0" xmlns:formx="urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0" xmlns:css3t="http://www.w3.org/TR/css3-text/" office:version="1.2" office:mimetype="application/vnd.oasis.opendocument.spreadsheet">');
else o.push('<office:document-content office:version="1.2" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0">\n'); // TODO
o.push(' <office:body>\n');
o.push(' <office:spreadsheet>\n');
for(var i = 0; i != wb.SheetNames.length; ++i) o.push(write_ws(wb.Sheets[wb.SheetNames[i]], wb, i, opts));
o.push(' </office:spreadsheet>\n');
o.push(' </office:body>\n');
o.push('</office:document-content>');
if(opts.bookType == "fods") o.push('</office:document>');
else o.push('</office:document-content>');
return o.join("");
};
})();
/* Part 3: Packages */
function parse_ods(zip, opts) {
opts = opts || ({});
var manifest = parse_manifest(getzipdata(zip, 'META-INF/manifest.xml'), opts);
return parse_content_xml(getzipdata(zip, 'content.xml'), opts);
var ods = !!safegetzipfile(zip, 'objectdata');
if(ods) var manifest = parse_manifest(getzipdata(zip, 'META-INF/manifest.xml'), opts);
var content = getzipdata(zip, 'content.xml');
return parse_content_xml(ods ? content : utf8read(content), opts);
}
function parse_fods(data, opts) {
return parse_content_xml(data, opts);
}
function write_ods(wb, opts) {
if(opts.bookType == "fods") return write_content_xml(wb, opts);
var zip = new jszip();
var f = "";
@ -669,4 +734,5 @@ var zip = new jszip();
}
ODS.parse_ods = parse_ods;
ODS.write_ods = write_ods;
ODS.parse_fods = parse_fods;
})(typeof exports !== 'undefined' ? exports : ODS);

2
ods.min.js vendored

File diff suppressed because one or more lines are too long

22
xlsx.core.min.js vendored

File diff suppressed because one or more lines are too long

137
xlsx.js

@ -4,7 +4,7 @@
/*jshint funcscope:true, eqnull:true */
var XLSX = {};
(function make_xlsx(XLSX){
XLSX.version = '0.8.4';
XLSX.version = '0.8.5';
var current_codepage = 1200, current_cptable;
if(typeof module !== "undefined" && typeof require !== 'undefined') {
if(typeof cptable === 'undefined') cptable = require('./dist/cpexcel');
@ -651,7 +651,7 @@ function eval_fmt(fmt, v, opts, flen) {
case '[':
o = c;
while(fmt[i++] !== ']' && i < fmt.length) o += fmt[i];
if(o.substr(-1) !== ']') throw 'unterminated "[" block: |' + o + '|';
if(o.slice(-1) !== ']') throw 'unterminated "[" block: |' + o + '|';
if(o.match(abstime)) {
if(dt==null) { dt=parse_date_code(v, opts); if(dt==null) return ""; }
out[out.length] = {t:'Z', v:o.toLowerCase()};
@ -1297,6 +1297,12 @@ function cc2str(arr) {
return o;
}
function str2cc(str) {
var o = [];
for(var i = 0; i != str.length; ++i) o.push(str.charCodeAt(i));
return o;
}
function dup(o) {
if(typeof JSON != 'undefined') return JSON.parse(JSON.stringify(o));
if(typeof o != 'object' || !o) return o;
@ -1319,11 +1325,15 @@ function getdatabin(data) {
if(!data) return null;
if(data.data) return char_codes(data.data);
if(data.asNodeBuffer && has_buf) return data.asNodeBuffer();
if(data._data && data._data.getContent) return Array.prototype.slice.call(data._data.getContent());
if(data._data && data._data.getContent) {
var o = data._data.getContent();
if(typeof o == "string") return str2cc(o);
return Array.prototype.slice.call(o);
}
return null;
}
function getdata(data) { return (data && data.name.substr(data.name.length-4) === ".bin") ? getdatabin(data) : getdatastr(data); }
function getdata(data) { return (data && data.name.slice(-4) === ".bin") ? getdatabin(data) : getdatastr(data); }
function safegetzipfile(zip, file) {
var f = file; if(zip.files[f]) return zip.files[f];
@ -1402,7 +1412,7 @@ var unescapexml = (function() {
var decregex=/[&<>'"]/g, charegex = /[\u0000-\u0008\u000b-\u001f]/g;
function escapexml(text){
var s = text + '';
return s.replace(decregex, function(y) { return rencoding[y]; }).replace(charegex,function(s) { return "_x" + ("000"+s.charCodeAt(0).toString(16)).substr(-4) + "_";});
return s.replace(decregex, function(y) { return rencoding[y]; }).replace(charegex,function(s) { return "_x" + ("000"+s.charCodeAt(0).toString(16)).slice(-4) + "_";});
}
/* TODO: handle codepages */
@ -1613,7 +1623,10 @@ function ReadShift(size, t) {
case 'utf8': o = __utf8(this, this.l, this.l + size); break;
case 'utf16le': size *= 2; o = __utf16le(this, this.l, this.l + size); break;
case 'wstr': o = cptable.utils.decode(current_codepage, this.slice(this.l, this.l+2*size)); size = 2 * size; break;
case 'wstr':
if(typeof cptable !== 'undefined') o = cptable.utils.decode(current_codepage, this.slice(this.l, this.l+2*size));
else return ReadShift.call(this, size, 'dbcs');
o = size = 2 * size; break;
/* [MS-OLEDS] 2.1.4 LengthPrefixedAnsiString */
case 'lpstr': o = __lpstr(this, this.l); size = 5 + o.length; break;
@ -8050,7 +8063,7 @@ return function parse_ws_xml_data(sdata, s, opts, guess) {
/* 18.3.1.4 c CT_Cell */
cells = x.substr(ri).split(cellregex);
for(ri = typeof tag.r === 'undefined' ? 0 : 1; ri != cells.length; ++ri) {
for(ri = 0; ri != cells.length; ++ri) {
x = cells[ri].trim();
if(x.length === 0) continue;
cref = x.match(rregex); idx = ri; i=0; cc=0;
@ -8691,7 +8704,7 @@ function write_ws_bin_cell(ba, cell, R, C, opts) {
}
var o = ({r:R, c:C});
/* TODO: cell style */
o.s = get_cell_style(opts.cellXfs, cell, opts);
//o.s = get_cell_style(opts.cellXfs, cell, opts);
switch(cell.t) {
case 's': case 'str':
if(opts.bookSST) {
@ -9236,17 +9249,17 @@ function write_wb_bin(wb, opts) {
return ba.end();
}
function parse_wb(data, name, opts) {
if(name.substr(name.length-4)===".bin") return parse_wb_bin((data), opts);
if(name.slice(-4)===".bin") return parse_wb_bin((data), opts);
return parse_wb_xml((data), opts);
}
function parse_ws(data, name, opts, rels, wb) {
if(name.substr(name.length-4)===".bin") return parse_ws_bin((data), opts, rels, wb);
if(name.slice(-4)===".bin") return parse_ws_bin((data), opts, rels, wb);
return parse_ws_xml((data), opts, rels, wb);
}
function parse_sty(data, name, opts) {
if(name.substr(name.length-4)===".bin") return parse_sty_bin((data), opts);
if(name.slice(-4)===".bin") return parse_sty_bin((data), opts);
return parse_sty_xml((data), opts);
}
@ -9255,42 +9268,42 @@ function parse_theme(data, name, opts) {
}
function parse_sst(data, name, opts) {
if(name.substr(name.length-4)===".bin") return parse_sst_bin((data), opts);
if(name.slice(-4)===".bin") return parse_sst_bin((data), opts);
return parse_sst_xml((data), opts);
}
function parse_cmnt(data, name, opts) {
if(name.substr(name.length-4)===".bin") return parse_comments_bin((data), opts);
if(name.slice(-4)===".bin") return parse_comments_bin((data), opts);
return parse_comments_xml((data), opts);
}
function parse_cc(data, name, opts) {
if(name.substr(name.length-4)===".bin") return parse_cc_bin((data), opts);
if(name.slice(-4)===".bin") return parse_cc_bin((data), opts);
return parse_cc_xml((data), opts);
}
function write_wb(wb, name, opts) {
return (name.substr(name.length-4)===".bin" ? write_wb_bin : write_wb_xml)(wb, opts);
return (name.slice(-4)===".bin" ? write_wb_bin : write_wb_xml)(wb, opts);
}
function write_ws(data, name, opts, wb) {
return (name.substr(name.length-4)===".bin" ? write_ws_bin : write_ws_xml)(data, opts, wb);
return (name.slice(-4)===".bin" ? write_ws_bin : write_ws_xml)(data, opts, wb);
}
function write_sty(data, name, opts) {
return (name.substr(name.length-4)===".bin" ? write_sty_bin : write_sty_xml)(data, opts);
return (name.slice(-4)===".bin" ? write_sty_bin : write_sty_xml)(data, opts);
}
function write_sst(data, name, opts) {
return (name.substr(name.length-4)===".bin" ? write_sst_bin : write_sst_xml)(data, opts);
return (name.slice(-4)===".bin" ? write_sst_bin : write_sst_xml)(data, opts);
}
/*
function write_cmnt(data, name:string, opts) {
return (name.substr(name.length-4)===".bin" ? write_comments_bin : write_comments_xml)(data, opts);
return (name.slice(-4)===".bin" ? write_comments_bin : write_comments_xml)(data, opts);
}
function write_cc(data, name:string, opts) {
return (name.substr(name.length-4)===".bin" ? write_cc_bin : write_cc_xml)(data, opts);
return (name.slice(-4)===".bin" ? write_cc_bin : write_cc_xml)(data, opts);
}
*/
var attregexg2=/([\w:]+)=((?:")([^"]*)(?:")|(?:')([^']*)(?:'))/g;
@ -9493,15 +9506,15 @@ function parse_xlml_xml(d, opts) {
if(cell.Index) c = +cell.Index - 1;
if(c < refguess.s.c) refguess.s.c = c;
if(c > refguess.e.c) refguess.e.c = c;
if(Rn[0].substr(-2) === "/>") ++c;
if(Rn[0].slice(-2) === "/>") ++c;
comments = [];
}
break;
case 'Row':
if(Rn[1]==='/' || Rn[0].substr(-2) === "/>") {
if(Rn[1]==='/' || Rn[0].slice(-2) === "/>") {
if(r < refguess.s.r) refguess.s.r = r;
if(r > refguess.e.r) refguess.e.r = r;
if(Rn[0].substr(-2) === "/>") {
if(Rn[0].slice(-2) === "/>") {
row = xlml_parsexmltag(Rn[0]);
if(row.Index) r = +row.Index - 1;
}
@ -9567,7 +9580,7 @@ function parse_xlml_xml(d, opts) {
case 'Alignment': break;
case 'Borders': break;
case 'Font':
if(Rn[0].substr(-2) === "/>") break;
if(Rn[0].slice(-2) === "/>") break;
else if(Rn[1]==="/") ss += str.slice(fidx, Rn.index);
else fidx = Rn.index + Rn[0].length;
break;
@ -9593,7 +9606,7 @@ function parse_xlml_xml(d, opts) {
case 'TotalTime':
case 'HyperlinkBase':
case 'Manager':
if(Rn[0].substr(-2) === "/>") break;
if(Rn[0].slice(-2) === "/>") break;
else if(Rn[1]==="/") xlml_set_prop(Props, Rn[3], str.slice(pidx, Rn.index));
else pidx = Rn.index + Rn[0].length;
break;
@ -9645,6 +9658,11 @@ function parse_xlml_xml(d, opts) {
break;
default:
/* FODS file root is <office:document> */
if(state.length == 0 && Rn[3] == "document") return parse_fods(str, opts);
/* UOS file root is <uof:UOF> */
if(state.length == 0 && Rn[3] == "UOF") return parse_fods(str, opts);
var seen = true;
switch(state[state.length-1][0]) {
/* OfficeDocumentSettings */
@ -9982,7 +10000,7 @@ function parse_xlml_xml(d, opts) {
/* CustomDocumentProperties */
if(!state[state.length-1][1]) throw 'Unrecognized tag: ' + Rn[3] + "|" + state.join("|");
if(state[state.length-1][0]==='CustomDocumentProperties') {
if(Rn[0].substr(-2) === "/>") break;
if(Rn[0].slice(-2) === "/>") break;
else if(Rn[1]==="/") xlml_set_custprop(Custprops, Rn, cp, str.slice(pidx, Rn.index));
else { cp = Rn; pidx = Rn.index + Rn[0].length; }
break;
@ -10007,6 +10025,7 @@ function parse_xlml(data, opts) {
}
}
/* TODO */
function write_xlml(wb, opts) {
var o = [XML_HEADER];
return o.join("");
@ -12067,20 +12086,12 @@ function write_biff_buf(wb, o) {
// TODO
return ba.end();
}
function write_biff(wb, o) {
var out = write_biff_buf(wb, o);
switch(o.type) {
case "base64": break; // TODO
case "binary": {
var bstr = "";
for(var i = 0; i < out.length; ++i) bstr += String.fromCharCode(out[i]);
return bstr;
}
case "file": return _fs.writeFileSync(o.file, out);
case "buffer": return out;
default: throw new Error("Unrecognized type " + o.type);
}
/* actual implementation in utils, wrappers are for read/write */
function write_csv_str(wb, o) {
var idx = 0;
for(var i=0;i<wb.SheetNames.length;++i) if(wb.SheetNames[i] == o.sheet) idx=i;
if(idx == 0 && !!o.sheet && wb.SheetNames[0] != o.sheet) throw new Error("Sheet not found: " + o.sheet);
return sheet_to_csv(wb.Sheets[wb.SheetNames[idx]], o);
}
/* Helper functions to call out to ODS */
function parse_ods(zip, opts) {
@ -12093,6 +12104,11 @@ function write_ods(wb, opts) {
if(typeof ODS === 'undefined' || !ODS.write_ods) throw new Error("Unsupported ODS");
return ODS.write_ods(wb, opts);
}
function parse_fods(data, opts) {
if(typeof module !== "undefined" && typeof require !== 'undefined' && typeof ODS === 'undefined') ODS = require('./od' + 's');
if(typeof ODS === 'undefined' || !ODS.parse_fods) throw new Error("Unsupported ODS");
return ODS.parse_fods(data, opts);
}
function fix_opts_func(defaults) {
return function fix_opts(opts) {
for(var i = 0; i != defaults.length; ++i) {
@ -12150,7 +12166,7 @@ function safe_parse_ws(zip, path, relsPath, sheet, sheetRels, sheets, opts, wb)
} catch(e) { if(opts.WTF) throw e; }
}
var nodirs = function nodirs(x){return x.substr(-1) != '/';};
var nodirs = function nodirs(x){return x.slice(-1) != '/';};
function parse_zip(zip, opts) {
make_ssf(SSF);
opts = opts || {};
@ -12159,6 +12175,8 @@ function parse_zip(zip, opts) {
/* OpenDocument Part 3 Section 2.2.1 OpenDocument Package */
if(safegetzipfile(zip, 'META-INF/manifest.xml')) return parse_ods(zip, opts);
/* UOC */
if(safegetzipfile(zip, 'objectdata.xml')) return parse_ods(zip, opts);
var entries = keys(zip.files).filter(nodirs).sort();
var dir = parse_ct((getzipstr(zip, '[Content_Types].xml')), opts);
@ -12174,7 +12192,7 @@ function parse_zip(zip, opts) {
dir.workbooks.push(binname);
xlsb = true;
}
if(dir.workbooks[0].substr(-3) == "bin") xlsb = true;
if(dir.workbooks[0].slice(-3) == "bin") xlsb = true;
if(xlsb) set_cp(1200);
if(!opts.bookSheets && !opts.bookProps) {
@ -12424,11 +12442,36 @@ function write_zip_type(wb, opts) {
return z.generate(oopts);
}
function write_string_type(out, opts) {
switch(opts.type) {
case "base64": break; // TODO
case "binary": break; // TODO
case "file": return _fs.writeFileSync(opts.file, out, {encoding:'utf8'});
case "buffer": break; // TODO
default: return out;
}
}
function write_binary_type(out, opts) {
switch(opts.type) {
case "base64": break; // TODO
case "binary":
var bstr = "";
for(var i = 0; i < out.length; ++i) bstr += String.fromCharCode(out[i]);
return bstr;
case "file": return _fs.writeFileSync(opts.file, out);
case "buffer": return out;
default: throw new Error("Unrecognized type " + opts.type);
}
}
function writeSync(wb, opts) {
var o = opts||{};
switch(o.bookType) {
case 'xml': return write_xlml(wb, o);
case 'biff2': return write_biff(wb, o);
case 'xml': return write_string_type(write_xlml(wb, o), o);
case 'csv': return write_string_type(write_csv_str(wb, o), o);
case 'fods': return write_string_type(write_ods(wb, o), o);
case 'biff2': return write_binary_type(write_biff_buf(wb, o), o);
default: return write_zip_type(wb, o);
}
}
@ -12436,14 +12479,16 @@ function writeSync(wb, opts) {
function writeFileSync(wb, filename, opts) {
var o = opts||{}; o.type = 'file';
o.file = filename;
if(!o.bookType) switch(o.file.substr(-5).toLowerCase()) {
if(!o.bookType) switch(o.file.slice(-5).toLowerCase()) {
case '.xlsx': o.bookType = 'xlsx'; break;
case '.xlsm': o.bookType = 'xlsm'; break;
case '.xlsb': o.bookType = 'xlsb'; break;
default: switch(o.file.substr(-4).toLowerCase()) {
case '.fods': o.bookType = 'fods'; break;
default: switch(o.file.slice(-4).toLowerCase()) {
case '.xls': o.bookType = 'biff2'; break;
case '.xml': o.bookType = 'xml'; break;
case '.ods': o.bookType = 'ods'; break;
case '.csv': o.bookType = 'csv'; break;
}}
return writeSync(wb, o);
}