forked from sheetjs/sheetjs
Demo UTF8 CSV option
This commit is contained in:
parent
cfd92222d2
commit
72af79c866
5
Makefile
5
Makefile
@ -1,11 +1,16 @@
|
||||
.PHONY: update
|
||||
update:
|
||||
git show master:index.html > index.html
|
||||
git show master:dist/cpexcel.js > dist/cpexcel.js
|
||||
git show master:dist/shim.min.js > dist/shim.min.js
|
||||
git show master:dist/xlsx.core.min.js > dist/xlsx.core.min.js
|
||||
git show master:dist/xlsx.full.min.js > dist/xlsx.full.min.js
|
||||
git show master:dist/xlsx.core.min.js > xlsx.core.min.js
|
||||
git show master:dist/xlsx.full.min.js > xlsx.full.min.js
|
||||
git show master:xlsx.js > xlsx.js
|
||||
git show master:shim.js > shim.js
|
||||
git show master:shim.js > tests/shim.js
|
||||
git show master:xlsxworker.js > xlsxworker.js
|
||||
git show master:tests/base64.js > tests/base64.js
|
||||
git show master:dist/xlsx.zahl.js > tests/xlsx.zahl.js
|
||||
git show master:tests/core.js > tests/core.js
|
||||
|
2
dist/shim.min.js
vendored
Normal file
2
dist/shim.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
15
dist/xlsx.core.min.js
vendored
Normal file
15
dist/xlsx.core.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
22
dist/xlsx.full.min.js
vendored
Normal file
22
dist/xlsx.full.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
53
index.html
53
index.html
@ -43,11 +43,13 @@ Output Format: <select name="format" onchange="setfmt()">
|
||||
</select><br />
|
||||
<input type="file" name="xlfile" id="xlf" />
|
||||
|
||||
<b> Drop a spreadsheet file anywhere in the page to see sheet data </b>
|
||||
|
||||
<textarea id="b64data">... or paste a base64-encoding here</textarea>
|
||||
<input type="button" id="dotext" value="Click here to process the base64 text" onclick="b64it();"/><br />
|
||||
<b>Advanced Demo Options:</b>
|
||||
Use Web Workers: (when available) <input type="checkbox" name="useworker" checked>
|
||||
Use readAsBinaryString: (when available) <input type="checkbox" name="userabs" checked>
|
||||
Use Web Workers when available: <input type="checkbox" name="useworker" checked>
|
||||
Always use UTF8 for CSV / text: <input type="checkbox" name="useutf8" checked>
|
||||
</pre>
|
||||
<pre id="out"></pre>
|
||||
<div id="htmlout"></div>
|
||||
@ -56,21 +58,14 @@ Use readAsBinaryString: (when available) <input type="checkbox" name="userabs" c
|
||||
<p>Drop a spreadsheet file here to see sheet data</p>
|
||||
</div>
|
||||
<br />
|
||||
<script src="shim.js"></script>
|
||||
<script src="xlsx.full.min.js"></script>
|
||||
<script src="dist/shim.min.js"></script>
|
||||
<script src="dist/xlsx.full.min.js"></script>
|
||||
<script>
|
||||
/*jshint browser:true */
|
||||
/* eslint-env browser */
|
||||
/* eslint no-use-before-define:0 */
|
||||
/*global Uint8Array, Uint16Array, ArrayBuffer */
|
||||
/*global XLSX */
|
||||
var X = XLSX;
|
||||
var XW = {
|
||||
/* worker message */
|
||||
msg: 'xlsx',
|
||||
/* worker scripts */
|
||||
worker: './xlsxworker.js'
|
||||
};
|
||||
/* eslint no-use-before-define:0 */
|
||||
|
||||
var global_wb;
|
||||
|
||||
@ -88,7 +83,7 @@ var process_wb = (function() {
|
||||
var to_json = function to_json(workbook) {
|
||||
var result = {};
|
||||
workbook.SheetNames.forEach(function(sheetName) {
|
||||
var roa = X.utils.sheet_to_json(workbook.Sheets[sheetName], {header:1});
|
||||
var roa = XLSX.utils.sheet_to_json(workbook.Sheets[sheetName], {header:1});
|
||||
if(roa.length) result[sheetName] = roa;
|
||||
});
|
||||
return JSON.stringify(result, 2, 2);
|
||||
@ -97,7 +92,7 @@ var process_wb = (function() {
|
||||
var to_csv = function to_csv(workbook) {
|
||||
var result = [];
|
||||
workbook.SheetNames.forEach(function(sheetName) {
|
||||
var csv = X.utils.sheet_to_csv(workbook.Sheets[sheetName]);
|
||||
var csv = XLSX.utils.sheet_to_csv(workbook.Sheets[sheetName]);
|
||||
if(csv.length){
|
||||
result.push("SHEET: " + sheetName);
|
||||
result.push("");
|
||||
@ -110,7 +105,7 @@ var process_wb = (function() {
|
||||
var to_fmla = function to_fmla(workbook) {
|
||||
var result = [];
|
||||
workbook.SheetNames.forEach(function(sheetName) {
|
||||
var formulae = X.utils.get_formulae(workbook.Sheets[sheetName]);
|
||||
var formulae = XLSX.utils.get_formulae(workbook.Sheets[sheetName]);
|
||||
if(formulae.length){
|
||||
result.push("SHEET: " + sheetName);
|
||||
result.push("");
|
||||
@ -123,7 +118,7 @@ var process_wb = (function() {
|
||||
var to_html = function to_html(workbook) {
|
||||
HTMLOUT.innerHTML = "";
|
||||
workbook.SheetNames.forEach(function(sheetName) {
|
||||
var htmlstr = X.write(workbook, {sheet:sheetName, type:'string', bookType:'html'});
|
||||
var htmlstr = XLSX.write(workbook, {sheet:sheetName, type:'string', bookType:'html'});
|
||||
HTMLOUT.innerHTML += htmlstr;
|
||||
});
|
||||
return "";
|
||||
@ -157,46 +152,42 @@ var b64it = window.b64it = (function() {
|
||||
var tarea = document.getElementById('b64data');
|
||||
return function b64it() {
|
||||
if(typeof console !== 'undefined') console.log("onload", new Date());
|
||||
var wb = X.read(tarea.value, {type:'base64', WTF:false});
|
||||
var wb = XLSX.read(tarea.value, {type:'base64', WTF:false});
|
||||
process_wb(wb);
|
||||
};
|
||||
})();
|
||||
|
||||
var do_file = (function() {
|
||||
var rABS = typeof FileReader !== "undefined" && (FileReader.prototype||{}).readAsBinaryString;
|
||||
var domrabs = document.getElementsByName("userabs")[0];
|
||||
if(!rABS) domrabs.disabled = !(domrabs.checked = false);
|
||||
|
||||
var use_worker = typeof Worker !== 'undefined';
|
||||
var domwork = document.getElementsByName("useworker")[0];
|
||||
if(!use_worker) domwork.disabled = !(domwork.checked = false);
|
||||
|
||||
var use_utf8 = false;
|
||||
|
||||
var xw = function xw(data, cb) {
|
||||
var worker = new Worker(XW.worker);
|
||||
var worker = new Worker('./xlsxworker.js');
|
||||
worker.onmessage = function(e) {
|
||||
switch(e.data.t) {
|
||||
case 'ready': break;
|
||||
case 'e': console.error(e.data.d); break;
|
||||
case XW.msg: cb(JSON.parse(e.data.d)); break;
|
||||
case 'xlsx': cb(JSON.parse(e.data.d)); break;
|
||||
}
|
||||
};
|
||||
worker.postMessage({d:data,b:rABS?'binary':'array'});
|
||||
worker.postMessage({d:data,b:'array',c:use_utf8 ? 65001 : void 0});
|
||||
};
|
||||
|
||||
return function do_file(files) {
|
||||
rABS = domrabs.checked;
|
||||
use_worker = domwork.checked;
|
||||
use_utf8 = document.getElementsByName("useutf8")[0].checked;
|
||||
var f = files[0];
|
||||
var reader = new FileReader();
|
||||
reader.onload = function(e) {
|
||||
if(typeof console !== 'undefined') console.log("onload", new Date(), rABS, use_worker);
|
||||
var data = e.target.result;
|
||||
if(!rABS) data = new Uint8Array(data);
|
||||
if(typeof console !== 'undefined') console.log("onload", new Date(), use_worker);
|
||||
var data = new Uint8Array(e.target.result);
|
||||
if(use_worker) xw(data, process_wb);
|
||||
else process_wb(X.read(data, {type: rABS ? 'binary' : 'array'}));
|
||||
else process_wb(XLSX.read(data, {type: 'array', codepage: use_utf8 ? 65001 : void 0}));
|
||||
};
|
||||
if(rABS) reader.readAsBinaryString(f);
|
||||
else reader.readAsArrayBuffer(f);
|
||||
reader.readAsArrayBuffer(f);
|
||||
};
|
||||
})();
|
||||
|
||||
|
@ -6,7 +6,7 @@ postMessage({t:"ready"});
|
||||
onmessage = function (evt) {
|
||||
var v;
|
||||
try {
|
||||
v = XLSX.read(evt.data.d, {type: evt.data.b});
|
||||
v = XLSX.read(evt.data.d, {type: evt.data.b, codepage: evt.data.c});
|
||||
postMessage({t:"xlsx", d:JSON.stringify(v)});
|
||||
} catch(e) { postMessage({t:"e",d:e.stack||e}); }
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user