From e9a7a4bde78b39e5f920e32fcbe4acfd7b026686 Mon Sep 17 00:00:00 2001 From: SheetJS Date: Sat, 3 Feb 2018 15:46:32 -0500 Subject: [PATCH] version bump 0.11.19: browser `writeFile` - IE6-9 ActiveX + VBScript shim - `writeFile` supported in browser - `oldie` demo for IE write strategies --- .gitignore | 1 + Makefile | 4 ++-- index.html | 2 +- nexthdr.js | 1 - pages/index.js | 1 + preact.html | 8 ++++---- sheetjs.jsx | 17 ++++++++++------- 7 files changed, 19 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index 6a9a216..c23b6db 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ SheetJS .next +static/shim.js diff --git a/Makefile b/Makefile index 826c888..a63d201 100644 --- a/Makefile +++ b/Makefile @@ -4,8 +4,9 @@ react: ## Simple server for react and clones .PHONY: next next: init ## next.js demo - mkdir -p pages + mkdir -p pages static cat nexthdr.js sheetjs.jsx > pages/sheetjs.js + cp ../../shim.js static/shim.js next .PHONY: native @@ -24,4 +25,3 @@ android: native ## react-native android sim init: ## set up node_modules and symlink mkdir -p node_modules cd node_modules; if [ ! -e xlsx ]; then ln -s ../../../ xlsx; fi; cd - - if [ ! -e node_modules/file-saver ]; then npm install file-saver; fi diff --git a/index.html b/index.html index 4d051dc..a6cde0d 100644 --- a/index.html +++ b/index.html @@ -9,8 +9,8 @@ + - diff --git a/nexthdr.js b/nexthdr.js index 18594af..4224974 100644 --- a/nexthdr.js +++ b/nexthdr.js @@ -1,3 +1,2 @@ /* xlsx.js (C) 2013-present SheetJS -- http://sheetjs.com */ import XLSX from 'xlsx'; -import { saveAs } from 'file-saver'; diff --git a/pages/index.js b/pages/index.js index 6935cd9..0ae8f28 100644 --- a/pages/index.js +++ b/pages/index.js @@ -6,6 +6,7 @@ export default () => ( SheetJS React Demo + diff --git a/preact.html b/preact.html index 3e9bb6a..b08d90d 100644 --- a/preact.html +++ b/preact.html @@ -4,20 +4,20 @@ -SheetJS React Demo +SheetJS Preact Demo - - + +
-

SheetJS React Demo

+

SheetJS Preact Demo


Source Code Repo
Issues? Something look weird? Click here and report an issue

diff --git a/sheetjs.jsx b/sheetjs.jsx index c8216b9..4da567f 100644 --- a/sheetjs.jsx +++ b/sheetjs.jsx @@ -18,10 +18,11 @@ class SheetJSApp extends React.Component { handleFile(file/*:File*/) { /* Boilerplate to set up FileReader */ const reader = new FileReader(); + const rABS = !!reader.readAsBinaryString; reader.onload = (e) => { /* Parse data */ const bstr = e.target.result; - const wb = XLSX.read(bstr, {type:'binary'}); + const wb = XLSX.read(bstr, {type:rABS ? 'binary' : 'array'}); /* Get first worksheet */ const wsname = wb.SheetNames[0]; const ws = wb.Sheets[wsname]; @@ -30,17 +31,15 @@ class SheetJSApp extends React.Component { /* Update state */ this.setState({ data: data, cols: make_cols(ws['!ref']) }); }; - reader.readAsBinaryString(file); + if(rABS) reader.readAsBinaryString(file); else reader.readAsArrayBuffer(file); }; exportFile() { /* convert state to workbook */ const ws = XLSX.utils.aoa_to_sheet(this.state.data); const wb = XLSX.utils.book_new(); XLSX.utils.book_append_sheet(wb, ws, "SheetJS"); - /* generate XLSX file */ - const wbout = XLSX.write(wb, {type:"array", bookType:"xlsx"}); - /* send to client */ - saveAs(new Blob([wbout],{type:"application/octet-stream"}), "sheetjs.xlsx"); + /* generate XLSX file and send to client */ + XLSX.writeFile(wb, "sheetjs.xlsx") }; render() { return ( @@ -137,4 +136,8 @@ const SheetJSFT = [ ].map(function(x) { return "." + x; }).join(","); /* generate an array of column objects */ -const make_cols = refstr => Array(XLSX.utils.decode_range(refstr).e.c + 1).fill(0).map((x,i) => ({name:XLSX.utils.encode_col(i), key:i})); +const make_cols = refstr => { + let o = [], C = XLSX.utils.decode_range(refstr).e.c + 1; + for(var i = 0; i < C; ++i) o[i] = {name:XLSX.utils.encode_col(i), key:i} + return o; +};