From aa4e13a18da64451358b129e6439afb87e3d0fb5 Mon Sep 17 00:00:00 2001 From: Joao Ramos Date: Tue, 27 Aug 2024 23:11:40 +0100 Subject: [PATCH] Fixed an use case where the export of Excel failed if no students had answered it --- src/pages/api/assignments/[id]/[export]/excel.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/pages/api/assignments/[id]/[export]/excel.ts b/src/pages/api/assignments/[id]/[export]/excel.ts index bf19569e..d4fa7f05 100644 --- a/src/pages/api/assignments/[id]/[export]/excel.ts +++ b/src/pages/api/assignments/[id]/[export]/excel.ts @@ -195,12 +195,16 @@ function commonExcel({ // K10:M12 = 10,11,12,13 // horizontally group Test Sections - worksheet.mergeCells( - startIndexTable, - staticHeaders.length + 1, - startIndexTable, - tableColumnHeadersFirstPart.length - ); + + // if there are test section headers to even merge: + if(testSectionHeaders.length > 1) { + worksheet.mergeCells( + startIndexTable, + staticHeaders.length + 1, + startIndexTable, + tableColumnHeadersFirstPart.length + ); + } // Add the dynamic second and third header rows for test sections and sub-columns worksheet.addRow([