From a9dd6def72d78c17e738362eccb1479b6be656ed Mon Sep 17 00:00:00 2001 From: SheetJS Date: Wed, 20 Feb 2013 10:25:02 -0500 Subject: [PATCH] refactoring the csv generation code XLSX.utils.sheet_to_csv --- bin/xlsx2csv.njs | 19 +--------------- index.html | 59 ++++++++++++++++++------------------------------ xlsx.js | 24 ++++++++++++++++++++ 3 files changed, 47 insertions(+), 55 deletions(-) diff --git a/bin/xlsx2csv.njs b/bin/xlsx2csv.njs index a7f63c5..44ba00f 100755 --- a/bin/xlsx2csv.njs +++ b/bin/xlsx2csv.njs @@ -25,22 +25,5 @@ if(xlsx.SheetNames.indexOf(sheetname)===-1) { process.exit(1); } -function stringify(val) { - switch(val.t){ - case 'n': return val.v; - case 's': case 'str': return JSON.stringify(val.v); - default: throw 'unrecognized type ' + val.t; - } -} var sheet = xlsx.Sheets[sheetname]; -if(sheet["!ref"]) { - var r = utils.decode_range(sheet["!ref"]); - for(var R = r.s.r; R <= r.e.r; ++R) { - var row = []; - for(var C = r.s.c; C <= r.e.c; ++C) { - var val = sheet[utils.encode_cell({c:C,r:R})]; - row.push(val ? stringify(val) : ""); - } - console.log(row.join(",")); - } -} +console.log(XLSX.utils.sheet_to_csv(sheet)); diff --git a/index.html b/index.html index c30c5cf..3d21968 100644 --- a/index.html +++ b/index.html @@ -20,47 +20,30 @@