本文整理汇总了TypeScript中xlsx.utils.sheet_to_json方法的典型用法代码示例。如果您正苦于以下问题:TypeScript utils.sheet_to_json方法的具体用法?TypeScript utils.sheet_to_json怎么用?TypeScript utils.sheet_to_json使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xlsx.utils
的用法示例。
在下文中一共展示了utils.sheet_to_json方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: parseRegister
/**
* Save all clients from the register to the database.
* @param {Object} register - Register worksheet to save to database.
*/
function parseRegister(worksheet: xlxs.IWorkSheet): db.Client[] {
const register: ExcelClient[] = xlxs.utils.sheet_to_json(worksheet) as any
register.sort((a, b) => {
if (a.nimi < b.nimi) return -1
if (a.nimi > b.nimi) return 1
return 0
})
let clients: db.Client[] = []
let clientName = ''
for (const client of register) {
if (client.nimi === clientName) {
// Add listed share number to clients shares
clients[clients.length-1].shares.push(client.numero)
} else if (client.nimi) {
clientName = client.nimi
clients.push({
name: client.nimi,
address: client.lähiosoite,
postOffice: client.postitoimipaikka,
shares: [client.numero]
})
}
}
return clients
}
示例2:
workbook.SheetNames.forEach((sheetName) => {
let worksheet = workbook.Sheets[sheetName];
let worksheetAsJson = xlsx.utils.sheet_to_json(worksheet);
input[sheetName] = [];
worksheetAsJson.forEach((item) => {
let row = {};
for(var k in item) {
row[k] = item[k];
}
input[sheetName].push(row);
});
});
示例3:
const str1: string = XLSX.utils.sheet_to_csv(ws2, {
FS: "\t",
RS: "|",
dateNF: "yyyy-mm-dd",
strip: true,
blankrows: true,
skipHidden: true
});
const html1: string = XLSX.utils.sheet_to_html(ws3, {
editable: false
});
const arr1: object[] = XLSX.utils.sheet_to_json(ws1, {
raw: true,
range: 1,
header: "A",
dateNF: "yyyy-mm-dd",
defval: 0,
blankrows: true
});
const arr2: any[][] = XLSX.utils.sheet_to_json<any[][]>(ws2, {
header: 1
});
const arr3: any[] = XLSX.utils.sheet_to_json(ws3, {
header: ["Sheet", "JS", "Rocks"]
});