sheetjs_sheetjs/types/xlsx-tests.ts

26 lines
646 B
TypeScript
Raw Normal View History

import xlsx = require('xlsx');
2017-05-13 23:37:23 +00:00
const options: xlsx.ParsingOptions = {
2017-05-12 21:46:39 +00:00
cellDates: true
};
2017-05-12 21:46:46 +00:00
const workbook = xlsx.readFile('test.xlsx', options);
const otherworkbook = xlsx.readFile('test.xlsx', {type: 'file'});
console.log(workbook.Props.Author);
2017-05-12 21:46:46 +00:00
const firstsheet: string = workbook.SheetNames[0];
2017-05-12 21:46:46 +00:00
const firstworksheet = workbook.Sheets[firstsheet];
console.log(firstworksheet["A1"]);
2017-05-13 23:37:23 +00:00
interface Tester {
2017-05-12 21:46:39 +00:00
name: string;
age: number;
}
2017-05-13 23:37:23 +00:00
const jsonvalues: Tester[] = xlsx.utils.sheet_to_json<Tester>(firstworksheet);
2017-05-12 21:46:46 +00:00
const csv = xlsx.utils.sheet_to_csv(firstworksheet);
const formulae = xlsx.utils.sheet_to_formulae(firstworksheet);