From 984cdf94dc66b74d20409f73fe93e3996e21e4ca Mon Sep 17 00:00:00 2001 From: SheetJS Date: Sat, 2 Mar 2013 01:47:41 -0500 Subject: [PATCH] updating html demo to handle base64 text --- index.html | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/index.html b/index.html index 3d21968..1772382 100644 --- a/index.html +++ b/index.html @@ -8,12 +8,17 @@ text-align:center; font:20pt bold,"Vollkorn";color:#bbb } +#b64data{ + width:100%; +} -JS-XLSX
+JS-XLSX Live Demo
CSV
JSON
-
Drop an XLSX file here to see the output in CSV.
+
Drop an XLSX file here to see data in CSV or JSON.
+ +

 
@@ -46,6 +51,23 @@ function to_csv(sheet) { return XLSX.utils.sheet_to_csv(sheet); } +var tarea = document.getElementById('b64data'); +function b64it() { + var xlsx = XLSX.read(tarea.value, {type: 'base64'}); + process_xlsx(xlsx); +} + +function process_xlsx(xlsx) { + var output = ""; + if(get_radio_value("format") === "json"){ + output = JSON.stringify(to_json(xlsx), 2, 2); + } else { + output = to_csv(xlsx.Sheets[xlsx.SheetNames[0]]); + } + if(out.innerText === undefined) out.textContent = output; + else out.innerText = output; +} + var drop = document.getElementById('drop'); function handleDrop(e) { e.stopPropagation(); @@ -58,13 +80,7 @@ function handleDrop(e) { reader.onload = function(e) { var data = e.target.result; var xlsx = XLSX.read(data, {type: 'binary'}); - var output = ""; - if(get_radio_value("format") === "json"){ - output = JSON.stringify(to_json(xlsx), 2, 2); - } else { - output = to_csv(xlsx.Sheets[xlsx.SheetNames[0]]); - } - out.innerText = output; + process_xlsx(xlsx); }; reader.readAsBinaryString(f); }