forked from SheetJS/sheetjs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
version bump 0.7.0: Basic write support
- very basic XLSX / XLSM write support with roundtrip tests (XLSB stubs) - reorganized source tree - new XLSB range check ensures that A1 is not emitted for empty sheets - SSF table emitted in output (consistent with js-xls) - CLI supports writing Backwards-incompatible changes: o new Property aliases (see CORE_PROPS and EXT_PROPS) o FILETIME custom properties parsed as JS Dates o `xlsx2csv` -> `xlsx` (and `bin/xlsx{2csv,}.njs`)
- Loading branch information
1 parent
b645f6e
commit d15b81e
Showing
47 changed files
with
3,455 additions
and
1,544 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
node_modules | ||
misc/coverage.html | ||
tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,9 +10,13 @@ program | |
.option('-f, --file <file>', 'use specified workbook') | ||
.option('-s, --sheet <sheet>', 'print specified sheet (default first sheet)') | ||
.option('-l, --list-sheets', 'list sheet names and exit') | ||
.option('-o, --output <file>', 'output to specified file') | ||
/*.option('-B, --xlsb', 'emit XLSB to <sheetname> or <file>.xlsb') */ | ||
.option('-M, --xlsm', 'emit XLSM to <sheetname> or <file>.xlsm') | ||
.option('-X, --xlsx', 'emit XLSX to <sheetname> or <file>.xlsx') | ||
.option('-S, --formulae', 'print formulae') | ||
.option('-j, --json', 'emit formatted JSON rather than CSV (all fields text)') | ||
.option('-J, --raw-js', 'emit raw JS object rather than CSV (raw numbers)') | ||
.option('-j, --json', 'emit formatted JSON (all fields text)') | ||
.option('-J, --raw-js', 'emit raw JS object (raw numbers)') | ||
.option('-F, --field-sep <sep>', 'CSV field separator', ",") | ||
.option('-R, --row-sep <sep>', 'CSV row separator', "\n") | ||
.option('-n, --sheet-rows <num>', 'Number of rows to process (0=all rows)') | ||
|
@@ -21,6 +25,7 @@ program | |
.option('-q, --quiet', 'quiet mode'); | ||
|
||
program.on('--help', function() { | ||
console.log(' Default output format is CSV'); | ||
console.log(' Support email: [email protected]'); | ||
console.log(' Web Demo: http://oss.sheetjs.com/js-'+n+'/'); | ||
}); | ||
|
@@ -36,19 +41,22 @@ if(program.sheet) sheetname = program.sheet; | |
if(program.file) filename = program.file; | ||
|
||
if(!filename) { | ||
console.error(n + "2csv: must specify a filename"); | ||
console.error(n + ": must specify a filename"); | ||
process.exit(1); | ||
} | ||
|
||
if(!fs.existsSync(filename)) { | ||
console.error(n + "2csv: " + filename + ": No such file or directory"); | ||
console.error(n + ": " + filename + ": No such file or directory"); | ||
process.exit(2); | ||
} | ||
|
||
var opts = {}, wb; | ||
if(program.listSheets) opts.bookSheets = true; | ||
if(program.sheetRows) opts.sheetRows = program.sheetRows; | ||
|
||
if(program.xlsx || program.xlsm || program.xlsb) { | ||
opts.cellNF = true; | ||
if(program.output) sheetname = program.output; | ||
} | ||
if(program.dev) { | ||
X.verbose = 2; | ||
opts.WTF = true; | ||
|
@@ -57,7 +65,7 @@ if(program.dev) { | |
else try { | ||
wb = X.readFile(filename, opts); | ||
} catch(e) { | ||
var msg = (program.quiet) ? "" : n + "2csv: error parsing "; | ||
var msg = (program.quiet) ? "" : n + ": error parsing "; | ||
msg += filename + ": " + e; | ||
console.error(msg); | ||
process.exit(3); | ||
|
@@ -69,6 +77,12 @@ if(program.listSheets) { | |
process.exit(0); | ||
} | ||
|
||
var wopts = {WTF:opts.WTF}; | ||
|
||
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); | ||
|
||
var target_sheet = sheetname || ''; | ||
if(target_sheet === '') target_sheet = wb.SheetNames[0]; | ||
|
||
|
@@ -77,12 +91,15 @@ try { | |
ws = wb.Sheets[target_sheet]; | ||
if(!ws) throw "Sheet " + target_sheet + " cannot be found"; | ||
} catch(e) { | ||
console.error(n + "2csv: error parsing "+filename+" "+target_sheet+": " + e); | ||
console.error(n + ": error parsing "+filename+" "+target_sheet+": " + e); | ||
process.exit(4); | ||
} | ||
|
||
if(!program.quiet) console.error(target_sheet); | ||
if(program.formulae) console.log(X.utils.get_formulae(ws).join("\n")); | ||
else if(program.json) console.log(JSON.stringify(X.utils.sheet_to_row_object_array(ws))); | ||
else if(program.rawJs) console.log(JSON.stringify(X.utils.sheet_to_row_object_array(ws,{raw:true}))); | ||
else console.log(X.utils.make_csv(ws, {FS:program.fieldSep, RS:program.rowSep})); | ||
var oo = ""; | ||
if(program.formulae) oo = X.utils.get_formulae(ws).join("\n"); | ||
else if(program.json) oo = JSON.stringify(X.utils.sheet_to_row_object_array(ws)); | ||
else if(program.rawJs) oo = JSON.stringify(X.utils.sheet_to_row_object_array(ws,{raw:true})); | ||
else oo = X.utils.make_csv(ws, {FS:program.fieldSep, RS:program.rowSep}); | ||
|
||
if(program.output) fs.writeFileSync(program.output, oo); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
XLSX.version = '0.6.2'; | ||
XLSX.version = '0.7.0'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
function isval(x) { return typeof x !== "undefined" && x !== null; } | ||
|
||
function keys(o) { return Object.keys(o).filter(function(x) { return o.hasOwnProperty(x); }); } | ||
|
||
function evert(obj, arr) { | ||
var o = {}; | ||
keys(obj).forEach(function(k) { | ||
if(!obj.hasOwnProperty(k)) return; | ||
if(!arr) o[obj[k]] = k; | ||
else (o[obj[k]]=o[obj[k]]||[]).push(k); | ||
}); | ||
return o; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.