

In the example below, export to Excel and note:Īll column headers will be vertically aligned to the middle, have a grey background colour of #f8f8f8 and an orange bottom border bottom of colour #ffab00 due to the Excel Style id header.Īll grouped headers will have a bold font due to Excel Style id headerGroup. You can define custom styles to apply to specific column headers when exported to Excel. An Excel Style with id headerGroup gets automatically applied to the AG Grid grouped headers when exported to Excel.An Excel Style with id header gets automatically applied to all (grouped and not grouped) AG Grid headers when exported to Excel.Similarly to styling cells, the grid will use the result of headerClass from the column definition to style the grid headers. Note that there are specific to Excel styles applied - the age column has a conditional number formatting styling applied: age values less than 23 have a green background applied, and age values less than 20 are using red italic underlined font. This is the case in this example of the year column which has the style notInExcel, but since it hasn't been specified in the gridOptions, the column then gets exported without formatting.Īs you can see in the column Group, the Excel styles can be combined into cellClassRules and cellClass If a cell has a style but there isn't an associated Excel Style defined, the style for that cell won't get exported.

You can see this is in the styling of the darkGreyBackground being applied to even rows. Styles can be combined it a similar fashion to CSS, this can be seen in the column age where athletes less than 20 years old get two styles applied (greenBackground and redFont).Ī default columnDef containing cellClassRules can be specified and it will be exported to Excel. columnDefs = Example: Export With StylesĪn Excel Style with id cell gets automatically applied to all cells ( not headers) when exported to Excel.Īll cells will be vertically aligned to the middle due to Excel Style id cell. The ExcelStyle id cell is applied to every cell that is not a header, and it's useful if you need a style to be applied to all cells. Everyone less than 23 will have a green background, and a light green color font ( #e0ffc1) also because redFont is set in cellClass, it will always be applied.
#Ag grid center align column how to#
The example below demonstrates how to merge the styles in Excel. If more than one Excel style is found, the results are merged (similar to how CSS classes are merged by the browser when multiple classes are applied). In Excel Export, the styles are mapped against the Excel styles that you have provided. Normally these styles map to CSS classes when the grid is doing normal rendering. Resolving Excel StylesĪll the defined classes from cellClass and all the classes resulting from evaluating the cellClassRules are applied to each cell, while the resulting classes from headerClass will be applied to each header cell when exporting to Excel. Whatever resultant class is applicable to the cell then is expected to be provided as an Excel Style to the excelStyles: ExcelStyle property in the gridOptions. In order to simplify the configuration, the Excel Export reuses the cellClassRules, the cellClass and the headerClass from the column definition. The main reason to export to Excel with styles is so that the look and feel remain as consistent as possible with your AG Grid application. Excel Export provides a special mechanism to add styles to the exported spreadsheet that works independently of the styles applied to the grid.
