Skip to content

Commit

Permalink
feat: xlsx 1:1 value support for root table
Browse files Browse the repository at this point in the history
  • Loading branch information
mkeen committed Jan 24, 2022
1 parent 40d06de commit caa3204
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/utils/xls.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,22 @@ export const createXlsFromSequelizeResults = (rows, model, hex = false, csv = fa
let mainXlsRow = [];

// Populate main sheet values
for (const [mainColName, mainCol] of columnsInMainSheet.entries()) {
if (!associations.map(singular => singular + 's').includes(mainColName)) {
if (row[mainCol] === null) {
row[mainCol] = 'null';
for (const [i, mainColName] of columnsInMainSheet.entries()) {
if (row[mainColName] === null) {
row[mainColName] = 'null';
}

if (Object.keys(row).includes(mainColName) && Object.keys(row[mainColName]).includes('id')) {
if (!Object.keys(sheets).includes(mainColName + 's')) {
sheets[mainColName + 's'] = { name: mainColName + 's', data: [Object.keys(row[mainColName]).concat([model.name.split('_').join('') + 'Id'])], };
}
sheets[mainColName + 's'].data.push(Object.values(row[mainColName]).map(val1 => encodeValue(val1, hex)).concat([encodeValue(row[mainColName].id, hex)]));
}
if (!associations.map(singular => singular + 's').includes(i)) { // Todo: change to colNames[i], but also filter column headings first (for skipping assoc cols)
if (row[mainColName] === null) {
row[mainColName] = 'null';
}
mainXlsRow.push(encodeValue(row[mainCol], hex));
mainXlsRow.push(encodeValue(row[mainColName], hex));
}
}

Expand Down

0 comments on commit caa3204

Please sign in to comment.