Skip to content

Commit

Permalink
version bump 0.8.2: ODS and cleanup
Browse files Browse the repository at this point in the history
- README and example cleanup
- basic XLSB and ODS write support
- flow typecheck for ODS file
  Note: xlsx.js flow fails: facebook/flow#380
- exposed jszip compression (fixes SheetJS#220, closes SheetJS#284)

README issues:

|  id  | author         | comment                                      |
|-----:|:---------------|:---------------------------------------------|
| SheetJS#202 | @sao93859      | closes SheetJS#202                                  |
| SheetJS#211 | @alexanderchan | closes SheetJS#211 corrected examples               |
| SheetJS#327 | @cskaandorp    | changed saveAs example to match write tests  |
| SheetJS#424 | @dskrvk        | added note about s2roa h/t @LeonardoPatignio |
| SheetJS#496 | @jimmywarting  | closes SheetJS#496 adapted rABS examples with rAAS  |

ODS file format issues:

|  id  | author         | comment                                      |
|-----:|:---------------|:---------------------------------------------|
| SheetJS#148 | @user4815162342| closes SheetJS#148 h/t @ziacik                      |
| SheetJS#166 | @paulproteus   | closes SheetJS#166 rudimentary ODS write support    |
| SheetJS#177 | @ziacik        | closes SheetJS#177                                  |
| SheetJS#179 | @ziacik        | closes SheetJS#179 use JSON when available          |
| SheetJS#317 | @ziacik        | closes SheetJS#317                                  |
| SheetJS#328 | @think01       | closes SheetJS#328                                  |
| SheetJS#383 | @mdamt         | closes SheetJS#383 duplicate cells should be copied |
| SheetJS#430 | @RB-Lab        | closes SheetJS#430                                  |
| SheetJS#546 | @lgodard       | closes SheetJS#546 thanks to other changes          |
  • Loading branch information
SheetJSDev committed Feb 3, 2017
1 parent 2a756ff commit 86d6a09
Show file tree
Hide file tree
Showing 66 changed files with 13,914 additions and 298 deletions.
17 changes: 15 additions & 2 deletions .flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,21 @@
.*/demo/browser.js
.*/shim.js

.*/odsbits/.*
.*/ods.js
.*/xlsx.js
.*/xlsxworker.js
.*/xlsxworker1.js
.*/xlsxworker2.js
.*/jszip.js
.*/tests/.*

.*/xlsx.flow.js
[include]
xlsx.js
xlsxworker.flow.js
xlsxworker1.flow.js
xlsxworker2.flow.js
ods.flow.js
.*/bin/.*.njs
.*/demo/browser.flow.js

Expand All @@ -23,4 +36,4 @@ misc/flowdeps.js
[options]
module.file_ext=.js
module.file_ext=.njs

module.ignore_non_literal_requires=true
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ tmp
*.xlsb
*.xlsm
*.xlsx
*.xlsm
*.xlsb
*.ods
*.xml
*.htm
*.html
Expand Down
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ tmp
*.xlsb
*.xlsm
*.xlsx
*.ods
*.xml
*.htm
*.html
Expand Down
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ node_js:
- "5"
- "4.2"
- "0.12"
- "0.11"
- "0.10"
- "0.9"
- "0.8"
before_install:
- "npm install -g npm@next"
Expand Down
17 changes: 12 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,19 @@ ULIB=$(shell echo $(LIB) | tr a-z A-Z)
DEPS=$(sort $(wildcard bits/*.js))
TARGET=$(LIB).js
FLOWTARGET=$(LIB).flow.js
FLOWAUX=$(patsubst %.js,%.flow.js,$(AUXTARGETS))
AUXSCPTS=xlsxworker1.js xlsxworker2.js xlsxworker.js
FLOWTGTS=$(TARGET) $(AUXTARGETS) $(AUXSCPTS)

## Main Targets

.PHONY: all
all: $(TARGET) $(AUXTARGETS) ## Build library and auxiliary scripts
all: $(TARGET) $(AUXTARGETS) $(AUXSCPTS) ## Build library and auxiliary scripts

$(TARGET): $(DEPS)
$(FLOWTGTS): %.js : %.flow.js
node -e 'process.stdout.write(require("fs").readFileSync("$<","utf8").replace(/^[ \t]*\/\*[:#][^*]*\*\/\s*(\n)?/gm,"").replace(/\/\*[:#][^*]*\*\//gm,""))' > $@

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

bits/01_version.js: package.json
Expand Down Expand Up @@ -58,6 +64,8 @@ dist-deps: ods.js ## Copy dependencies for distribution
cp node_modules/codepage/dist/cpexcel.full.js dist/cpexcel.js
cp jszip.js dist/jszip.js
cp ods.js dist/ods.js
uglifyjs ods.js -o dist/ods.min.js --source-map dist/ods.min.map --preamble "$$(head -n 1 bits/00_header.js)"
misc/strip_sourcemap.sh dist/ods.min.js

bower.json: misc/_bower.json package.json
cat $< | sed 's/_VERSION_/'`grep version package.json | awk '{gsub(/[^0-9a-z\.-]/,"",$$2); print $$2}'`'/' > $@
Expand All @@ -69,9 +77,8 @@ aux: $(AUXTARGETS)
ods: ods.js

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


## Testing
Expand All @@ -90,7 +97,7 @@ $(TESTFMT): test_%:
## Code Checking

.PHONY: lint
lint: $(TARGET) ## Run jshint and jscs checks
lint: $(TARGET) $(AUXTARGETS) ## Run jshint and jscs checks
@jshint --show-non-errors $(TARGET) $(AUXTARGETS)
@jshint --show-non-errors $(CMDS)
@jshint --show-non-errors package.json bower.json
Expand Down
93 changes: 71 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,18 @@ Supported read formats:

Supported write formats:

- XLSX
- Excel 2007+ XML Formats (XLSX/XLSM)
- Excel 2007+ Binary Format (XLSB) nodejs only
- CSV (and general DSV)
- JSON and JS objects (various styles)
- OpenDocument Spreadsheet (ODS)

Demo: <http://oss.sheetjs.com/js-xlsx>

Source: <http://git.io/xlsx>

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

## Installation

With [npm](https://www.npmjs.org/package/xlsx):
Expand Down Expand Up @@ -53,7 +57,7 @@ circumstances, so they do not ship with the core. For browser use, they must
be included directly:

```html
<!-- international support from https://github.com/sheetjs/js-codepage -->
<!-- international support from js-codepage -->
<script src="dist/cpexcel.js"></script>
<!-- ODS support -->
<script src="dist/ods.js"></script>
Expand Down Expand Up @@ -116,45 +120,75 @@ oReq.onload = function(e) {
oReq.send();
```

- 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 */
function handleDrop(e) {
e.stopPropagation();
e.preventDefault();
var files = e.dataTransfer.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();
var name = f.name;
reader.onload = function(e) {
var data = e.target.result;

/* 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);
}
}
drop_dom_element.addEventListener('drop', handleDrop, false);
```

- 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();
var name = f.name;
reader.onload = function(e) {
var data = e.target.result;

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 */
};
Expand All @@ -164,6 +198,11 @@ function handleFile(e) {
input_dom_element.addEventListener('change', handleFile, false);
```

The readAsArrayBuffer form requires some preprocessing:

```js
```

## Working with the Workbook

The full object format is described later in this README.
Expand Down Expand Up @@ -254,7 +293,7 @@ function s2ab(s) {
}

/* 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");
```

Complete examples:
Expand Down Expand Up @@ -290,8 +329,11 @@ Utilities are available in the `XLSX.utils` object:
Exporting:

- `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_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:

Expand Down Expand Up @@ -371,7 +413,7 @@ Type `d` is the Date type, generated only when the option `cellDates` is passed.
Since JSON does not have a natural Date type, parsers are generally expected to
store ISO 8601 Date strings like you would get from `date.toISOString()`. On
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.

Type `s` is the String type. `v` should be explicitly stored as a string to
Expand All @@ -395,7 +437,7 @@ Special worksheet keys (accessible as `worksheet[key]`, each starting with `!`):
Functions that handle worksheets should test for the presence of `!ref` field.
If the `!ref` is omitted or is not a valid range, functions are free to treat
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).

When reading a worksheet with the `sheetRows` property set, the ref parameter
Expand Down Expand Up @@ -468,9 +510,10 @@ The exported `write` and `writeFile` functions accept an options argument:

| Option Name | Default | Description |
| :---------- | ------: | :--------------------------------------------------- |
| cellDates | false | Store dates as type `d` (default is `n`) |
| bookSST | false | Generate Shared String Table ** |
| 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") |
| compression | `false` | Use file compression for formats with ZIP containers |

- `bookSST` is slower and more memory intensive, but has better compatibility
with older versions of iOS Numbers
Expand All @@ -483,16 +526,16 @@ The exported `write` and `writeFile` functions accept an options argument:

## Tested Environments

- NodeJS 0.8, 0.10 (latest release), 0.11.14 (unstable), io.js
- 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 using Base64 mode (IE10/11 using HTML5 mode)
- FF 18 using Base64 or HTML5 mode
- Chrome 24 using Base64 or HTML5 mode

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

## Test Files

Expand Down Expand Up @@ -537,7 +580,7 @@ version release and should not be committed between versions.
## License

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.

It is the opinion of the Original Author that this code conforms to the terms of
the Microsoft Open Specifications Promise, falling under the same terms as
Expand Down Expand Up @@ -573,10 +616,16 @@ Open Document Format for Office Applications Version 1.2 (29 September 2011)

## Badges

[![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)

[![Coverage Status](http://img.shields.io/coveralls/SheetJS/js-xlsx/master.svg)](https://coveralls.io/r/SheetJS/js-xlsx?branch=master)

[![Analytics](https://ga-beacon.appspot.com/UA-36810333-1/SheetJS/js-xlsx?pixel)](https://github.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)
17 changes: 10 additions & 7 deletions bin/xlsx.njs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ if(process.version === 'v0.10.31') {
process.exit(1);
}

var filename, sheetname = '';
var filename/*:?string*/, sheetname = '';
if(program.args[0]) {
filename = program.args[0];
if(program.args[1]) sheetname = program.args[1];
Expand All @@ -60,13 +60,13 @@ if(!filename) {
console.error(n + ": must specify a filename");
process.exit(1);
}

/*:: if(filename) { */
if(!fs.existsSync(filename)) {
console.error(n + ": " + filename + ": No such file or directory");
process.exit(2);
}

var opts = {}, wb;
var opts = {}, wb/*:?Workbook*/;
if(program.listSheets) opts.bookSheets = true;
if(program.sheetRows) opts.sheetRows = program.sheetRows;
if(program.password) opts.password = program.password;
Expand Down Expand Up @@ -98,16 +98,17 @@ else try {
}
if(program.read) process.exit(0);

/*:: if(wb) { */
if(program.listSheets) {
console.log(wb.SheetNames.join("\n"));
process.exit(0);
}

var wopts = {WTF:opts.WTF, bookSST:program.sst};

if(program.xlsx) return X.writeFile(wb, sheetname || (filename + ".xlsx"), wopts);
if(program.xlsm) return X.writeFile(wb, sheetname || (filename + ".xlsm"), wopts);
if(program.xlsb) return X.writeFile(wb, sheetname || (filename + ".xlsb"), wopts);
if(program.xlsx) { X.writeFile(wb, sheetname || (filename + ".xlsx"), wopts); process.exit(0); }
if(program.xlsm) { X.writeFile(wb, sheetname || (filename + ".xlsm"), wopts); process.exit(0); }
if(program.xlsb) { X.writeFile(wb, sheetname || (filename + ".xlsb"), wopts); process.exit(0); }

var target_sheet = sheetname || '';
if(target_sheet === '') target_sheet = wb.SheetNames[0];
Expand All @@ -121,7 +122,7 @@ try {
process.exit(4);
}

if(program.perf) return;
if(program.perf) process.exit(0);

var oo = "";
if(!program.quiet) console.error(target_sheet);
Expand All @@ -132,3 +133,5 @@ else oo = X.utils.make_csv(ws, {FS:program.fieldSep, RS:program.rowSep});

if(program.output) fs.writeFileSync(program.output, oo);
else console.log(oo);
/*:: } */
/*:: } */
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.8.1';
XLSX.version = '0.8.2';
Loading

0 comments on commit 86d6a09

Please sign in to comment.