Skip to content

Commit

Permalink
version bump 0.7.11: ODS hooks
Browse files Browse the repository at this point in the history
- ODS hooks + very basic parser (ods.js)
- handle implicit row/col spec (h/t @EarlJS, see http://git.io/2lwOuA)
  • Loading branch information
SheetJSDev committed Oct 10, 2014
1 parent 5942587 commit 61d2e55
Show file tree
Hide file tree
Showing 41 changed files with 1,235 additions and 68 deletions.
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ test.js
.jscs.json
.gitmodules
.travis.yml
bits/
odsbits/
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: node_js
node_js:
- "0.11"
- "0.10.30"
- "0.10"
- "0.8"
before_install:
- "npm install -g mocha"
Expand Down
32 changes: 25 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
LIB=xlsx
DEPS=$(sort $(wildcard bits/*.js))
TARGET=$(LIB).js
FMT=xlsx xlsm xlsb misc full
FMT=xlsx xlsm xlsb ods misc full
REQS=jszip.js
ADDONS=dist/cpexcel.js
AUXTARGETS=ods.js

ULIB=$(shell echo $(LIB) | tr a-z A-Z)
DEPS=$(sort $(wildcard bits/*.js))
TARGET=$(LIB).js

.PHONY: all
all: $(TARGET) $(AUXTARGETS)

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

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

.PHONY: clean
clean:
Expand Down Expand Up @@ -45,8 +51,8 @@ $(TESTFMT): test_%:

.PHONY: lint
lint: $(TARGET)
jshint --show-non-errors $(TARGET)
jscs $(TARGET)
jshint --show-non-errors $(TARGET) $(AUXTARGETS)
jscs $(TARGET) $(AUXTARGETS)

.PHONY: test-osx
test-osx:
Expand Down Expand Up @@ -85,7 +91,19 @@ dist: dist-deps $(TARGET) bower.json
uglifyjs $(REQS) $(TARGET) -o dist/$(LIB).core.min.js --source-map dist/$(LIB).core.min.map --preamble "$$(head -n 1 bits/00_header.js)"
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)"

.PHONY: aux
aux: $(AUXTARGETS)

.PHONY: ods
ods: ods.js

ODSDEPS=$(sort $(wildcard odsbits/*.js))
ods.js: $(ODSDEPS)
cat $(ODSDEPS) | tr -d '\15\32' > $@
cp ods.js dist/ods.js

.PHONY: dist-deps
dist-deps:
dist-deps: ods.js
cp node_modules/codepage/dist/cpexcel.full.js dist/cpexcel.js
cp jszip.js dist/jszip.js
cp ods.js dist/ods.js
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# xlsx

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

## Installation

Expand Down Expand Up @@ -36,6 +36,8 @@ be included directly:

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

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

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

Open Document Format for Office Applications Version 1.2 (29 September 2011)


## Badges

[![Build Status](https://travis-ci.org/SheetJS/js-xlsx.svg?branch=master)](https://travis-ci.org/SheetJS/js-xlsx)
Expand Down
2 changes: 1 addition & 1 deletion bits/01_version.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
XLSX.version = '0.7.10';
XLSX.version = '0.7.11';
10 changes: 8 additions & 2 deletions bits/21_ziputils.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,17 @@ function getdata(data) {
return null;
}

function getzipfile(zip, file) {
function safegetzipfile(zip, file) {
var f = file; if(zip.files[f]) return zip.files[f];
f = file.toLowerCase(); if(zip.files[f]) return zip.files[f];
f = f.replace(/\//g,'\\'); if(zip.files[f]) return zip.files[f];
throw new Error("Cannot find file " + file + " in zip");
return null;
}

function getzipfile(zip, file) {
var o = safegetzipfile(zip, file);
if(o == null) throw new Error("Cannot find file " + file + " in zip");
return o;
}

function getzipdata(zip, file, safe) {
Expand Down
16 changes: 9 additions & 7 deletions bits/67_wsxml.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,13 @@ function write_ws_xml_cell(cell, ref, ws, opts, idx, wb) {
}

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

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

/* 18.3.1.4 c CT_Cell */
cells = x.substr(ri).split(cellregex);
for(ri = 1; ri != cells.length; ++ri) {
for(ri = typeof tag.r === 'undefined' ? 0 : 1; ri != cells.length; ++ri) {
x = cells[ri].trim();
if(x.length === 0) continue;
cref = x.match(rregex); idx = ri; i=0; cc=0;
x = "<c " + x;
x = "<c " + (x.substr(0,1)=="<"?">":"") + x;
if(cref !== null && cref.length === 2) {
idx = 0; d=cref[1];
for(i=0; i != d.length; ++i) {
if((cc=d.charCodeAt(i)-64) < 1 || cc > 26) break;
idx = 26*idx + cc;
}
--idx;
}

tagc = idx;
} else ++tagc;
for(i = 0; i != x.length; ++i) if(x.charCodeAt(i) === 62) break; ++i;
tag = parsexmltag(x.substr(0,i), true);
if(!tag.r) tag.r = utils.encode_cell({r:tagr-1, c:tagc});
d = x.substr(i);
p = {t:""};

Expand Down
6 changes: 6 additions & 0 deletions bits/83_parseods.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* Helper function to call out to ODS parser */
function parse_ods(zip, opts) {
if(typeof module !== "undefined" && typeof require !== 'undefined' && typeof ODS === 'undefined') ODS = require('./dist/od' + 's');
if(typeof ODS === 'undefined' || !ODS.parse_ods) throw new Error("Unsupported ODS");
return ODS.parse_ods(zip, opts);
}
4 changes: 4 additions & 0 deletions bits/85_parsezip.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ function parse_zip(zip, opts) {
opts = opts || {};
fix_read_opts(opts);
reset_cp();

/* OpenDocument Part 3 Section 2.2.1 OpenDocument Package */
if(safegetzipfile(zip, 'META-INF/manifest.xml')) return parse_ods(zip, opts);

var entries = keys(zip.files).filter(nodirs).sort();
var dir = parse_ct(getzipdata(zip, '[Content_Types].xml'), opts);
var xlsb = false;
Expand Down
3 changes: 2 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "js-xlsx",
"homepage": "https://github.com/SheetJS/js-xlsx",
"main": "dist/xlsx.js",
"version": "0.7.10",
"version": "0.7.11",
"ignore": [
"bin",
"bits",
Expand All @@ -14,6 +14,7 @@
"xlsx",
"xlsm",
"xlsb",
"ods",
"js-xlsx"
]
}
Loading

0 comments on commit 61d2e55

Please sign in to comment.