sheetjs_sheetjs/demos/deno/sheet2csv.ts

22 lines
682 B
TypeScript
Raw Normal View History

2022-02-13 09:35:34 +00:00
/*! sheetjs (C) 2013-present SheetJS -- http://sheetjs.com */
2022-03-22 22:19:52 +00:00
// @deno-types="https://unpkg.com/xlsx/types/index.d.ts"
import * as XLSX from 'https://unpkg.com/xlsx/xlsx.mjs';
import * as cptable from 'https://unpkg.com/xlsx/dist/cpexcel.full.mjs';
2022-02-13 09:35:34 +00:00
XLSX.set_cptable(cptable);
const filename = Deno.args[0];
if(!filename) {
console.error("usage: sheet2csv <filename> [sheetname]");
Deno.exit(1);
}
const workbook = XLSX.readFile(filename);
const sheetname = Deno.args[1] || workbook.SheetNames[0];
if(!workbook.Sheets[sheetname]) {
console.error(`error: workbook missing sheet ${sheetname}`);
Deno.exit(1);
}
console.log(XLSX.utils.sheet_to_csv(workbook.Sheets[sheetname]));