I have an excel file. And I need to group its rows with some rules.
As you see in excel sheet, there are two groups. Each group's question begins with 'Q' and a number like 'Q1, Q2, Q3....'
- A column first row is question
- B column first row is style
- C column first row is season
- if there is Blank tag, it has to be empty array.
- Below parts are detail.

I want to create a json format like
const data = [
[],
{
"question": "this is example question.",
"style": "table",
"thead": "Gender Identity",
"season": "",
"detail": [{
"answer": "Male",
"percent": "50%",
"response": "5"
},
{
"answer": "Female",
"percent": "50%",
"response": "5"
},
{
"answer": "Non-binary",
"percent": "0%",
"response": "0"
},
{
"answer": "Trans*",
"percent": "0%",
"response": "0"
},
{
"answer": "Prefer not to say",
"percent": "0%",
"response": "0"
},
{
"answer": "Self describe (please specify)",
"percent": "0%",
"response": "0"
}
]
},
{
"question": "example question 2",
"style": "table",
"thead": "Age",
"season": "",
"group": "",
"detail": [{
"answer": "50-59 years old",
"percent": "0%",
"response": "0"
},
{
"answer": "60-69 years old",
"percent": "0%",
"response": "0"
},
{
"answer": "70-79 years old",
"percent": "30%",
"response": "3"
},
{
"answer": "80-89 years old",
"percent": "50%",
"response": "5"
},
{
"answer": "90+ years old",
"percent": "20%",
"response": "2"
}
]
}
]
I tried xlsx library and read xlsx file. But it gives me multiple array but not an appropriate one. For importing and reading data, I used
const filename = path.join(__dirname, `./tempXLSX/dump.xlsx`)
const readOpts = {
cellText: false,
cellDates: true
};
const jsonOpts = {
header: 1,
defval: '',
blankrows: true,
raw: false,
}
const workbook = XLSX.readFile(filename, readOpts);
const worksheet = workbook.Sheets['Sheet'];
const isXLSXFiletoJSON = XLSX.utils.sheet_to_json(worksheet, jsonOpts)