Sheetjs: Add a sheet_to_aoa function

Created on 6 Sep 2018  路  2Comments  路  Source: SheetJS/sheetjs

Would be handy to be able to turn the sheet into an array of arrays.

for (const row of xlsx.utils.sheet_to_aoa(s)) {
  for (const cell of row) {
  //...
  } 
}

May also help with #1234

Most helpful comment

Just found out about header: 1 in sheet_to_json, so above can become:

function sheet_to_aoa(sheet) {
  return xlsx.utils.sheet_to_json(sheet, {header: 1})
}

All 2 comments

Here is a workaround implementation via tab-separated-values:

const xlsx = require('xlsx')

function sheet_to_aoa(sheet)  {
  const FS = '\t'
  return xlsx.utils.sheet_to_csv(sheet, {FS}).split('\n').map(r => r.split(FS))
}

Just found out about header: 1 in sheet_to_json, so above can become:

function sheet_to_aoa(sheet) {
  return xlsx.utils.sheet_to_json(sheet, {header: 1})
}
Was this page helpful?
0 / 5 - 0 ratings