Grid Excel export adding header only uses first cell of header

Hello,


I am trying to add a header when exporting to excel. There should be two different cells in the header but only the first one appears. Below is the properties passed to the function when exporting and an image of what the excel sheet looks like. Attached is the code being used for the exporting.

If I am doing something wrong please let me know.


Thanks,

Charles


Attachment: app.component_ede7fa4c.zip

1 Reply 1 reply marked as answer

RS Rajapandiyan Settu Syncfusion Team December 21, 2021 11:50 AM UTC

Hi Charles, 

Thanks for contacting Syncfusion support. 

Query: I am trying to add a header when exporting to excel. There should be two different cells in the header but only the first one appears. 

We have analyzed your query at our end. By validating your code, we found that the index is not defined to the cells used in headerRows. This is the cause of reported behavior. You can resolve the reported behavior by using following code example. 



[app.component.ts] 

 
      const excelExportProperties1any = { 
        header: { 
          headerRows: 1, 
          rows: [ 
            { 
              cells: [ 
                {  
                  index: 1,  // provide the index of the cell 
                  colSpan: 4, 
                  value: 'This is a Real Corporation', 
                  style: { 
                    fontColor: '#ffffff', 
                    hAlign: 'Center', 
                    backColor: '#467FA5', 
                  }, 
                }, 
                { 
                  index: 5, // provide the index of the cell 
                  colSpan: 2, 
                  value: 'Test', 
                  style: { 
                    fontColor: '#ffffff', 
                    hAlign: 'Center', 
                    backColor: '#90AFC4', 
                  }, 
                }, 
              ], 
            }, 
          ], 
        }, 
      }; 
      this.grid.excelExport(excelExportProperties1); 
 


We have prepared a sample for your reference. You can get it from the below link. 


Please get back to us if you need further assistance with this. 

Regards, 
Rajapandiyan S 


Marked as answer
Loader.
Up arrow icon