jQuery Grid Export to Excel Options

The export options specific for Excel. The excel dictionary can contain the following settings, all being optional:

  • fileName - the name of the file that will be saved.
  • fileFormat - the Excel format of the file that will be saved. Use "xml" for the Excel 2003 and "xlsx" for the newer Excel 2007 format. NOTE: In order to save the generated Excel file in "xlsx" format, you will need to load the third-party JSZip JavaScript library as shown in this example. If "xlsx" is specified and the zip library is not found, the exporting process will fall back to the 2003 "xml" format by default.
  • noLegacyFallback - suppress falling back to the Excel 2003 "xml" format when "xlsx" is specified and the JSZip library is not available.
  • author - the author of the Excel spreadsheet document.
  • created - the creation Date of the Excel spreadsheet document.
  • dataSource - DataSource options or variable, that can be used to override the current dataSource used by the Grid. If the data source specified here will not be read, one must set the readDataSource variable to true in order for the exporting process to read it.
  • readDataSource - read the custom DataSource, specified with the above option.
  • columnFields - a list of fields determining which fields from the dataSource items to export as columns. If not specified, the current Grid columns will be used.
  • header - the worksheet header options.
    • enabled - indicates whether to dislpay a header or not
    • style - style for the header cells. A style can contain the following options:
      • textAlign - horizontal alignment of the text in the cell. Can be "left", "right" or "center".
      • verticalAlign - vertical alignment of the text in the cell. Can be "top", "bottom" or "center".
      • wrap - a boolean value indicating whether the text in a cell should wrap at the cell boundary.
      • format - the custom number format string for the cell. Checkout this article for more information about number formatting in Excel.
      • bold - a boolean value indicating whether the text in the cell should be bold.
      • italic - a boolean value indicating whether the text in the cell should be italic.
      • color - the text color in a hex format (e.g: #E3E3E3).
      • fontName - the name of the font (e.g: Arial).
      • fontSize - the size of the font used for the cell.
      • background: - the cell background color in hex format(e.g: #E3E3E3).
    • cells - a list of options for the header cells. Cell options include:
      • style - the cell style (see above.)
      • type - the type of the cell - String, Number, Boolean or Date.
      • value - the value of the cell.
      • index - the index of the cell in the row (NOT zero-based).
      • colSpan - the number of adjacent cells to merge with the current cell. The cells to merge will be to the right of the current cell unless the worksheet is set to display left-to-right.
      • rowSpan - the number of adjacent cells below the current cell that are to be merged with the current cell.
  • worksheet - the options for the worksheet, that will be generated from the data. Valid optinos are:
    • name - the worksheet name
    • columns - a list of styles for each column of the worksheet. Column styles include:
      • autoWidth - a boolean value indicating whether the column should be automatically resized to fit data.
      • index - the index of the column (NOT zero-based).
      • width - the column width in pixels (points for the Excel 2003 "xml" format).
  • worksheets - additional worksheets to be added to the Excel file. Each worksheet can contain:
    • name - the name of the worksheet.
    • columns - a list of column styles (see above).
    • rows - a list of rows. Each row can have:
      • index - the index of the row in the worksheet (NOT zero-based).
      • height - the row height.
      • cells - a list of all cells in the row (see above).
  • worksheetIndex - the zero-based index, where to put the worksheet generated by the Grid. Defaults to 0, which will cause it to be put first, before any additional worksheets specified.
...
exportOptions: {
    excel: {
        fileName: "Untitled",
        fileFormat: "xlsx",
        noLegacyFallback: false,
        author: UNDEFINED,
        created: new Date(),
        dataSource: {
            data: gridData
        },
        readDataSource: true,
        columnFields: ["name", "email"],
        header: {
            enabled: true,
            style: {
                bold: true
            },
            cells: [
                {
                    value: "Name",
                    style: {
                        bold: true
                    }
                },
                {
                    value: "Email Address",
                    style: {
                        bold: true,
                        italic: true
                    }
                }
            ]
        },
        worksheet: {
            name: "Sheet1",
            columns: [
                {
                    autoWidth: true
                },
                {
                    autoWidth: true
                }
            ]
        },
        worksheets: [],
        worksheetIndex: 0
    }
}
...