Socket
Socket
Sign inDemoInstall

xlsx

Package Overview
Dependencies
Maintainers
1
Versions
108
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

xlsx - npm Package Compare versions

Comparing version 0.8.0 to 0.8.8

dist/ods.min.js

5

bower.json
{
"name": "js-xlsx",
"homepage": "https://github.com/SheetJS/js-xlsx",
"main": "dist/xlsx.js",
"version": "0.8.0",
"main": "dist/xlsx.core.min.js",
"ignore": [

@@ -20,5 +19,5 @@ "bin",

"ods",
"js-xls"
"js-xls",
"js-xlsx"
]
}

453

dist/ods.js

@@ -1,2 +0,2 @@

/* ods.js (C) 2014 SheetJS -- http://sheetjs.com */
/* ods.js (C) 2014-present SheetJS -- http://sheetjs.com */
/* vim: set ts=2: */

@@ -10,6 +10,5 @@ /*jshint -W041 */

if(typeof module !== "undefined" && typeof require !== 'undefined') try {
return require('../' + 'xlsx').utils;
return require('../xlsx.js').utils;
} catch(e) {
try { return require('./' + 'xlsx').utils; }
catch(ee) { return require('xl' + 'sx').utils; }
return require('./xlsx.js').utils;
}

@@ -25,3 +24,11 @@ throw new Error("Cannot find XLSX utils");

}
function getdata(data) {
function dup(o) {
if(typeof JSON != 'undefined') return JSON.parse(JSON.stringify(o));
if(typeof o != 'object' || !o) return o;
var out = {};
for(var k in o) if(o.hasOwnProperty(k)) out[k] = dup(o[k]);
return out;
}
function getdatastr(data) {
if(!data) return null;

@@ -35,2 +42,6 @@ if(data.data) return data.data;

/* ODS and friends only use text files in container */
function getdata(data) { return getdatastr(data); }
/* NOTE: unlike ECMA-376, OASIS does not comment on filename case sensitivity */
function safegetzipfile(zip, file) {

@@ -59,8 +70,7 @@ var f = file; if(zip.files[f]) return zip.files[f];

if (typeof module !== 'undefined' && module.exports) {
if(has_buf && typeof jszip === 'undefined') jszip = require('js'+'zip');
if(typeof jszip === 'undefined') jszip = require('./js'+'zip').JSZip;
_fs = require('f'+'s');
if(typeof jszip === 'undefined') jszip = require('./jszip.js');
_fs = require('fs');
}
}
var attregexg=/\b[\w:-]+=["'][^"]*['"]/g;
var attregexg=/[^\s?>\/]+=["'][^"]*['"]/g;
var tagregex=/<[^>]*>/g;

@@ -74,3 +84,3 @@ var nsregex=/<\w*:/, nsregex2 = /<(\/?)\w+:/;

if(eq === tag.length) return z;
var m = tag.match(attregexg), j=0, w="", v="", i=0, q="", cc="";
var m = tag.match(attregexg), j=0, v="", i=0, q="", cc="";
if(m) for(i = 0; i != m.length; ++i) {

@@ -81,4 +91,11 @@ cc = m[i];

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;
}
}

@@ -106,3 +123,4 @@ return z;

// TODO: CP remap (need to read file version to determine OS)
var encregex = /&[a-z]*;/g, coderegex = /_x([\da-fA-F]+)_/g;
/* 22.4.2.4 bstr (Basic String) */
var encregex = /&[a-z]*;/g, coderegex = /_x([\da-fA-F]{4})_/g;
function unescapexml(text){

@@ -118,3 +136,3 @@ var s = text + '';

function parsexmlbool(value, tag) {
function parsexmlbool(value) {
switch(value) {

@@ -127,4 +145,5 @@ case '1': case 'true': case 'TRUE': return true;

function datenum(v) {
var epoch = Date.parse(v);
function datenum(v, date1904) {
var epoch = v.getTime();
if(date1904) epoch += 1462*24*60*60*1000;
return (epoch + 2209161600000) / (24 * 60 * 60 * 1000);

@@ -159,2 +178,4 @@ }

}
var XML_HEADER = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\r\n';
/* copied from js-xls (C) SheetJS Apache2 license */

@@ -167,6 +188,7 @@ function xlml_normalize(d) {

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";
var parse_manifest = function(d, opts) {
function parse_manifest(d, opts) {
var str = xlml_normalize(d);

@@ -178,3 +200,3 @@ var Rn;

case 'file-entry': // 4.3 <manifest:file-entry>
FEtag = parsexmltag(Rn[0]);
FEtag = parsexmltag(Rn[0], false);
if(FEtag.path == '/' && FEtag.type !== CT_ODS) throw new Error("This OpenDocument is not a spreadsheet");

@@ -187,7 +209,42 @@ break;

throw new Error("Unsupported ODS Encryption");
default: throw Rn;
default: if(opts && opts.WTF) throw Rn;
}
};
}
function write_manifest(manifest, opts) {
var o = [XML_HEADER];
o.push('<manifest:manifest xmlns:manifest="urn:oasis:names:tc:opendocument:xmlns:manifest:1.0" manifest:version="1.2">\n');
o.push(' <manifest:file-entry manifest:full-path="/" manifest:version="1.2" manifest:media-type="application/vnd.oasis.opendocument.spreadsheet"/>\n');
for(var i = 0; i < manifest.length; ++i) o.push(' <manifest:file-entry manifest:full-path="' + manifest[i][0] + '" manifest:media-type="' + manifest[i][1] + '"/>\n');
o.push('</manifest:manifest>');
return o.join("");
}
/* Part 3 Section 6 Metadata Manifest File */
function write_rdf_type(file, res, tag) {
return [
' <rdf:Description rdf:about="' + file + '">\n',
' <rdf:type rdf:resource="http://docs.oasis-open.org/ns/office/1.2/meta/' + (tag || "odf") + '#' + res + '"/>\n',
' </rdf:Description>\n'
].join("");
}
function write_rdf_has(base, file) {
return [
' <rdf:Description rdf:about="' + base + '">\n',
' <ns0:hasPart xmlns:ns0="http://docs.oasis-open.org/ns/office/1.2/meta/pkg#" rdf:resource="' + file + '"/>\n',
' </rdf:Description>\n'
].join("");
}
function write_rdf(rdf, opts) {
var o = [XML_HEADER];
o.push('<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">\n');
for(var i = 0; i != rdf.length; ++i) {
o.push(write_rdf_type(rdf[i][0], rdf[i][1]));
o.push(write_rdf_has("",rdf[i][0]));
}
o.push(write_rdf_type("","Document", "pkg"));
o.push('</rdf:RDF>');
return o.join("");
}
var parse_text_p = function(text, tag) {
return utf8read(text.replace(/<text:s\/>/g," ").replace(/<[^>]*>/g,""));
return unescapexml(text.replace(/<text:s\/>/g," ").replace(/<[^>]*>/g,""));
};

@@ -211,2 +268,13 @@

};
/* Part 3 TODO: actually parse formulae */
function ods_to_csf_formula(f) {
if(f.substr(0,3) == "of:") f = f.substr(3);
/* 5.2 Basic Expressions */
if(f.charCodeAt(0) == 61) {
f = f.substr(1);
if(f.charCodeAt(0) == 61) f = f.substr(1);
}
/* Part 3 Section 5.8 References */
return f.replace(/\[((?:\.[A-Z]+[0-9]+)(?::\.[A-Z]+[0-9]+)?)\]/g, "$1").replace(/\./g, "");
}
var parse_content_xml = (function() {

@@ -226,22 +294,28 @@

return function pcx(d, opts) {
return function pcx(d, _opts) {
var opts = _opts || {};
var str = xlml_normalize(d);
var state = [], tmp;
var tag;
var NFtag, NF, pidx;
var NFtag = {name:""}, NF = "", pidx = 0;
var sheetag;
var rowtag;
var Sheets = {}, SheetNames = [], ws = {};
var Rn, q;
var ctag;
var textp, textpidx, textptag;
var R, C, range = {s: {r:1000000,c:10000000}, e: {r:0, c:0}};
var ctag = {value:""};
var textp = "", textpidx = 0, textptag;
var R = -1, C = -1, range = {s: {r:1000000,c:10000000}, e: {r:0, c:0}};
var number_format_map = {};
var merges = [], mrange = {}, mR = 0, mC = 0;
var arrayf = [];
var rept = 1, isstub = false;
var i = 0;
xlmlregex.lastIndex = 0;
while((Rn = xlmlregex.exec(str))) switch((Rn[3]=Rn[3].replace(/_.*$/,""))) {
while((Rn = xlmlregex.exec(str))) switch(Rn[3]) {
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['名称'] || sheetag.name);
SheetNames.push(sheetag.name);

@@ -251,3 +325,3 @@ Sheets[sheetag.name] = ws;

else if(Rn[0].charAt(Rn[0].length-2) !== '/') {
sheetag = parsexmltag(Rn[0]);
sheetag = parsexmltag(Rn[0], false);
R = C = -1;

@@ -259,10 +333,12 @@ range.s.r = range.s.c = 10000000; range.e.r = range.e.c = 0;

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]);
ctag = parsexmltag(Rn[0], false);
if(ctag['number-columns-repeated']) C+= parseInt(ctag['number-columns-repeated'], 10);

@@ -273,2 +349,3 @@ else ++C;

++C;
rept = 1;
if(C > range.e.c) range.e.c = C;

@@ -278,4 +355,18 @@ if(R > range.e.r) range.e.r = R;

if(R < range.s.r) range.s.r = R;
ctag = parsexmltag(Rn[0]);
q = {t:ctag['value-type'], v:null};
ctag = parsexmltag(Rn[0], false);
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;
mC = parseInt(ctag['number-matrix-columns-spanned'],10) || 0;
mrange = {s: {r:R,c:C}, e:{r:R + mR-1,c:C + mC-1}};
q.F = get_utils().encode_range(mrange);
arrayf.push([mrange, q.F]);
}
if(ctag.formula) q.f = ods_to_csf_formula(ctag.formula);
else for(i = 0; i < arrayf.length; ++i)
if(R >= arrayf[i][0].s.r && R <= arrayf[i][0].e.r)
if(C >= arrayf[i][0].s.c && C <= arrayf[i][0].e.c)
q.F = arrayf[i][1];
}
if(ctag['number-columns-spanned'] || ctag['number-rows-spanned']) {

@@ -287,2 +378,6 @@ mR = parseInt(ctag['number-rows-spanned'],10) || 0;

}
/* 19.675.2 table:number-columns-repeated */
if(ctag['number-columns-repeated']) rept = parseInt(ctag['number-columns-repeated'], 10);
/* 19.385 office:value-type */

@@ -294,12 +389,27 @@ switch(q.t) {

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 'date': q.t = 'n'; q.v = datenum(new Date(ctag['date-value'])); q.z = 'm/d/yy'; break;
case 'time': q.t = 'n'; q.v = parse_isodur(ctag['time-value'])/86400; break;
case 'string': q.t = 's'; break;
default: throw new Error('Unsupported value type ' + q.t);
case 'number': q.t = 'n'; q.v = parseFloat(ctag['数据数值']); break;
default:
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);
}
} else {
if(q.t === 's') q.v = textp;
isstub = false;
if(q.t === 's') {
q.v = textp || '';
isstub = textpidx == 0;
}
if(textp) q.w = textp;
if(!(opts.sheetRows && opts.sheetRows < R)) ws[get_utils().encode_cell({r:R,c:C})] = q;
q = null;
if(!isstub || opts.cellStubs) {
if(!(opts.sheetRows && opts.sheetRows < R)) {
ws[get_utils().encode_cell({r:R,c:C})] = q;
while(--rept > 0) ws[get_utils().encode_cell({r:R,c:++C})] = dup(q);
if(range.e.c <= C) range.e.c = C;
}
} else { C += rept; rept = 0; }
q = {};
textp = "";
}

@@ -309,5 +419,7 @@ 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>

@@ -319,8 +431,29 @@ if(Rn[1]==='/'){if((tmp=state.pop())[0]!==Rn[3]) throw "Bad state: "+tmp;}

/* 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>
case 'image': // 10.4.4 <draw:image>
case 'data-pilot-tables': // 9.6.2 <table:data-pilot-tables>
case 'list-style': // 16.30 <text:list-style>
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>

@@ -335,3 +468,3 @@ case 'percentage-style': // 16.27.9 <number:percentage-style>

NF = "";
NFtag = parsexmltag(Rn[0]);
NFtag = parsexmltag(Rn[0], false);
state.push([Rn[3], true]);

@@ -341,5 +474,10 @@ } 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>

@@ -357,6 +495,8 @@

case 'date-style':
tag = parsexmltag(Rn[0]);
tag = parsexmltag(Rn[0], false);
NF += number_formats[Rn[3]][tag.style==='long'?1:0]; break;
} break;
case 'fraction': break; // TODO 16.27.6 <number:fraction>
case 'day': // 16.27.11 <number:day>

@@ -376,3 +516,3 @@ case 'month': // 16.27.12 <number:month>

case 'date-style':
tag = parsexmltag(Rn[0]);
tag = parsexmltag(Rn[0], false);
NF += number_formats[Rn[3]][tag.style==='long'?1:0]; break;

@@ -385,3 +525,3 @@ } break;

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]) {

@@ -399,3 +539,3 @@ case 'number-style':

case 'body': break; // 3.3 16.9.6 19.726.3
case 'body': case '电子表格': break; // 3.3 16.9.6 19.726.3

@@ -405,19 +545,32 @@ case 'forms': break; // 12.25.2 13.2

case 'graphic-properties': break;
case 'null-date': break; // 9.4.2 <table:null-date> TODO: date1904
case 'graphic-properties': break; // 17.21 <style:graphic-properties>
case 'calculation-settings': break; // 9.4.1 <table:calculation-settings>
case 'named-expressions': break; // 9.4.11 <table:named-expressions>
case 'named-range': break; // 9.4.11 <table:named-range>
case 'named-range': break; // 9.4.12 <table:named-range>
case 'named-expression': break; // 9.4.13 <table:named-expression>
case 'sort': break; // 9.4.19 <table:sort>
case 'sort-by': break; // 9.4.20 <table:sort-by>
case 'sort-groups': break; // 9.4.22 <table:sort-groups>
case 'span': break; // <text:span>
case 'p':
case 'line-break': break; // 6.1.5 <text:line-break>
case 'p': case '文本串':
if(Rn[1]==='/') textp = parse_text_p(str.slice(textpidx,Rn.index), textptag);
else { textptag = parsexmltag(Rn[0]); textpidx = Rn.index + Rn[0].length; }
else { textptag = parsexmltag(Rn[0], false); textpidx = Rn.index + Rn[0].length; }
break; // <text:p>
case 's': break; // <text:s>
case 'date': break; // <*:date>
case 'annotation': break;
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
case 'iteration': break; // 9.4.3 <table:iteration>
case 'content-validations': break; // 9.4.4 <table:
case 'content-validation': break; // 9.4.5 <table:
case 'error-message': break; // 9.4.7 <table:
case 'database-ranges': break; // 9.4.14 <table:database-ranges>

@@ -429,3 +582,98 @@ case 'database-range': break; // 9.4.15 <table:database-range>

case 'filter-condition': break; // 9.5.5 <table:filter-condition>
default: if(opts.WTF) throw Rn;
case 'list-level-style-bullet': break; // 16.31 <text:
case 'list-level-style-number': break; // 16.32 <text:
case 'list-level-properties': break; // 17.19 <style:
/* 7.3 Document Fields */
case 'sender-firstname': // 7.3.6.2
case 'sender-lastname': // 7.3.6.3
case 'sender-initials': // 7.3.6.4
case 'sender-title': // 7.3.6.5
case 'sender-position': // 7.3.6.6
case 'sender-email': // 7.3.6.7
case 'sender-phone-private': // 7.3.6.8
case 'sender-fax': // 7.3.6.9
case 'sender-company': // 7.3.6.10
case 'sender-phone-work': // 7.3.6.11
case 'sender-street': // 7.3.6.12
case 'sender-city': // 7.3.6.13
case 'sender-postal-code': // 7.3.6.14
case 'sender-country': // 7.3.6.15
case 'sender-state-or-province': // 7.3.6.16
case 'author-name': // 7.3.7.1
case 'author-initials': // 7.3.7.2
case 'chapter': // 7.3.8
case 'file-name': // 7.3.9
case 'template-name': // 7.3.9
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
case 'source-service': // 9.6.6
case 'data-pilot-field': // 9.6.7
case 'data-pilot-level': // 9.6.8
case 'data-pilot-subtotals': // 9.6.9
case 'data-pilot-subtotal': // 9.6.10
case 'data-pilot-members': // 9.6.11
case 'data-pilot-member': // 9.6.12
case 'data-pilot-display-info': // 9.6.13
case 'data-pilot-sort-info': // 9.6.14
case 'data-pilot-layout-info': // 9.6.15
case 'data-pilot-field-reference': // 9.6.16
case 'data-pilot-groups': // 9.6.17
case 'data-pilot-group': // 9.6.18
case 'data-pilot-group-member': // 9.6.19
break;
/* 10.3 Drawing Shapes */
case 'rect': // 10.3.2
break;
/* 14.6 DDE Connections */
case 'dde-connection-decls': // 14.6.2 <text:
case 'dde-connection-decl': // 14.6.3 <text:
case 'dde-link': // 14.6.4 <table:
case 'dde-source': // 14.6.5 <office:
break;
case 'properties': break; // 13.7 <form:properties>
case 'property': break; // 13.8 <form:property>
case 'a': break; // 6.1.8 hyperlink
/* non-standard */
case 'table-protection': break;
case 'data-pilot-grand-total': break; // <table:
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;
}

@@ -439,8 +687,91 @@ var out = {

})();
var write_content_xml = (function() {
var null_cell_xml = ' <table:table-cell />\n';
var write_ws = function(ws, wb, i, opts) {
/* Section 9 Tables */
var o = [];
o.push(' <table:table table:name="' + escapexml(wb.SheetNames[i]) + '">\n');
var R=0,C=0, range = get_utils().decode_range(ws['!ref']);
for(R = 0; R < range.s.r; ++R) o.push(' <table:table-row></table:table-row>\n');
for(; R <= range.e.r; ++R) {
o.push(' <table:table-row>\n');
for(C=0; C < range.s.c; ++C) o.push(null_cell_xml);
for(; C <= range.e.c; ++C) {
var ref = get_utils().encode_cell({r:R, c:C}), cell = ws[ref];
if(cell) switch(cell.t) {
case 'b': o.push(' <table:table-cell office:value-type="boolean" office:boolean-value="' + (cell.v ? 'true' : 'false') + '"><text:p>' + (cell.v ? 'TRUE' : 'FALSE') + '</text:p></table:table-cell>\n'); break;
case 'n': o.push(' <table:table-cell office:value-type="float" office:value="' + cell.v + '"><text:p>' + (cell.w||cell.v) + '</text:p></table:table-cell>\n'); break;
case 's': case 'str': o.push(' <table:table-cell office:value-type="string"><text:p>' + escapexml(cell.v) + '</text:p></table:table-cell>\n'); break;
//case 'd': // TODO
//case 'e':
default: o.push(null_cell_xml);
} else o.push(null_cell_xml);
}
o.push(' </table:table-row>\n');
}
o.push(' </table:table>\n');
return o.join("");
};
return function wcx(wb, opts) {
var o = [XML_HEADER];
/* 3.1.3.2 */
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');
if(opts.bookType == "fods") o.push('</office:document>');
else o.push('</office:document-content>');
return o.join("");
};
})();
/* Part 3: Packages */
var parse_ods = function(zip, opts) {
//var manifest = parse_manifest(getzipdata(zip, 'META-INF/manifest.xml'));
return parse_content_xml(getzipdata(zip, 'content.xml'), opts);
};
function parse_ods(zip, opts) {
opts = 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');
if(!content) throw new Error("Missing content.xml in " + (ods ? "ODS" : "UOF")+ " file");
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 = "";
var manifest = [];
var rdf = [];
/* 3:3.3 and 2:2.2.4 */
f = "mimetype";
zip.file(f, "application/vnd.oasis.opendocument.spreadsheet");
/* Part 1 Section 2.2 Documents */
f = "content.xml";
zip.file(f, write_content_xml(wb, opts));
manifest.push([f, "text/xml"]);
rdf.push([f, "ContentFile"]);
/* Part 3 Section 6 Metadata Manifest File */
f = "manifest.rdf";
zip.file(f, write_rdf(rdf, opts));
manifest.push([f, "application/rdf+xml"]);
/* Part 3 Section 4 Manifest File */
f = "META-INF/manifest.xml";
zip.file(f, write_manifest(manifest, opts));
return zip;
}
ODS.parse_ods = parse_ods;
ODS.write_ods = write_ods;
ODS.parse_fods = parse_fods;
})(typeof exports !== 'undefined' ? exports : ODS);

@@ -1,2 +0,2 @@

/* ods.js (C) 2014 SheetJS -- http://sheetjs.com */
/* ods.js (C) 2014-present SheetJS -- http://sheetjs.com */
/* vim: set ts=2: */

@@ -10,6 +10,5 @@ /*jshint -W041 */

if(typeof module !== "undefined" && typeof require !== 'undefined') try {
return require('../' + 'xlsx').utils;
return require('../xlsx.js').utils;
} catch(e) {
try { return require('./' + 'xlsx').utils; }
catch(ee) { return require('xl' + 'sx').utils; }
return require('./xlsx.js').utils;
}

@@ -25,3 +24,11 @@ throw new Error("Cannot find XLSX utils");

}
function getdata(data) {
function dup(o) {
if(typeof JSON != 'undefined') return JSON.parse(JSON.stringify(o));
if(typeof o != 'object' || !o) return o;
var out = {};
for(var k in o) if(o.hasOwnProperty(k)) out[k] = dup(o[k]);
return out;
}
function getdatastr(data) {
if(!data) return null;

@@ -35,2 +42,6 @@ if(data.data) return data.data;

/* ODS and friends only use text files in container */
function getdata(data) { return getdatastr(data); }
/* NOTE: unlike ECMA-376, OASIS does not comment on filename case sensitivity */
function safegetzipfile(zip, file) {

@@ -59,8 +70,7 @@ var f = file; if(zip.files[f]) return zip.files[f];

if (typeof module !== 'undefined' && module.exports) {
if(has_buf && typeof jszip === 'undefined') jszip = require('js'+'zip');
if(typeof jszip === 'undefined') jszip = require('./js'+'zip').JSZip;
_fs = require('f'+'s');
if(typeof jszip === 'undefined') jszip = require('./jszip.js');
_fs = require('fs');
}
}
var attregexg=/\b[\w:-]+=["'][^"]*['"]/g;
var attregexg=/[^\s?>\/]+=["'][^"]*['"]/g;
var tagregex=/<[^>]*>/g;

@@ -74,3 +84,3 @@ var nsregex=/<\w*:/, nsregex2 = /<(\/?)\w+:/;

if(eq === tag.length) return z;
var m = tag.match(attregexg), j=0, w="", v="", i=0, q="", cc="";
var m = tag.match(attregexg), j=0, v="", i=0, q="", cc="";
if(m) for(i = 0; i != m.length; ++i) {

@@ -81,4 +91,11 @@ cc = m[i];

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;
}
}

@@ -106,3 +123,4 @@ return z;

// TODO: CP remap (need to read file version to determine OS)
var encregex = /&[a-z]*;/g, coderegex = /_x([\da-fA-F]+)_/g;
/* 22.4.2.4 bstr (Basic String) */
var encregex = /&[a-z]*;/g, coderegex = /_x([\da-fA-F]{4})_/g;
function unescapexml(text){

@@ -118,3 +136,3 @@ var s = text + '';

function parsexmlbool(value, tag) {
function parsexmlbool(value) {
switch(value) {

@@ -127,4 +145,5 @@ case '1': case 'true': case 'TRUE': return true;

function datenum(v) {
var epoch = Date.parse(v);
function datenum(v, date1904) {
var epoch = v.getTime();
if(date1904) epoch += 1462*24*60*60*1000;
return (epoch + 2209161600000) / (24 * 60 * 60 * 1000);

@@ -159,2 +178,4 @@ }

}
var XML_HEADER = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\r\n';
/* copied from js-xls (C) SheetJS Apache2 license */

@@ -167,6 +188,7 @@ function xlml_normalize(d) {

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";
var parse_manifest = function(d, opts) {
function parse_manifest(d, opts) {
var str = xlml_normalize(d);

@@ -178,3 +200,3 @@ var Rn;

case 'file-entry': // 4.3 <manifest:file-entry>
FEtag = parsexmltag(Rn[0]);
FEtag = parsexmltag(Rn[0], false);
if(FEtag.path == '/' && FEtag.type !== CT_ODS) throw new Error("This OpenDocument is not a spreadsheet");

@@ -187,7 +209,42 @@ break;

throw new Error("Unsupported ODS Encryption");
default: throw Rn;
default: if(opts && opts.WTF) throw Rn;
}
};
}
function write_manifest(manifest, opts) {
var o = [XML_HEADER];
o.push('<manifest:manifest xmlns:manifest="urn:oasis:names:tc:opendocument:xmlns:manifest:1.0" manifest:version="1.2">\n');
o.push(' <manifest:file-entry manifest:full-path="/" manifest:version="1.2" manifest:media-type="application/vnd.oasis.opendocument.spreadsheet"/>\n');
for(var i = 0; i < manifest.length; ++i) o.push(' <manifest:file-entry manifest:full-path="' + manifest[i][0] + '" manifest:media-type="' + manifest[i][1] + '"/>\n');
o.push('</manifest:manifest>');
return o.join("");
}
/* Part 3 Section 6 Metadata Manifest File */
function write_rdf_type(file, res, tag) {
return [
' <rdf:Description rdf:about="' + file + '">\n',
' <rdf:type rdf:resource="http://docs.oasis-open.org/ns/office/1.2/meta/' + (tag || "odf") + '#' + res + '"/>\n',
' </rdf:Description>\n'
].join("");
}
function write_rdf_has(base, file) {
return [
' <rdf:Description rdf:about="' + base + '">\n',
' <ns0:hasPart xmlns:ns0="http://docs.oasis-open.org/ns/office/1.2/meta/pkg#" rdf:resource="' + file + '"/>\n',
' </rdf:Description>\n'
].join("");
}
function write_rdf(rdf, opts) {
var o = [XML_HEADER];
o.push('<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">\n');
for(var i = 0; i != rdf.length; ++i) {
o.push(write_rdf_type(rdf[i][0], rdf[i][1]));
o.push(write_rdf_has("",rdf[i][0]));
}
o.push(write_rdf_type("","Document", "pkg"));
o.push('</rdf:RDF>');
return o.join("");
}
var parse_text_p = function(text, tag) {
return utf8read(text.replace(/<text:s\/>/g," ").replace(/<[^>]*>/g,""));
return unescapexml(text.replace(/<text:s\/>/g," ").replace(/<[^>]*>/g,""));
};

@@ -211,2 +268,13 @@

};
/* Part 3 TODO: actually parse formulae */
function ods_to_csf_formula(f) {
if(f.substr(0,3) == "of:") f = f.substr(3);
/* 5.2 Basic Expressions */
if(f.charCodeAt(0) == 61) {
f = f.substr(1);
if(f.charCodeAt(0) == 61) f = f.substr(1);
}
/* Part 3 Section 5.8 References */
return f.replace(/\[((?:\.[A-Z]+[0-9]+)(?::\.[A-Z]+[0-9]+)?)\]/g, "$1").replace(/\./g, "");
}
var parse_content_xml = (function() {

@@ -226,22 +294,28 @@

return function pcx(d, opts) {
return function pcx(d, _opts) {
var opts = _opts || {};
var str = xlml_normalize(d);
var state = [], tmp;
var tag;
var NFtag, NF, pidx;
var NFtag = {name:""}, NF = "", pidx = 0;
var sheetag;
var rowtag;
var Sheets = {}, SheetNames = [], ws = {};
var Rn, q;
var ctag;
var textp, textpidx, textptag;
var R, C, range = {s: {r:1000000,c:10000000}, e: {r:0, c:0}};
var ctag = {value:""};
var textp = "", textpidx = 0, textptag;
var R = -1, C = -1, range = {s: {r:1000000,c:10000000}, e: {r:0, c:0}};
var number_format_map = {};
var merges = [], mrange = {}, mR = 0, mC = 0;
var arrayf = [];
var rept = 1, isstub = false;
var i = 0;
xlmlregex.lastIndex = 0;
while((Rn = xlmlregex.exec(str))) switch((Rn[3]=Rn[3].replace(/_.*$/,""))) {
while((Rn = xlmlregex.exec(str))) switch(Rn[3]) {
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['名称'] || sheetag.name);
SheetNames.push(sheetag.name);

@@ -251,3 +325,3 @@ Sheets[sheetag.name] = ws;

else if(Rn[0].charAt(Rn[0].length-2) !== '/') {
sheetag = parsexmltag(Rn[0]);
sheetag = parsexmltag(Rn[0], false);
R = C = -1;

@@ -259,10 +333,12 @@ range.s.r = range.s.c = 10000000; range.e.r = range.e.c = 0;

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]);
ctag = parsexmltag(Rn[0], false);
if(ctag['number-columns-repeated']) C+= parseInt(ctag['number-columns-repeated'], 10);

@@ -273,2 +349,3 @@ else ++C;

++C;
rept = 1;
if(C > range.e.c) range.e.c = C;

@@ -278,4 +355,18 @@ if(R > range.e.r) range.e.r = R;

if(R < range.s.r) range.s.r = R;
ctag = parsexmltag(Rn[0]);
q = {t:ctag['value-type'], v:null};
ctag = parsexmltag(Rn[0], false);
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;
mC = parseInt(ctag['number-matrix-columns-spanned'],10) || 0;
mrange = {s: {r:R,c:C}, e:{r:R + mR-1,c:C + mC-1}};
q.F = get_utils().encode_range(mrange);
arrayf.push([mrange, q.F]);
}
if(ctag.formula) q.f = ods_to_csf_formula(ctag.formula);
else for(i = 0; i < arrayf.length; ++i)
if(R >= arrayf[i][0].s.r && R <= arrayf[i][0].e.r)
if(C >= arrayf[i][0].s.c && C <= arrayf[i][0].e.c)
q.F = arrayf[i][1];
}
if(ctag['number-columns-spanned'] || ctag['number-rows-spanned']) {

@@ -287,2 +378,6 @@ mR = parseInt(ctag['number-rows-spanned'],10) || 0;

}
/* 19.675.2 table:number-columns-repeated */
if(ctag['number-columns-repeated']) rept = parseInt(ctag['number-columns-repeated'], 10);
/* 19.385 office:value-type */

@@ -294,12 +389,27 @@ switch(q.t) {

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 'date': q.t = 'n'; q.v = datenum(new Date(ctag['date-value'])); q.z = 'm/d/yy'; break;
case 'time': q.t = 'n'; q.v = parse_isodur(ctag['time-value'])/86400; break;
case 'string': q.t = 's'; break;
default: throw new Error('Unsupported value type ' + q.t);
case 'number': q.t = 'n'; q.v = parseFloat(ctag['数据数值']); break;
default:
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);
}
} else {
if(q.t === 's') q.v = textp;
isstub = false;
if(q.t === 's') {
q.v = textp || '';
isstub = textpidx == 0;
}
if(textp) q.w = textp;
if(!(opts.sheetRows && opts.sheetRows < R)) ws[get_utils().encode_cell({r:R,c:C})] = q;
q = null;
if(!isstub || opts.cellStubs) {
if(!(opts.sheetRows && opts.sheetRows < R)) {
ws[get_utils().encode_cell({r:R,c:C})] = q;
while(--rept > 0) ws[get_utils().encode_cell({r:R,c:++C})] = dup(q);
if(range.e.c <= C) range.e.c = C;
}
} else { C += rept; rept = 0; }
q = {};
textp = "";
}

@@ -309,5 +419,7 @@ 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>

@@ -319,8 +431,29 @@ if(Rn[1]==='/'){if((tmp=state.pop())[0]!==Rn[3]) throw "Bad state: "+tmp;}

/* 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>
case 'image': // 10.4.4 <draw:image>
case 'data-pilot-tables': // 9.6.2 <table:data-pilot-tables>
case 'list-style': // 16.30 <text:list-style>
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>

@@ -335,3 +468,3 @@ case 'percentage-style': // 16.27.9 <number:percentage-style>

NF = "";
NFtag = parsexmltag(Rn[0]);
NFtag = parsexmltag(Rn[0], false);
state.push([Rn[3], true]);

@@ -341,5 +474,10 @@ } 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>

@@ -357,6 +495,8 @@

case 'date-style':
tag = parsexmltag(Rn[0]);
tag = parsexmltag(Rn[0], false);
NF += number_formats[Rn[3]][tag.style==='long'?1:0]; break;
} break;
case 'fraction': break; // TODO 16.27.6 <number:fraction>
case 'day': // 16.27.11 <number:day>

@@ -376,3 +516,3 @@ case 'month': // 16.27.12 <number:month>

case 'date-style':
tag = parsexmltag(Rn[0]);
tag = parsexmltag(Rn[0], false);
NF += number_formats[Rn[3]][tag.style==='long'?1:0]; break;

@@ -385,3 +525,3 @@ } break;

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]) {

@@ -399,3 +539,3 @@ case 'number-style':

case 'body': break; // 3.3 16.9.6 19.726.3
case 'body': case '电子表格': break; // 3.3 16.9.6 19.726.3

@@ -405,19 +545,32 @@ case 'forms': break; // 12.25.2 13.2

case 'graphic-properties': break;
case 'null-date': break; // 9.4.2 <table:null-date> TODO: date1904
case 'graphic-properties': break; // 17.21 <style:graphic-properties>
case 'calculation-settings': break; // 9.4.1 <table:calculation-settings>
case 'named-expressions': break; // 9.4.11 <table:named-expressions>
case 'named-range': break; // 9.4.11 <table:named-range>
case 'named-range': break; // 9.4.12 <table:named-range>
case 'named-expression': break; // 9.4.13 <table:named-expression>
case 'sort': break; // 9.4.19 <table:sort>
case 'sort-by': break; // 9.4.20 <table:sort-by>
case 'sort-groups': break; // 9.4.22 <table:sort-groups>
case 'span': break; // <text:span>
case 'p':
case 'line-break': break; // 6.1.5 <text:line-break>
case 'p': case '文本串':
if(Rn[1]==='/') textp = parse_text_p(str.slice(textpidx,Rn.index), textptag);
else { textptag = parsexmltag(Rn[0]); textpidx = Rn.index + Rn[0].length; }
else { textptag = parsexmltag(Rn[0], false); textpidx = Rn.index + Rn[0].length; }
break; // <text:p>
case 's': break; // <text:s>
case 'date': break; // <*:date>
case 'annotation': break;
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
case 'iteration': break; // 9.4.3 <table:iteration>
case 'content-validations': break; // 9.4.4 <table:
case 'content-validation': break; // 9.4.5 <table:
case 'error-message': break; // 9.4.7 <table:
case 'database-ranges': break; // 9.4.14 <table:database-ranges>

@@ -429,3 +582,98 @@ case 'database-range': break; // 9.4.15 <table:database-range>

case 'filter-condition': break; // 9.5.5 <table:filter-condition>
default: if(opts.WTF) throw Rn;
case 'list-level-style-bullet': break; // 16.31 <text:
case 'list-level-style-number': break; // 16.32 <text:
case 'list-level-properties': break; // 17.19 <style:
/* 7.3 Document Fields */
case 'sender-firstname': // 7.3.6.2
case 'sender-lastname': // 7.3.6.3
case 'sender-initials': // 7.3.6.4
case 'sender-title': // 7.3.6.5
case 'sender-position': // 7.3.6.6
case 'sender-email': // 7.3.6.7
case 'sender-phone-private': // 7.3.6.8
case 'sender-fax': // 7.3.6.9
case 'sender-company': // 7.3.6.10
case 'sender-phone-work': // 7.3.6.11
case 'sender-street': // 7.3.6.12
case 'sender-city': // 7.3.6.13
case 'sender-postal-code': // 7.3.6.14
case 'sender-country': // 7.3.6.15
case 'sender-state-or-province': // 7.3.6.16
case 'author-name': // 7.3.7.1
case 'author-initials': // 7.3.7.2
case 'chapter': // 7.3.8
case 'file-name': // 7.3.9
case 'template-name': // 7.3.9
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
case 'source-service': // 9.6.6
case 'data-pilot-field': // 9.6.7
case 'data-pilot-level': // 9.6.8
case 'data-pilot-subtotals': // 9.6.9
case 'data-pilot-subtotal': // 9.6.10
case 'data-pilot-members': // 9.6.11
case 'data-pilot-member': // 9.6.12
case 'data-pilot-display-info': // 9.6.13
case 'data-pilot-sort-info': // 9.6.14
case 'data-pilot-layout-info': // 9.6.15
case 'data-pilot-field-reference': // 9.6.16
case 'data-pilot-groups': // 9.6.17
case 'data-pilot-group': // 9.6.18
case 'data-pilot-group-member': // 9.6.19
break;
/* 10.3 Drawing Shapes */
case 'rect': // 10.3.2
break;
/* 14.6 DDE Connections */
case 'dde-connection-decls': // 14.6.2 <text:
case 'dde-connection-decl': // 14.6.3 <text:
case 'dde-link': // 14.6.4 <table:
case 'dde-source': // 14.6.5 <office:
break;
case 'properties': break; // 13.7 <form:properties>
case 'property': break; // 13.8 <form:property>
case 'a': break; // 6.1.8 hyperlink
/* non-standard */
case 'table-protection': break;
case 'data-pilot-grand-total': break; // <table:
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;
}

@@ -439,8 +687,91 @@ var out = {

})();
var write_content_xml = (function() {
var null_cell_xml = ' <table:table-cell />\n';
var write_ws = function(ws, wb, i, opts) {
/* Section 9 Tables */
var o = [];
o.push(' <table:table table:name="' + escapexml(wb.SheetNames[i]) + '">\n');
var R=0,C=0, range = get_utils().decode_range(ws['!ref']);
for(R = 0; R < range.s.r; ++R) o.push(' <table:table-row></table:table-row>\n');
for(; R <= range.e.r; ++R) {
o.push(' <table:table-row>\n');
for(C=0; C < range.s.c; ++C) o.push(null_cell_xml);
for(; C <= range.e.c; ++C) {
var ref = get_utils().encode_cell({r:R, c:C}), cell = ws[ref];
if(cell) switch(cell.t) {
case 'b': o.push(' <table:table-cell office:value-type="boolean" office:boolean-value="' + (cell.v ? 'true' : 'false') + '"><text:p>' + (cell.v ? 'TRUE' : 'FALSE') + '</text:p></table:table-cell>\n'); break;
case 'n': o.push(' <table:table-cell office:value-type="float" office:value="' + cell.v + '"><text:p>' + (cell.w||cell.v) + '</text:p></table:table-cell>\n'); break;
case 's': case 'str': o.push(' <table:table-cell office:value-type="string"><text:p>' + escapexml(cell.v) + '</text:p></table:table-cell>\n'); break;
//case 'd': // TODO
//case 'e':
default: o.push(null_cell_xml);
} else o.push(null_cell_xml);
}
o.push(' </table:table-row>\n');
}
o.push(' </table:table>\n');
return o.join("");
};
return function wcx(wb, opts) {
var o = [XML_HEADER];
/* 3.1.3.2 */
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');
if(opts.bookType == "fods") o.push('</office:document>');
else o.push('</office:document-content>');
return o.join("");
};
})();
/* Part 3: Packages */
var parse_ods = function(zip, opts) {
//var manifest = parse_manifest(getzipdata(zip, 'META-INF/manifest.xml'));
return parse_content_xml(getzipdata(zip, 'content.xml'), opts);
};
function parse_ods(zip, opts) {
opts = 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');
if(!content) throw new Error("Missing content.xml in " + (ods ? "ODS" : "UOF")+ " file");
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 = "";
var manifest = [];
var rdf = [];
/* 3:3.3 and 2:2.2.4 */
f = "mimetype";
zip.file(f, "application/vnd.oasis.opendocument.spreadsheet");
/* Part 1 Section 2.2 Documents */
f = "content.xml";
zip.file(f, write_content_xml(wb, opts));
manifest.push([f, "text/xml"]);
rdf.push([f, "ContentFile"]);
/* Part 3 Section 6 Metadata Manifest File */
f = "manifest.rdf";
zip.file(f, write_rdf(rdf, opts));
manifest.push([f, "application/rdf+xml"]);
/* Part 3 Section 4 Manifest File */
f = "META-INF/manifest.xml";
zip.file(f, write_manifest(manifest, opts));
return zip;
}
ODS.parse_ods = parse_ods;
ODS.write_ods = write_ods;
ODS.parse_fods = parse_fods;
})(typeof exports !== 'undefined' ? exports : ODS);
{
"name": "xlsx",
"version": "0.8.0",
"version": "0.8.8",
"author": "sheetjs",
"description": "Excel (XLSB/XLSX/XLSM/XLS/XML) and ODS spreadsheet parser and writer",
"description": "Excel (XLSB/XLSX/XLSM/XLS/XML) and ODS (ODS/FODS/UOS) spreadsheet parser and writer",
"keywords": [ "excel", "xls", "xlsx", "xlsb", "xlsm", "ods", "office", "spreadsheet" ],

@@ -11,7 +11,13 @@ "bin": {

"main": "./xlsx",
"browser": {
"node": false,
"crypto": false,
"fs": false,
"../xlsx.js": false
},
"dependencies": {
"exit-on-epipe":"",
"ssf":"~0.8.1",
"codepage":"~1.3.6",
"cfb":">=0.10.0",
"jszip":"2.4.0",
"codepage":"",
"cfb":"~0.11.0",
"crc-32":"",

@@ -36,2 +42,3 @@ "adler-32":"",

},
"homepage": "https://oss.sheetjs.com/js-xlsx/",
"bugs": { "url": "https://github.com/SheetJS/js-xlsx/issues" },

@@ -38,0 +45,0 @@ "license": "Apache-2.0",

# xlsx
Parser and writer for various spreadsheet formats. Pure-JS cleanroom
implementation from official specifications and related documents.
implementation from official specifications, related documents, and test files.
Emphasis on parsing and writing robustness, cross-format feature compatibility
with a unified JS representation, and ES3/ES5 browser compatibility back to IE6.
Supported read formats:
File format support for known spreadsheet data formats:
- Excel 2007+ XML Formats (XLSX/XLSM)
- Excel 2007+ Binary Format (XLSB)
- Excel 2003-2004 XML Format (XML "SpreadsheetML")
- Excel 97-2004 (XLS BIFF8)
- Excel 5.0/95 (XLS BIFF5)
- OpenDocument Spreadsheet (ODS)
| Format | Read | Write |
|:-------------------------------------------------------------|:-----:|:-----:|
| **Excel Worksheet/Workbook Formats** |:-----:|:-----:|
| Excel 2007+ XML Formats (XLSX/XLSM) | :o: | :o: |
| Excel 2007+ Binary Format (XLSB BIFF12) | :o: | :o: |
| Excel 2003-2004 XML Format (XML "SpreadsheetML") | :o: | |
| Excel 97-2004 (XLS BIFF8) | :o: | |
| Excel 5.0/95 (XLS BIFF5) | :o: | |
| Excel 4.0 (XLS/XLW BIFF4) | :o: | |
| Excel 3.0 (XLS BIFF3) | :o: | |
| Excel 2.0/2.1 (XLS BIFF2) | :o: | :o: |
| **Excel Supported Text Formats** |:-----:|:-----:|
| Delimiter-Separated Values (CSV/TSV/DSV) | | :o: |
| **Other Workbook/Worksheet Formats** |:-----:|:-----:|
| OpenDocument Spreadsheet (ODS) | :o: | :o: |
| Flat XML ODF Spreadsheet (FODS) | :o: | :o: |
| Uniform Office Format Spreadsheet (标文通 UOS1/UOS2) | :o: | |
| **Other Common Spreadsheet Output Formats** |:-----:|:-----:|
| HTML Tables | :o: | |
Supported write formats:
- XLSX
- CSV (and general DSV)
- JSON and JS objects (various styles)
Demo: <http://oss.sheetjs.com/js-xlsx>

@@ -25,2 +34,5 @@

Paid support available through the [reinforcements program](http://sheetjs.com/reinforcements)
## Installation

@@ -30,11 +42,17 @@

npm install xlsx
```bash
$ npm install xlsx
```
In the browser:
<script lang="javascript" src="dist/xlsx.core.min.js"></script>
```html
<script lang="javascript" src="dist/xlsx.core.min.js"></script>
```
With [bower](http://bower.io/search/?q=js-xlsx):
bower install js-xlsx
```bash
$ bower install js-xlsx
```

@@ -44,3 +62,3 @@ CDNjs automatically pulls the latest version and makes all versions available at

## Optional Modules
### Optional Modules

@@ -52,6 +70,8 @@ The node version automatically requires modules for additional features. Some

<!-- international support from https://github.com/sheetjs/js-codepage -->
<script src="dist/cpexcel.js"></script>
<!-- ODS support -->
<script src="dist/ods.js"></script>
```html
<!-- international support from js-codepage -->
<script src="dist/cpexcel.js"></script>
<!-- ODS support -->
<script src="dist/ods.js"></script>
```

@@ -62,4 +82,12 @@ An appropriate version for each dependency is included in the dist/ directory.

## ECMAScript 5 Compatibility
### JS Ecosystem Demos
The `demos` directory includes sample projects for:
- [`browserify`](http://browserify.org/)
- [`requirejs`](http://requirejs.org/)
- [`webpack`](https://webpack.js.org/)
### ECMAScript 5 Compatibility
Since xlsx.js uses ES5 functions like `Array#forEach`, older browsers require

@@ -71,3 +99,5 @@ [Polyfills](http://git.io/QVh77g). This repo and the gh-pages branch include

<script type="text/javascript" src="/path/to/shim.js"></script>
```html
<script type="text/javascript" src="/path/to/shim.js"></script>
```

@@ -81,3 +111,3 @@ ## Parsing Workbooks

```
```js
if(typeof require !== 'undefined') XLSX = require('xlsx');

@@ -91,3 +121,3 @@ var workbook = XLSX.readFile('test.xlsx');

```
```js
/* set up XMLHttpRequest */

@@ -117,5 +147,16 @@ var url = "test_files/formula_stress_test_ajax.xlsx";

- HTML5 drag-and-drop using readAsBinaryString:
- HTML5 drag-and-drop using readAsBinaryString or readAsArrayBuffer:
note: readAsBinaryString and readAsArrayBuffer may not be available in every
browser. Use dynamic feature tests to determine which method to use.
```
```js
/* processing array buffers, only required for readAsArrayBuffer */
function fixdata(data) {
var o = "", l = 0, w = 10240;
for(; l<data.byteLength/w; ++l) o+=String.fromCharCode.apply(null,new Uint8Array(data.slice(l*w,l*w+w)));
o+=String.fromCharCode.apply(null, new Uint8Array(data.slice(l*w)));
return o;
}
var rABS = true; // true: readAsBinaryString ; false: readAsArrayBuffer
/* set up drag-and-drop event */

@@ -127,3 +168,4 @@ function handleDrop(e) {

var i,f;
for (i = 0, f = files[i]; i != files.length; ++i) {
for (i = 0; i != files.length; ++i) {
f = files[i];
var reader = new FileReader();

@@ -134,8 +176,16 @@ var name = f.name;

/* if binary string, read with type 'binary' */
var workbook = XLSX.read(data, {type: 'binary'});
var workbook;
if(rABS) {
/* if binary string, read with type 'binary' */
workbook = XLSX.read(data, {type: 'binary'});
} else {
/* if array buffer, convert to base64 */
var arr = fixdata(data);
workbook = XLSX.read(btoa(arr), {type: 'base64'});
}
/* DO SOMETHING WITH workbook HERE */
};
reader.readAsBinaryString(f);
if(rABS) reader.readAsBinaryString(f);
else reader.readAsArrayBuffer(f);
}

@@ -146,9 +196,11 @@ }

- HTML5 input file element using readAsBinaryString:
- HTML5 input file element using readAsBinaryString or readAsArrayBuffer:
```
```js
/* fixdata and rABS are defined in the drag and drop example */
function handleFile(e) {
var files = e.target.files;
var i,f;
for (i = 0, f = files[i]; i != files.length; ++i) {
for (i = 0; i != files.length; ++i) {
f = files[i];
var reader = new FileReader();

@@ -159,3 +211,11 @@ var name = f.name;

var workbook = XLSX.read(data, {type: 'binary'});
var workbook;
if(rABS) {
/* if binary string, read with type 'binary' */
workbook = XLSX.read(data, {type: 'binary'});
} else {
/* if array buffer, convert to base64 */
var arr = fixdata(data);
workbook = XLSX.read(btoa(arr), {type: 'base64'});
}

@@ -176,3 +236,3 @@ /* DO SOMETHING WITH workbook HERE */

```
```js
var first_sheet_name = workbook.SheetNames[0];

@@ -193,7 +253,7 @@ var address_of_cell = 'A1';

```
```js
var sheet_name_list = workbook.SheetNames;
sheet_name_list.forEach(function(y) { /* iterate through sheets */
var worksheet = workbook.Sheets[y];
for (z in worksheet) {
for (var z in worksheet) {
/* all keys that do not begin with "!" correspond to cell addresses */

@@ -210,7 +270,17 @@ if(z[0] === '!') continue;

Note that older versions of IE does not support HTML5 File API, so the base64
mode is provided for testing. On OSX you can get the base64 encoding with:
Note that older versions of IE do not support HTML5 File API, so the base64 mode
is used for testing. On OSX you can get the base64 encoding with:
$ <target_file.xlsx base64 | pbcopy
```bash
$ <target_file base64 | pbcopy
```
On Windows XP and up you can get the base64 encoding using `certutil`:
```cmd
> certutil -encode target_file target_file.b64
```
(note: You have to open the file and remove the header and footer lines)
- <http://oss.sheetjs.com/js-xlsx/ajax.html> XMLHttpRequest

@@ -239,3 +309,3 @@

```
```js
/* output format determined by filename */

@@ -246,6 +316,7 @@ XLSX.writeFile(workbook, 'out.xlsx');

- write to binary string (using FileSaver.js):
- browser generate binary blob and "download" to client
(using [FileSaver.js](https://github.com/eligrey/FileSaver.js/) for download):
```
/* bookType can be 'xlsx' or 'xlsm' or 'xlsb' */
```js
/* bookType can be 'xlsx' or 'xlsm' or 'xlsb' or 'ods' */
var wopts = { bookType:'xlsx', bookSST:false, type:'binary' };

@@ -263,3 +334,3 @@

/* the saveAs call downloads a file on the local machine */
saveAs(new Blob([s2ab(wbout)],{type:""}), "test.xlsx")
saveAs(new Blob([s2ab(wbout)],{type:"application/octet-stream"}), "test.xlsx");
```

@@ -299,6 +370,9 @@

- `sheet_to_json` converts a workbook object to an array of JSON objects.
- `sheet_to_csv` generates delimiter-separated-values output
- `sheet_to_formulae` generates a list of the formulae (with value fallbacks)
- `sheet_to_json` converts a worksheet object to an array of JSON objects.
`sheet_to_row_object_array` is an alias that will be removed in the future.
- `sheet_to_csv` generates delimiter-separated-values output.
- `sheet_to_formulae` generates a list of the formulae (with value fallbacks).
The `sheet_to_*` functions accept a worksheet and an optional options object.
Cell and cell address manipulation:

@@ -326,3 +400,3 @@

```
```js
for(var R = range.s.r; R <= range.e.r; ++R) {

@@ -337,14 +411,15 @@ for(var C = range.s.c; C <= range.e.c; ++C) {

| Key | Description |
| --- | ----------- |
| `v` | raw value (see Data Types section for more info) |
| `w` | formatted text (if applicable) |
| `t` | cell type: `b` Boolean, `n` Number, `e` error, `s` String, `d` Date |
| `f` | cell formula (if applicable) |
| `r` | rich text encoding (if applicable) |
| `h` | HTML rendering of the rich text (if applicable) |
| `c` | comments associated with the cell ** |
| `z` | number format string associated with the cell (if requested) |
| `l` | cell hyperlink object (.Target holds link, .tooltip is tooltip) |
| `s` | the style/theme of the cell (if applicable) |
| Key | Description |
| --- | ---------------------------------------------------------------------- |
| `v` | raw value (see Data Types section for more info) |
| `w` | formatted text (if applicable) |
| `t` | cell type: `b` Boolean, `n` Number, `e` error, `s` String, `d` Date |
| `f` | cell formula encoded as an A1-style string (if applicable) |
| `F` | range of enclosing array if formula is array formula (if applicable) |
| `r` | rich text encoding (if applicable) |
| `h` | HTML rendering of the rich text (if applicable) |
| `c` | comments associated with the cell |
| `z` | number format string associated with the cell (if requested) |
| `l` | cell hyperlink object (.Target holds link, .tooltip is tooltip) |
| `s` | the style/theme of the cell (if applicable) |

@@ -356,2 +431,5 @@ Built-in export utilities (such as the CSV exporter) will use the `w` text if it

The actual array formula is stored in the `f` field of the first cell in the
array range. Other cells in the range will omit the `f` field.
### Data Types

@@ -365,12 +443,12 @@

| Value | Error Meaning |
| ----: | :------------ |
| 0x00 | #NULL! |
| 0x07 | #DIV/0! |
| 0x0F | #VALUE! |
| 0x17 | #REF! |
| 0x1D | #NAME? |
| 0x24 | #NUM! |
| 0x2A | #N/A |
| 0x2B | #GETTING_DATA |
| Value | Error Meaning |
| ----: | :------------- |
| 0x00 | #NULL! |
| 0x07 | #DIV/0! |
| 0x0F | #VALUE! |
| 0x17 | #REF! |
| 0x1D | #NAME? |
| 0x24 | #NUM! |
| 0x2A | #N/A |
| 0x2B | #GETTING\_DATA |

@@ -386,3 +464,3 @@ Type `n` is the Number type. This includes all forms of data that Excel stores

the other hand, writers and exporters should be able to handle date strings and
JS Date objects. Note that Excel disregards the timezone modifier and treats all
JS Date objects. Note that Excel disregards timezone modifiers and treats all
dates in the local timezone. js-xlsx does not correct for this error.

@@ -393,3 +471,17 @@

### Formulae
The A1-style formula string is stored in the `f` field. Even though different
file formats store the formulae in different ways, the formats are converted.
Shared formulae are decompressed and each cell has the correct formula.
Array formulae are stored in the top-left cell of the array block. All cells
of an array formula have a `F` field corresponding to the range. A single-cell
formula can be distinguished from a plain formula by the presence of `F` field.
The `sheet_to_formulae` method generates one line per formula or array formula.
Array formulae are rendered in the form `range=formula` while plain cells are
rendered in the form `cell=formula or value`.
### Worksheet Object

@@ -412,3 +504,3 @@

the sheet as empty or attempt to guess the range. The standard utilities that
ship with this library treat sheets as empty (for example, the CSV output is an
ship with this library treat sheets as empty (for example, the CSV output is
empty string).

@@ -445,17 +537,18 @@

| Option Name | Default | Description |
| :---------- | ------: | :---------- |
| cellFormula | true | Save formulae to the .f field ** |
| cellHTML | true | Parse rich text and save HTML to the .h field |
| cellNF | false | Save number format string to the .z field |
| cellStyles | false | Save style/theme info to the .s field |
| cellDates | false | Store dates as type `d` (default is `n`) ** |
| sheetStubs | false | Create cell objects for stub cells |
| sheetRows | 0 | If >0, read the first `sheetRows` rows ** |
| bookDeps | false | If true, parse calculation chains |
| bookFiles | false | If true, add raw files to book object ** |
| bookProps | false | If true, only parse enough to get book metadata ** |
| bookSheets | false | If true, only parse enough to get the sheet names |
| bookVBA | false | If true, expose vbaProject.bin to `vbaraw` field ** |
| password | "" | If defined and file is encrypted, use password ** |
| Option Name | Default | Description |
| :---------- | ------: | :--------------------------------------------------- |
| type | | Input data encoding (see Input Type below) |
| cellFormula | true | Save formulae to the .f field ** |
| cellHTML | true | Parse rich text and save HTML to the .h field |
| cellNF | false | Save number format string to the .z field |
| cellStyles | false | Save style/theme info to the .s field |
| cellDates | false | Store dates as type `d` (default is `n`) ** |
| sheetStubs | false | Create cell objects for stub cells |
| sheetRows | 0 | If >0, read the first `sheetRows` rows ** |
| bookDeps | false | If true, parse calculation chains |
| bookFiles | false | If true, add raw files to book object ** |
| bookProps | false | If true, only parse enough to get book metadata ** |
| bookSheets | false | If true, only parse enough to get the sheet names |
| bookVBA | false | If true, expose vbaProject.bin to `vbaraw` field ** |
| password | "" | If defined and file is encrypted, use password ** |

@@ -479,4 +572,32 @@ - `cellFormula` option only applies to formats that require extra processing to

The defaults are enumerated in bits/84_defaults.js
The defaults are enumerated in bits/84\_defaults.js
### Input Type
Strings can be interpreted in multiple ways. The `type` parameter for `read`
tells the library how to parse the data argument:
| `type` | expected input |
|------------|-----------------------------------------------------------------|
| `"base64"` | string: base64 encoding of the file |
| `"binary"` | string: binary string (`n`-th byte is `data.charCodeAt(n)`) |
| `"buffer"` | nodejs Buffer |
| `"array"` | array: array of 8-bit unsigned int (`n`-th byte is `data[n]`) |
| `"file"` | string: filename that will be read and processed (nodejs only) |
### Guessing File Type
Excel and other spreadsheet tools read the first few bytes and apply other
heuristics to determine a file type. This enables file type punning: renaming
files with the `.xls` extension will tell your computer to use Excel to open the
file but Excel will know how to handle it. This library applies similar logic:
| Byte 0 | Raw File Type | Spreadsheet Types |
|:-------|:--------------|:----------------------------------------------------|
| `0xD0` | CFB Container | BIFF 5/8 or password-protected XLSX/XLSB |
| `0x09` | BIFF Stream | BIFF 2/3/4/5 |
| `0x3C` | XML/HTML | SpreadsheetML or Flat ODS or UOS1 or HTML |
| `0x50` | ZIP Archive | XLSB or XLSX/M or ODS or UOS2 |
| `0xFE` | UTF8 Text | SpreadsheetML or Flat ODS or UOS1 |
## Writing Options

@@ -486,11 +607,13 @@

| Option Name | Default | Description |
| :---------- | ------: | :---------- |
| cellDates | false | Store dates as type `d` (default is `n`) |
| bookSST | false | Generate Shared String Table ** |
| bookType | 'xlsx' | Type of Workbook ("xlsx" or "xlsm" or "xlsb") |
| Option Name | Default | Description |
| :---------- | -------: | :-------------------------------------------------- |
| type | | Output data encoding (see Output Type below) |
| cellDates | `false` | Store dates as type `d` (default is `n`) |
| bookSST | `false` | Generate Shared String Table ** |
| bookType | `"xlsx"` | Type of Workbook (see below for supported formats) |
| sheet | `""` | Name of Worksheet for single-sheet formats ** |
| compression | `false` | Use ZIP compression for ZIP-based formats ** |
- `bookSST` is slower and more memory intensive, but has better compatibility
with older versions of iOS Numbers
- `bookType = 'xlsb'` is stubbed and far from complete
- The raw data is the only thing guaranteed to be saved. Formulae, formatting,

@@ -502,8 +625,104 @@ and other niceties may not be serialized (pending CSF standardization)

### Supported Output Formats
For broad compatibility with third-party tools, this library supports many
output formats. The specific file type is controlled with `bookType` option:
| bookType | file ext | container | sheets | Description |
| :------- | -------: | :-------: | :----- |:--------------------------------- |
| `xlsx` | `.xlsx` | ZIP | multi | Excel 2007+ XML Format |
| `xlsm` | `.xlsm` | ZIP | multi | Excel 2007+ Macro XML Format |
| `xlsb` | `.xlsb` | ZIP | multi | Excel 2007+ Binary Format |
| `ods` | `.ods` | ZIP | multi | OpenDocument Spreadsheet |
| `biff2` | `.xls` | none | single | Excel 2.0 Worksheet format |
| `fods` | `.fods` | none | multi | Flat OpenDocument Spreadsheet |
| `csv` | `.csv` | none | single | Comma Separated Values |
- `compression` only applies to formats with ZIP containers.
- Formats that only support a single sheet require a `sheet` option specifying
the worksheet. If the string is empty, the first worksheet is used.
### Output Type
The `type` argument for `write` mirrors the `type` argument for `read`:
| `type` | output |
|------------|-----------------------------------------------------------------|
| `"base64"` | string: base64 encoding of the file |
| `"binary"` | string: binary string (`n`-th byte is `data.charCodeAt(n)`) |
| `"buffer"` | nodejs Buffer |
| `"file"` | string: name of file to be written (nodejs only) |
## File Formats
Despite the fact that the name of the library is `xlsx`, it supports numerous
non-XLSX file formats:
### Excel 2.0-95 (BIFF2/BIFF3/BIFF4/BIFF5)
BIFF 2/3 XLS are single-sheet streams of binary records. Excel 4 introduced
the concept of a workbook (`XLW` files) but also had single-sheet `XLS` format.
The structure is largely similar to the Lotus 1-2-3 file formats. BIFF5/8/12
extended the format in various ways but largely stuck to the same record format.
There is no official specification for any of these formats. Excel 95 can write
files in these formats, so record lengths and fields were backsolved by writing
in all of the supported formats and comparing files. Excel 2016 can generate
BIFF5 files, enabling a full suite of file tests starting from XLSX or BIFF2.
### Excel 97-2004 Binary (BIFF8)
BIFF8 exclusively uses the Compound File Binary container format, splitting some
content into streams within the file. At its core, it still uses an extended
version of the binary record format from older versions of BIFF.
The `MS-XLS` specification covers the basics of the file format, and other
specifications expand on serialization of features like properties.
### Excel 2003-2004 (SpreadsheetML)
Predating XLSX, SpreadsheetML files are simple XML files. There is no official
and comprehensive specification, although MS has released whitepapers on the
format. Since Excel 2016 can generate SpreadsheetML files, backsolving is
pretty straightforward.
### Excel 2007+ Binary (XLSB, BIFF12)
Introduced in parallel with XLSX, the XLSB filetype combines BIFF architecture
with the content separation and ZIP container of XLSX. For the most part nodes
in an XLSX sub-file can be mapped to XLSB records in a corresponding sub-file.
The `MS-XLSB` specification covers the basics of the file format, and other
specifications expand on serialization of features like properties.
### OpenDocument Spreadsheet (ODS/FODS) and Uniform Office Spreadsheet (UOS1/2)
ODS is an XML-in-ZIP format akin to XLSX while FODS is an XML format akin to
SpreadsheetML. Both are detailed in the OASIS standard, but tools like LO/OO
add undocumented extensions.
UOS is a very similar format, and it comes in 2 varieties corresponding to ODS
and FODS respectively. For the most part, the difference between the formats
lies in the names of tags and attributes.
### Comma-Separated Values
Excel CSV deviates from RFC4180 in a number of important ways. The generated
CSV files should generally work in Excel although they may not work in RFC4180
compatible readers.
### HTML
Excel HTML worksheets include special metadata encoded in styles. For example,
`mso-number-format` is a localized string containing the number format. Despite
the metadata the output is valid HTML, although it does accept bare `&` symbols.
## Tested Environments
- NodeJS 0.8, 0.10 (latest release), 0.11.14 (unstable), io.js
- IE 6/7/8/9/10/11 using Base64 mode (IE10/11 using HTML5 mode)
- FF 18 using Base64 or HTML5 mode
- Chrome 24 using Base64 or HTML5 mode
- NodeJS 0.8, 0.9, 0.10, 0.11, 0.12, 4.x, 5.x, 6.x, 7.x
- IE 6/7/8/9/10/11 (IE6-9 browsers require shims for interacting with client)
- Chrome 24+
- Safari 6+
- FF 18+

@@ -513,4 +732,4 @@ Tests utilize the mocha testing framework. Travis-CI and Sauce Labs links:

- <https://travis-ci.org/SheetJS/js-xlsx> for XLSX module in nodejs
- <https://travis-ci.org/SheetJS/SheetJS.github.io> for XLS* modules
- <https://saucelabs.com/u/sheetjs> for XLS* modules using Sauce Labs
- <https://travis-ci.org/SheetJS/SheetJS.github.io> for XLS\* modules
- <https://saucelabs.com/u/sheetjs> for XLS\* modules using Sauce Labs

@@ -529,3 +748,3 @@ ## Test Files

```
```bash
$ cp xlsx.js ../SheetJS.github.io

@@ -549,3 +768,3 @@ $ cd ../SheetJS.github.io

```
```bash
$ mv xlsx.js xlsx.new.js

@@ -562,3 +781,3 @@ $ make

Please consult the attached LICENSE file for details. All rights not explicitly
granted by the Apache 2.0 license are reserved by the Original Author.
granted by the Apache 2.0 License are reserved by the Original Author.

@@ -588,2 +807,4 @@ It is the opinion of the Original Author that this code conforms to the terms of

- [MS-OSHARED]: Office Common Data Types and Objects Structures
- [MS-ODRAW]: Office Drawing Binary File Format
- [MS-ODRAWXML]: Office Drawing Extensions to Office Open XML Structure
- [MS-OVBA]: Office VBA File Format Structure

@@ -600,2 +821,4 @@ - [MS-CTXLS]: Excel Custom Toolbar Binary File Format

[![Build Status](https://saucelabs.com/browser-matrix/xlsx.svg)](https://saucelabs.com/u/xlsx)
[![Build Status](https://travis-ci.org/SheetJS/js-xlsx.svg?branch=master)](https://travis-ci.org/SheetJS/js-xlsx)

@@ -605,2 +828,8 @@

[![githalytics.com alpha](https://cruel-carlota.pagodabox.com/ed5bb2c4c4346a474fef270f847f3f78 "githalytics.com")](http://githalytics.com/SheetJS/js-xlsx)
[![NPM Downloads](https://img.shields.io/npm/dt/xlsx.svg)](https://npmjs.org/package/xlsx)
[![Dependencies Status](https://david-dm.org/sheetjs/js-xlsx/status.svg)](https://david-dm.org/sheetjs/js-xlsx)
[![ghit.me](https://ghit.me/badge.svg?repo=sheetjs/js-xlsx)](https://ghit.me/repo/sheetjs/js-xlsx)
[![Analytics](https://ga-beacon.appspot.com/UA-36810333-1/SheetJS/js-xlsx?pixel)](https://github.com/SheetJS/js-xlsx)

@@ -1,4 +0,4 @@

/* xlsx.js (C) 2013-2015 SheetJS -- http://sheetjs.com */
/* xlsx.js (C) 2013-present SheetJS -- http://sheetjs.com */
/* uncomment the next line for encoding support */
//importScripts('dist/cpexcel.js');
importScripts('dist/cpexcel.js');
importScripts('jszip.js');

@@ -15,3 +15,3 @@ importScripts('xlsx.js');

} catch(e) { postMessage({t:"e",d:e.stack||e}); }
postMessage({t:"xlsx", d:JSON.stringify(v)});
postMessage({t:"xlsx", d:JSON.stringify(v)});
};

@@ -1,4 +0,4 @@

/* xlsx.js (C) 2013-2015 SheetJS -- http://sheetjs.com */
/* xlsx.js (C) 2013-present SheetJS -- http://sheetjs.com */
/* uncomment the next line for encoding support */
//importScripts('dist/cpexcel.js');
importScripts('dist/cpexcel.js');
importScripts('jszip.js');

@@ -30,3 +30,3 @@ importScripts('xlsx.js');

var r = s2ab(res.d)[1];
postMessage(r, [r]);
postMessage(r, [r]);
};

@@ -1,4 +0,4 @@

/* xlsx.js (C) 2013-2015 SheetJS -- http://sheetjs.com */
/* xlsx.js (C) 2013-present SheetJS -- http://sheetjs.com */
/* uncomment the next line for encoding support */
//importScripts('dist/cpexcel.js');
importScripts('dist/cpexcel.js');
importScripts('jszip.js');

@@ -30,3 +30,3 @@ importScripts('xlsx.js');

var r = s2ab(res.d)[1];
postMessage(r, [r]);
postMessage(r, [r]);
};

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc