5

I am currently using NodeJS and the library SheetsJS to read an XLSX workbook.

My task is to take data from multiple sheets and append them to a new worksheet. The structure of the sheet has the Categories in Column A and Category Values in Column B.

*Things I've Tried * I have tried 2 things that have presented 2 different issues:

1.) I've tried using the builtin function sheet_to_json to format my xlsx data into JSON but it makes the header the key for every object. I've used the option skipHeader: true to negate this but if A1 is the header, A2 is the next value that gets repeated as the object.

Below is a code snippet:

let readFiletoJSON = filename => {
    //wb = workbook
    let wb = xlsx.readFile(filename, {cellDates: true});

    let ws = wb.Sheets["1-Header"]

    let currentRange = { s: { c: 0, r: 1 }, e: { c: 1, r: 10 } }
    let encodedRange = xlsx.utils.encode_range(currentRange)

    let sheetData = []
    sheetData.push(
        xlsx.utils.sheet_to_json(ws, {range: encodedRange}, {skipHeader: true})
    )

    console.log(sheetData)

2.) I have also tried creating my own array of objects with Column A as the key and Column B as the value however, I have trouble figuring out how to read the object into the new worksheet. How can I read the values into the new sheet?

I hope this is clear enough. Thank you in advance.

hello_there
  • 175
  • 3
  • 9

0 Answers0