Skip to content

Commit 61d2e55

Browse files
committed
version bump 0.7.11: ODS hooks
- ODS hooks + very basic parser (ods.js) - handle implicit row/col spec (h/t @EarlJS, see http://git.io/2lwOuA)
1 parent 5942587 commit 61d2e55

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1235
-68
lines changed

.npmignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,5 @@ test.js
2121
.jscs.json
2222
.gitmodules
2323
.travis.yml
24+
bits/
25+
odsbits/

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
language: node_js
22
node_js:
33
- "0.11"
4-
- "0.10.30"
4+
- "0.10"
55
- "0.8"
66
before_install:
77
- "npm install -g mocha"

Makefile

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
LIB=xlsx
2-
DEPS=$(sort $(wildcard bits/*.js))
3-
TARGET=$(LIB).js
4-
FMT=xlsx xlsm xlsb misc full
2+
FMT=xlsx xlsm xlsb ods misc full
53
REQS=jszip.js
64
ADDONS=dist/cpexcel.js
5+
AUXTARGETS=ods.js
6+
7+
ULIB=$(shell echo $(LIB) | tr a-z A-Z)
8+
DEPS=$(sort $(wildcard bits/*.js))
9+
TARGET=$(LIB).js
10+
11+
.PHONY: all
12+
all: $(TARGET) $(AUXTARGETS)
713

814
$(TARGET): $(DEPS)
915
cat $^ | tr -d '\15\32' > $@
1016

1117
bits/01_version.js: package.json
12-
echo "XLSX.version = '"`grep version package.json | awk '{gsub(/[^0-9a-z\.-]/,"",$$2); print $$2}'`"';" > $@
18+
echo "$(ULIB).version = '"`grep version package.json | awk '{gsub(/[^0-9a-z\.-]/,"",$$2); print $$2}'`"';" > $@
1319

1420
.PHONY: clean
1521
clean:
@@ -45,8 +51,8 @@ $(TESTFMT): test_%:
4551

4652
.PHONY: lint
4753
lint: $(TARGET)
48-
jshint --show-non-errors $(TARGET)
49-
jscs $(TARGET)
54+
jshint --show-non-errors $(TARGET) $(AUXTARGETS)
55+
jscs $(TARGET) $(AUXTARGETS)
5056

5157
.PHONY: test-osx
5258
test-osx:
@@ -85,7 +91,19 @@ dist: dist-deps $(TARGET) bower.json
8591
uglifyjs $(REQS) $(TARGET) -o dist/$(LIB).core.min.js --source-map dist/$(LIB).core.min.map --preamble "$$(head -n 1 bits/00_header.js)"
8692
uglifyjs $(REQS) $(ADDONS) $(TARGET) -o dist/$(LIB).full.min.js --source-map dist/$(LIB).full.min.map --preamble "$$(head -n 1 bits/00_header.js)"
8793

94+
.PHONY: aux
95+
aux: $(AUXTARGETS)
96+
97+
.PHONY: ods
98+
ods: ods.js
99+
100+
ODSDEPS=$(sort $(wildcard odsbits/*.js))
101+
ods.js: $(ODSDEPS)
102+
cat $(ODSDEPS) | tr -d '\15\32' > $@
103+
cp ods.js dist/ods.js
104+
88105
.PHONY: dist-deps
89-
dist-deps:
106+
dist-deps: ods.js
90107
cp node_modules/codepage/dist/cpexcel.full.js dist/cpexcel.js
91108
cp jszip.js dist/jszip.js
109+
cp ods.js dist/ods.js

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# xlsx
22

3-
Parser and writer for Excel 2007+ (XLSX/XLSM/XLSB) files. Pure-JS cleanroom
4-
implementation from the Office Open XML spec, [MS-XLSB], and related documents.
3+
Parser and writer for Excel 2007+ (XLSX/XLSM/XLSB) files and parser for ODS files.
4+
Pure-JS cleanroom implementation from the Office Open XML spec, [MS-XLSB], and related documents.
55

66
## Installation
77

@@ -36,6 +36,8 @@ be included directly:
3636

3737
<!-- international support from https://github.com/sheetjs/js-codepage -->
3838
<script src="dist/cpexcel.js"></script>
39+
<!-- ODS support -->
40+
<script src="dist/ods.js"></script>
3941

4042
An appropriate version for each dependency is included in the dist/ directory.
4143

@@ -458,6 +460,9 @@ OSP-covered specifications:
458460
- [MS-OE376]: Office Implementation Information for ECMA-376 Standards Support
459461
- [MS-XLDM]: Spreadsheet Data Model File Format
460462

463+
Open Document Format for Office Applications Version 1.2 (29 September 2011)
464+
465+
461466
## Badges
462467

463468
[![Build Status](https://travis-ci.org/SheetJS/js-xlsx.svg?branch=master)](https://travis-ci.org/SheetJS/js-xlsx)

bits/01_version.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
XLSX.version = '0.7.10';
1+
XLSX.version = '0.7.11';

bits/21_ziputils.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,17 @@ function getdata(data) {
1313
return null;
1414
}
1515

16-
function getzipfile(zip, file) {
16+
function safegetzipfile(zip, file) {
1717
var f = file; if(zip.files[f]) return zip.files[f];
1818
f = file.toLowerCase(); if(zip.files[f]) return zip.files[f];
1919
f = f.replace(/\//g,'\\'); if(zip.files[f]) return zip.files[f];
20-
throw new Error("Cannot find file " + file + " in zip");
20+
return null;
21+
}
22+
23+
function getzipfile(zip, file) {
24+
var o = safegetzipfile(zip, file);
25+
if(o == null) throw new Error("Cannot find file " + file + " in zip");
26+
return o;
2127
}
2228

2329
function getzipdata(zip, file, safe) {

bits/67_wsxml.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,13 @@ function write_ws_xml_cell(cell, ref, ws, opts, idx, wb) {
148148
}
149149

150150
var parse_ws_xml_data = (function parse_ws_xml_data_factory() {
151-
var cellregex = /<(?:\w+:)?c /, rowregex = /<\/(?:\w+:)?row>/;
151+
var cellregex = /<(?:\w+:)?c[ >]/, rowregex = /<\/(?:\w+:)?row>/;
152152
var rregex = /r=["']([^"']*)["']/, isregex = /<is>([\S\s]*?)<\/is>/;
153153
var match_v = matchtag("v"), match_f = matchtag("f");
154154

155155
return function parse_ws_xml_data(sdata, s, opts, guess) {
156156
var ri = 0, x = "", cells = [], cref = [], idx = 0, i=0, cc=0, d="", p;
157-
var tag;
157+
var tag, tagr = 0, tagc = 0;
158158
var sstr;
159159
var fmtid = 0, fillid = 0, do_format = Array.isArray(styles.CellXf), cf;
160160
for(var marr = sdata.split(rowregex), mt = 0, marrlen = marr.length; mt != marrlen; ++mt) {
@@ -165,29 +165,31 @@ return function parse_ws_xml_data(sdata, s, opts, guess) {
165165
/* 18.3.1.73 row CT_Row */
166166
for(ri = 0; ri < xlen; ++ri) if(x.charCodeAt(ri) === 62) break; ++ri;
167167
tag = parsexmltag(x.substr(0,ri), true);
168-
var tagr = parseInt(tag.r, 10);
168+
/* SpreadSheetGear uses implicit r/c */
169+
tagr = typeof tag.r !== 'undefined' ? parseInt(tag.r, 10) : tagr+1; tagc = -1;
169170
if(opts.sheetRows && opts.sheetRows < tagr) continue;
170171
if(guess.s.r > tagr - 1) guess.s.r = tagr - 1;
171172
if(guess.e.r < tagr - 1) guess.e.r = tagr - 1;
172173

173174
/* 18.3.1.4 c CT_Cell */
174175
cells = x.substr(ri).split(cellregex);
175-
for(ri = 1; ri != cells.length; ++ri) {
176+
for(ri = typeof tag.r === 'undefined' ? 0 : 1; ri != cells.length; ++ri) {
176177
x = cells[ri].trim();
177178
if(x.length === 0) continue;
178179
cref = x.match(rregex); idx = ri; i=0; cc=0;
179-
x = "<c " + x;
180+
x = "<c " + (x.substr(0,1)=="<"?">":"") + x;
180181
if(cref !== null && cref.length === 2) {
181182
idx = 0; d=cref[1];
182183
for(i=0; i != d.length; ++i) {
183184
if((cc=d.charCodeAt(i)-64) < 1 || cc > 26) break;
184185
idx = 26*idx + cc;
185186
}
186187
--idx;
187-
}
188-
188+
tagc = idx;
189+
} else ++tagc;
189190
for(i = 0; i != x.length; ++i) if(x.charCodeAt(i) === 62) break; ++i;
190191
tag = parsexmltag(x.substr(0,i), true);
192+
if(!tag.r) tag.r = utils.encode_cell({r:tagr-1, c:tagc});
191193
d = x.substr(i);
192194
p = {t:""};
193195

bits/83_parseods.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/* Helper function to call out to ODS parser */
2+
function parse_ods(zip, opts) {
3+
if(typeof module !== "undefined" && typeof require !== 'undefined' && typeof ODS === 'undefined') ODS = require('./dist/od' + 's');
4+
if(typeof ODS === 'undefined' || !ODS.parse_ods) throw new Error("Unsupported ODS");
5+
return ODS.parse_ods(zip, opts);
6+
}

bits/85_parsezip.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ function parse_zip(zip, opts) {
1919
opts = opts || {};
2020
fix_read_opts(opts);
2121
reset_cp();
22+
23+
/* OpenDocument Part 3 Section 2.2.1 OpenDocument Package */
24+
if(safegetzipfile(zip, 'META-INF/manifest.xml')) return parse_ods(zip, opts);
25+
2226
var entries = keys(zip.files).filter(nodirs).sort();
2327
var dir = parse_ct(getzipdata(zip, '[Content_Types].xml'), opts);
2428
var xlsb = false;

bower.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "js-xlsx",
33
"homepage": "https://github.com/SheetJS/js-xlsx",
44
"main": "dist/xlsx.js",
5-
"version": "0.7.10",
5+
"version": "0.7.11",
66
"ignore": [
77
"bin",
88
"bits",
@@ -14,6 +14,7 @@
1414
"xlsx",
1515
"xlsm",
1616
"xlsb",
17+
"ods",
1718
"js-xlsx"
1819
]
1920
}

0 commit comments

Comments
 (0)