Framework:Javascript Data GridAngular Data GridReact Data GridVue Data Grid

JavaScript Data Grid: Excel Export API Reference

This page documents the Excel Export API and Interfaces.

Grid Properties

suppressExcelExport
boolean
Prevents the user from exporting the grid to Excel.
Default: false
excelStyles
A list (array) of Excel styles to be used when exporting to Excel with styles.
excelStyles: ExcelStyle[];

interface ExcelStyle {
  id: string;
  alignment?: ExcelAlignment;
  borders?: ExcelBorders;
  dataType?: ExcelDataType;
  font?: ExcelFont;
  interior?: ExcelInterior;
  numberFormat?: ExcelNumberFormat;
  protection?: ExcelProtection;
}

API Methods

exportDataAsExcel
Function
Downloads an Excel export of the grid's data.
function exportDataAsExcel(
    params?: ExcelExportParams
): void;
getDataAsExcel
Similar to exportDataAsExcel, except instead of downloading a file, it will return a Blob to be processed by the user.
function getDataAsExcel(
    params?: ExcelExportParams
): string | Blob | undefined;
getSheetDataForExcel
Function
This is method to be used to get the grid's data as a sheet, that will later be exported either by getMultipleSheetsAsExcel() or exportMultipleSheetsAsExcel().
function getSheetDataForExcel(
    params?: ExcelExportParams
): string | undefined;
exportMultipleSheetsAsExcel
Function
Downloads an Excel export of multiple sheets in one file.
function exportMultipleSheetsAsExcel(
    params: ExcelExportMultipleSheetParams
): void;

interface ExcelExportMultipleSheetParams {
  author?: string;
  data: string[];
  fileName?: string;
  fontSize?: number;
}
getMultipleSheetsAsExcel
Similar to exportMultipleSheetsAsExcel, except instead of downloading a file, it will return a Blob to be processed by the user.
function getMultipleSheetsAsExcel(
    params: ExcelExportMultipleSheetParams
): Blob | undefined;

interface ExcelExportMultipleSheetParams {
  author?: string;
  data: string[];
  fileName?: string;
  fontSize?: number;
}

Interfaces

ExcelExportParams:

author
string
The author of the exported file.
Default: 'AG Grid'
autoConvertFormulas
boolean
If set to true, this will try to convert any cell that starts with = to a formula, instead of setting the cell value as regular string that starts with =.
Default: false
columnWidth
number
Defines the default column width. If no value is present, each column will have value currently set in the application with a min value of 75px. This property can also be supplied a callback function that returns a number: (params: ColumnWidthCallbackParams) => number.
exportMode
string
For backwards compatibility, this property could be set to xml, which will export an Excel Spreadsheet compatible with old Office versions (prior to Office 2007). Setting this to xml is not recommended as some features will not work in legacy mode.
Default: 'xlsx'
Options: 'xlsx', 'xml'
fontSize
number
The default value for the font size of the Excel document.
Default: 11
headerRowHeight
number | Function
The height in pixels of header rows. Defaults to Excel default value. This property can also be supplied a callback function that returns a number: (params: RowHeightCallbackParams) => number.
rowHeight
number | Function
The height in pixels of all rows. Defaults to Excel default value. This property can also be supplied a callback function that returns a number: (params: RowHeightCallbackParams) => number.
sheetName
string
The name of the sheet in Excel where the grid will be exported. There is a max limit of 31 characters.
Default: 'ag-grid'
appendContent
Content to put at the top of the exported sheet. A 2D array of ExcelCell objects (see Extra Content section).
prependContent
Content to put at the bottom of the exported sheet. A 2D array of ExcelCell objects (see Extra Content section).
allColumns
boolean
If true, all columns will be exported in the order they appear in the columnDefs. When false only the columns currently being displayed will be exported.
Default: false
columnKeys
(string | Column)[]
Provide a list (an array) of column keys or Column objects if you want to export specific columns.
fileName
string
String to use as the file name.
Default: 'export.xlsx'
onlySelected
boolean
Export only selected rows.
Default: false
onlySelectedAllPages
boolean
Only export selected rows including other pages (only makes sense when using pagination).
Default: false
margins
The Excel document page margins. Relevant for printing.
pageSetup
Allows you to setup the page orientation and size.
suppressTextAsCDATA
boolean
If true, text content will be encoded with XML character entities like < and >. This is only relevant when exportMode='xml'.
Default: false
skipColumnGroupHeaders
boolean
Set to true to exclude header column groups.
Default: false
skipColumnHeaders
boolean
Set to true if you don't want to export column headers.
Default: false
skipRowGroups
boolean
Set to true to skip row group headers if grouping rows. Only relevant when grouping rows.
Default: false
skipPinnedBottom
boolean
Set to true to suppress exporting rows pinned to the bottom of the grid.
Default: false
getCustomContentBelowRow
A callback function to return content to be inserted below a row in the export.
getCustomContentBelowRow = (
    params: GetCustomContentBelowRowParams
) => ExcelCell;

interface GetCustomContentBelowRowParams {
  node: RowNode;
  api: GridApi;
  columnApi: ColumnApi;
  context: object;
}

interface ExcelCell {
  ref?: string;
  styleId?: string;
  data: ExcelData;
  mergeAcross?: number;
}
shouldRowBeSkipped
Function
A callback function that will be invoked once per row in the grid. Return true to omit the row from the export.
shouldRowBeSkipped = (
    params: ShouldRowBeSkippedParams
) => boolean;

interface ShouldRowBeSkippedParams {
  node: RowNode;
  api: GridApi;
  context: object;
}
processCellCallback
Function
A callback function invoked once per cell in the grid. Return a string value to be displayed in the export. For example this is useful for formatting date values.
processCellCallback = (
    params: ProcessCellCallbackParams
) => string;

interface ProcessCellCallbackParams {
  node: RowNode;
  api: GridApi;
  columnApi: ColumnApi;
  context: object;
  value: any;
  accumulatedRowIndex: number;
  column: Column;
  type: string;
}
processHeaderCallback
Function
A callback function invoked once per column. Return a string to be displayed in the column header.
processHeaderCallback = (
    params: ProcessHeaderCallbackParams
) => string;

interface ProcessHeaderCallbackParams {
  node: RowNode;
  api: GridApi;
  columnApi: ColumnApi;
  context: object;
}
processGroupHeaderCallback
Function
A callback function invoked once per column group. Return a string to be displayed in the column group header. Note that column groups are exported by default, this option will not work with skipColumnGroupHeaders=true.
processGroupHeaderCallback = (
    params: ProcessGroupHeaderCallbackParams
) => string;

interface ProcessGroupHeaderCallbackParams {
  node: RowNode;
  api: GridApi;
  columnApi: ColumnApi;
  context: object;
}
processRowGroupCallback
Function
A callback function invoked once per row group. Return a string to be displayed in the group cell.
processRowGroupCallback = (
    params: ProcessRowGroupCallbackParams
) => string;

interface ProcessRowGroupCallbackParams {
  node: RowNode;
  api: GridApi;
  columnApi: ColumnApi;
  context: object;
}
addImageToCell
Function
A callback function invoked once per cell. Return an ExcelImage object to add an image to the current cell.
addImageToCell = (
    params: AddImageToCellParams
) => AddImageToCell;

interface AddImageToCellParams {
  rowIndex: number;
  column: Column;
  value: string;
}

interface AddImageToCell {
  image: ExcelImage;
  value: string;
}

ExcelExportMultipleSheetParams:

author
string
The author of the exported file.
Default: 'AG Grid'
data
string[]
Array of strings containing the raw data for Excel workbook sheets. This property is only used when exporting to multiple sheets using api.exportMultipleSheetsAsExcel() and the data for each sheet is obtained by calling api.getSheetDataForExcel(). See Multiple Sheets.
fileName
string
String to use as the file name.
Default: 'export.xlsx'
fontSize
number
The default value for the font size of the Excel document.
Default: 11

ExcelCell

data
The data that will be added to the cell.
styleId
string
The ExcelStyle id to be associated with the cell.
mergeAcross
number
The number of cells to span across (1 means span 2 columns)
Default: 0

ExcelData

type *
The type of data being in the cell.
value *
string
The value of the cell.

ExcelImage

id *
string
The image id. This field is required so the same image doesn't get imported multiple times.
base64 *
string
A base64 string that represents the image being imported. See more info about Base64/
imageType *
string
The type of image being exported.
Options: 'jpg', 'png', 'gif'
fitCell
boolean
If set to true, the image will cover the whole cell that is being imported to.
Default: false
transparency
number
Set a value between 0 - 100 that will indicate the percentage of transparency of the image.
Default: 0
rotation
number
Set a value between 0 - 359 that will indicate the number of degrees to rotate the image clockwise.
Default: 0
recolor
string
Set this property to select a preset that changes the appearance of the image.
Options: 'Grayscale', 'Sepia', 'Washout'
width
number
The width of the image in pixels. If this value is not selected, fitCell will be automatically set to true.
height
number
The height of the image in pixels. If this value is not selected, fitCell will be automatically set to true.
position
See position for more details.

position

excelImage > position
row
number
The row containing this image. This property is set automatically, don't change it unless you know what you are doing.
rowSpan
number
The amount of rows this image will cover.
Default: 1
column
number
The column containing this image. This property is set automatically, don't change it unless you know what you are doing.
colSpan
number
The amount of columns this image will cover.
Default: 1
offsetX
number
The amount in pixels the image should be offset horizontally.
Default: 0
offsetY
number
The amount in pixels the image should be offset vertically.
Default: 0

ExcelStyle

id *
string
The id of the Excel Style, this should match a CSS cell class.
alignment
Use this property to customise cell alignment properties.
borders
Use this property to customise cell borders.
dataType
Use this property to specify the type of data being exported.
Default: 'String'
font
Use this property to customise the font used in the cell.
interior
Use this property to customise the cell background.
numberFormat
Use this property to customise the cell value as a formatted number.
protection
Use this property to setup cell protection.

ExcelAlignment

horizontal
string
Use this property to change the cell horizontal alignment.
Default: 'Automatic'
Options: 'Automatic', 'Left', 'Center', 'Right', 'Fill', 'Justify', 'CenterAcrossSelection', 'Distributed', 'JustifyDistributed'
indent
number
Use this property to change the level of indentation in the cell.
Default: 0
readingOrder
string
Use this property to change the cell reading order.
Default: 'LeftToRight'
Options: 'RightToLeft', 'LeftToRight', 'Context'
rotate
number
The number of degrees between 0 and 359 to rotate the text.
Default: 0
shrinkToFit
boolean
If set to true, the font size of the cell will automatically change to force the text to fit within the cell.
Default: false
vertical
string
Use this property to change the cell vertical alignment.
Default: 'Automatic'
Options: 'Automatic', 'Top', 'Bottom', 'Center', 'Justify', 'Distributed', 'JustifyDistributed'
wrapText
boolean
If set to true, multiline text will be displayed as multiline by Excel.
Default: false

ExcelBorders

borderBottom
Use to set the cell's bottom border.
borderLeft
Use to set the cell's left border.
borderRight
Use to set the cell's right border.
borderTop
Use to set the cell's top border.

ExcelBorder

color
string
The color of the border.
Default: 'black'
lineStyle
string
The style of the border.
Default: 'None'
Options: 'None', 'Continuous', 'Dash', 'Dot', 'DashDot', 'DashDotDot', 'SlantDashDot', 'Double'
weight
number
The thickness of the border from 0 (thin) to 3 (thick)
Default: 0
Options: 0, 1, 2, 3

ExcelFont

bold
boolean
Set to true to set the cell text to bold.
Default: false
color
string
The color of the cell font.
Default: '#000000'
family
string
The family of the font to used in the cell.
Default: 'Automatic'
Options: 'Automatic', 'Roman', 'Swiss', 'Modern', 'Script', 'Decorative'
fontName
string
The name of the font to be used in the cell.
Default: 'Calibri'
italic
boolean
Set to true to display the cell font as italic.
Default: false
outline
boolean
Set to true to add a text outline.
Default: false
shadow
boolean
Set to true to add text shadow.
Default: false
size
number
Set this property to used a different font size other than the default.
strikeThrough
boolean
Set to true to add a strikeThrough line.
Default: false
underline
string
Use this property to underline the cell text.
Options: 'Single', 'Double'
verticalAlign
string
Use this property to change the default font alignment. Note: This is different than setting cell vertical alignment.
Options: 'Superscript', 'Subscript'

ExcelInterior

color
string
The colour of the cell background.
pattern
string
Use this property to set background color patterns.
Default: 'None'
Options: 'None', 'Solid', 'Gray75', 'Gray50', 'Gray25', 'Gray125', 'Gray0625', 'HorzStripe', 'VertStripe', 'ReverseDiagStripe', 'DiagStripe', 'DiagCross', 'ThickDiagCross', 'ThinHorzStripe', 'ThinVertStripe', 'ThinReverseDiagStripe', 'ThinDiagStripe', 'ThinHorzCross', 'ThinDiagCross'
patternColor
string
The colour to be used as a secondary colour combined with patterns.

ExcelNumberFormat

format
string
Use this property to provide a pattern to format a number. (eg. 10000 could become $10,000.00).

ExcelProtection

protected
boolean
Set to false to disable cell protection (locking)
Default: true
hideFormula
boolean
Set to true to hide formulas within protected cells
Default: false

ExcelSheetMargin

top
number
The sheet top margin.
Default: 0.75
right
number
The sheet right margin.
Default: 0.7
bottom
number
The sheet bottom margin.
Default: 0.75
left
number
The sheet left margin.
Default: 0.7
header
number
The sheet header margin.
Default: 0.3
number
The sheet footer margin.
Default: 0.3

ExcelSheetPageSetup

orientation
string
Use this property to change the print orientation.
Default: 'Portrait'
Options: 'Portrait', 'Landscape'
pageSize
string
Use this property to set the sheet size.
Default: 'Letter'
Options: 'Letter', 'Letter Small', 'Tabloid', 'Ledger', 'Legal', 'Statement', 'Executive', 'A3', 'A4', 'A4 Small', 'A5', 'A6', 'B4', 'B5', 'Folio', 'Envelope', 'Envelope DL', 'Envelope C5', 'Envelope B5', 'Envelope C3', 'Envelope C4', 'Envelope C6', 'Envelope Monarch', 'Japanese Postcard', 'Japanese Double Postcard'

ExcelHeaderFooterConfig

all
The configuration for header and footer on every page.
first
The configuration for header and footer on the first page only.
even
The configuration for header and footer on even numbered pages only..

ExcelHeaderFooter

header
An array of maximum 3 items (Left, Center, Right), containing header configurations.
An array of maximum 3 items (Left, Center, Right), containing footer configurations.

ExcelHeaderFooterContent

value *
string
The value of the text to be included in the header.
position
string
Configures where the text should be added (Left, Center, Right)
Default: 'Left'
Options: 'Left', 'Center', 'Right'
font
The font style of the header/footer value.

Types

ExcelDataType

type ExcelDataType = 'String' | 'Formula' | 'Number' | 'Boolean' | 'DateTime' | 'Error'

ExcelOOXMLDataType

type ExcelOOXMLDataType = 'str' | 's' | 'f' | 'inlineStr' | 'n' | 'b' | 'd' | 'e' | 'empty'