Skip to content

Commit 4001b89

Browse files
add width and dropdown
1 parent 85cdc3a commit 4001b89

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/index.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,18 +220,29 @@ async function convertJsonToCommonStyledExcel(data) {
220220
const endCol = startCol + (cell.colspan || 1) - 1;
221221

222222
worksheet.mergeCells(startRow, startCol, endRow, endCol);
223-
224-
colIndex += cell.colspan || 1;
223+
colIndex += (cell.colspan || 1);
224+
}
225+
else if (cell.dropdown) {
226+
const formulae = [`"${cell.dropdown.join(",")}"`];
227+
worksheet.getCell(rowIndex + 1, colIndex).dataValidation = {
228+
type: 'list',
229+
allowBlank: false,
230+
formulae: formulae,
231+
showErrorMessage: true,
232+
errorTitle: 'Invalid Selection',
233+
error: 'Please select a value from the dropdown',
234+
};
235+
colIndex++;
225236
} else {
226237
colIndex++;
227238
}
228239
});
229240
});
230241
worksheet.columns.forEach(column => {
231-
column.width = 20; // Set a default width
242+
column.width = column.width ? column.width : 20; // Set a default width
232243
});
233244
}
234-
const buffer = await workbook.xlsx.writeBuffer()
245+
const buffer = await workbook.xlsx.writeBuffer();
235246
return buffer
236247
}
237248

0 commit comments

Comments
 (0)