node-excel-export
node-excel-export copied to clipboard
Header merging with two headers is not working
I have two Headers listed below var heading = [ [{value: 'a1', style: styles.headerDark}, {value: 'b1', style: styles.headerDark}, {value: 'c1', style: styles.headerDark}] ]; if i merge that headers like below First header only showing in excel second header appear as empty header but colum merged from 8th col to 10th column. var merges = [ { start: { row: 1, column: 1 }, end: { row: 1, column: 7 } }, { start: { row: 1, column: 8 }, end: { row: 1, column: 10 } } ]
Finally var report = excel.buildExport( [ // <- Notice that this is an array. Pass multiple sheets to create multi sheet report { name: 'Report',// <- Specify sheet name (optional) merges: merges, // <- Merge cell ranges heading: heading, // <- Raw heading array (optional) specification: specification,// <- Report specification headerStyle: styles.headerDark, data: dataset // <-- Report data } ] ); @andreyan-andreev Please Resolve this issue
The above issue is solved by doing the following In index.js remove the below lines sheet.heading.forEach(function (row) { data.push(row) })
Replace the above code with the following
merges.forEach(function (merge) { mergeCount++; specCount=0 for (let col in specification) { if(specCount == merge.start.column-1){ headerArray.push(sheet.heading[0][mergeCount-1]) }else if(merge.end.column >= specCount && merge.start.column < specCount){ headerArray.push({value: ''}) } specCount++ } })
data.push(headerArray)
Then the header merge will work fine if you do this
Please make a correction and update the code @andreyan-andreev