# Report Format Type - Excel

Canonical page: https://www.adaptabletools.com/docs/handbook-exporting-reports-format-type-excel

- Excel exports produce a downloadable workbook (Clipboard is not available for this format)
- Requires AG Grid's `ExcelExportModule`
- Use `excelSheetName` in Export Options for the default worksheet name; use `exportReport` + `exportConfig.exportParams` for one-off AG Grid Excel params

The most commonly used Report Format Type is `Excel`, where the exported data can be opened in Excel.

This option is only available if the `ExcelExportModule` [AG Grid Module](https://www.adaptabletools.com/docs/getting-started-aggrid-modules/index.md) is loaded

When using this option only the downloadable File [System Export Destination](https://www.adaptabletools.com/docs/handbook-exporting-destinations/index.md) is available (i.e. the data cannot be sent to the Clipboard).

Users **are** able to create a [Custom Export Destination](https://www.adaptabletools.com/docs/handbook-exporting-destinations-custom/index.md), e.g S3, and then export the Excel formatted data there

## Excel sheet name

By default AdapTable names the worksheet `Sheet 1`. Set `excelSheetName` in [Export Options](https://www.adaptabletools.com/docs/technical-reference-exporting/index.md) to change that for every Excel or Visual Excel export.

### `excelSheetName`

Worksheet name when exporting to Excel

```ts
excelSheetName?: string | ((excelSheetNameContext: BaseExportContext) => string);
```

The function form receives [`BaseExportContext`](https://www.adaptabletools.com/docs/reference/baseexportcontext.md) so you can vary the sheet name by report or destination.

To change workbook file name, font, or other AG Grid Excel export params for a **single** API export, use `exportConfig.exportParams` on [exportReport](https://www.adaptabletools.com/docs/handbook-exporting-configuring/index.md#advanced-exporting) instead — for example `sheetName` on [AG Grid `ExcelExportParams`](https://www.ag-grid.com/javascript-data-grid/excel-export-api/).

```ts {4}
const adaptableOptions: AdaptableOptions = {
  exportOptions: {
    excelSheetName: (context: BaseExportContext) =>
      `${context.reportName} — ${context.reportFormat}`,
  },
};
```

## Notes

[Notes](https://www.adaptabletools.com/docs/handbook-notes/index.md) are exported as cell comments, including the Note's Author.

Excel shows the same indicator for every comment, so the [Note Type](https://www.adaptabletools.com/docs/handbook-notes-configuring/index.md) cannot be shown as a colour. Instead, when any Note has a type other than the default (`noteOptions.defaultNoteType`, `Info` unless changed), each exported comment starts with its type, e.g. `Warning: Check this price`.

If all Notes have the default type, the comment contains only the Note text.

## Excel Column Types

AdapTable allows developers to define in AG Grid columns which have a particular Excel Data Type.

This ensures that Excel will render that column using the correct type.

- This only affects the behaviour in Excel for exported data
- There is no impact on how AdapTable (or AG Grid) renders the Column or formats the Cells

There are 4 types of Column Data Types supported:

- `numberExcelType`
- `stringExcelType`
- `dateExcelType`
- `booleanExcelType`

These are configured using the `cellClass` property in the `ColDef` object (which is an array), e.g:

```
cellClass: ["stringExcelType"]
```

This can very occasionally result in the column losing any formatting which it has been given in AdapTable

**Example: Excel Column Type**

Exporting to Excel using Excel Column Types (to preserve formatting)

- In this example we configure 2 Columns with Excel Column Types:
  - `Rating` - has a `stringExcelType`
  - `Price` - has a `numberExcelType`

- Export to Excel and note that the `Price` column is of type Number and the `Rating` column shows all values as strings

Demo project (Vanilla); the files without a marker are shown below:

```text
src/
  adaptableOptions.ts
  agGridModules.ts     [template]
  columnDefs.ts
  gridOptions.ts
  index.ts             [template]
  onAdaptableReady.ts  [template]
  rowData.ts
  styles.css           [template]
index.html             [template]
package.json           [template]
tsconfig.json          [template]
```

Files marked `[template]` are the same in every demo; see the [demo template](https://www.adaptabletools.com/llms/demo-template.md#vanilla).

**`src/adaptableOptions.ts`**

```ts
import {AdaptableOptions} from '@adaptabletools/adaptable';
import {Car} from './rowData';

export const adaptableOptions: AdaptableOptions<Car> = {
  primaryKey: 'model',
  adaptableId: 'Excel Column Types',
  initialState: {
    Theme: {CurrentTheme: 'dark'},
    Dashboard: {
      PinnedToolbars: ['Export'],
    },
    Layout: {
      CurrentLayout: 'Standard Layout',
      Layouts: [
        {
          TableColumns: [
            'make',
            'model',
            'made',
            'available',
            'pricePerMile',
            'rating',
          ],
          Name: 'Standard Layout',
          AutoSizeColumns: true,
        },
      ],
    },
  },
};
```

**`src/gridOptions.ts`**

```ts
import {GridOptions, themeBalham} from 'ag-grid-enterprise';

import {columnDefs} from './columnDefs';
import {rowData, Car} from './rowData';

export const gridOptions: GridOptions<Car> = {
  theme: themeBalham,
  defaultColDef: {
    resizable: true,
    sortable: true,
    editable: true,
    filter: true,
    floatingFilter: true,
  },
  columnDefs: columnDefs,
  rowData: rowData.map(data => {
    return {
      ...data,
      made: data.made.toISOString() as any,
    };
  }),
  sideBar: true,
  suppressMenuHide: true,
  cellSelection: true,
  statusBar: {
    statusPanels: [
      {statusPanel: 'agTotalRowCountComponent', align: 'left'},
      {statusPanel: 'agFilteredRowCountComponent'},
      {
        key: 'Center Panel',
        statusPanel: 'AdaptableStatusPanel',
        align: 'center',
      },
    ],
  },
};
```

**`src/columnDefs.ts`**

```ts
import {ColDef} from 'ag-grid-enterprise';
import {Car} from './rowData';

export const columnDefs: ColDef<Car>[] = [
  {
    headerName: 'Make',
    field: 'make',
    filter: true,
    editable: false,
    enableRowGroup: true,
    enablePivot: true,
    cellDataType: 'text',
  },
  {
    headerName: 'Model',
    field: 'model',
    filter: true,
    editable: false,
    cellDataType: 'text',
  },
  {
    headerName: 'Price',
    field: 'pricePerMile',
    filter: true,
    editable: false,
    cellDataType: 'number',
    cellClass: ['numberExcelType'],
  },
  {
    headerName: 'Made',
    field: 'made',
    //  valueGetter: params => {
    //   return params.data?.made?.toISOString();
    // },
    filter: true,
    editable: false,
    cellDataType: 'date',
    cellClass: ['dateExcelType'],
  },
  {
    headerName: 'Available',
    field: 'available',
    filter: true,
    editable: true,
    cellDataType: 'boolean',
  },
  {
    headerName: 'Rating',
    field: 'rating',
    editable: true,
    sortable: true,
    cellDataType: 'text',
    cellClass: ['stringExcelType'],
    filter: true,
    resizable: true,
  },
];
```

**`src/rowData.ts`**

```ts
export interface Car {
  make: string;
  model: string;
  made: Date;
  available: boolean;
  pricePerMile: number;
  rating: string;
}

export const rowData: Car[] = [
  {
    make: 'Toyota',
    model: 'Celica',
    made: new Date(2017, 11, 4),
    available: true,
    pricePerMile: 21.345676,
    rating: '001',
  },
  {
    make: 'Ford',
    model: 'Focus',
    made: new Date(2017, 3, 3),
    available: false,
    pricePerMile: 31.2432432423,
    rating: 'A3',
  },
  {
    make: 'Toyota',
    model: 'Yaris',
    made: new Date(2013, 1, 15),
    available: true,
    pricePerMile: 29.32432423,
    rating: '003',
  },
  {
    make: 'Toyota',
    model: 'Corolla',
    made: new Date(2017, 6, 9),
    available: false,
    pricePerMile: 32.9032523473287,
    rating: '005',
  },
  {
    make: 'Ford',
    model: 'Mondeo',
    made: new Date(2009, 10, 2),
    available: true,
    pricePerMile: 28.247893473289,
    rating: 'A2',
  },
  {
    make: 'Ford',
    model: 'Fiesta',
    made: new Date(2018, 8, 12),
    available: false,
    pricePerMile: 34.0001,
    rating: 'A5',
  },
  {
    make: 'Porsche',
    model: 'Boxter',
    made: new Date(2016, 1, 28),
    available: true,
    pricePerMile: 32.29580292,
    rating: '004',
  },
  {
    make: 'Ford',
    model: 'Galaxy',
    made: new Date(2015, 4, 14),
    available: false,
    pricePerMile: 29.29432404,
    rating: 'A2',
  },

  {
    make: 'Porsche',
    model: 'Mission',
    made: new Date(2008, 10, 7),
    available: false,
    pricePerMile: 35.7822957,
    rating: '005',
  },
  {
    make: 'Mitsubbishi',
    model: 'Outlander',
    made: new Date(2017, 11, 14),
    available: true,
    pricePerMile: 19.224309,
    rating: '004',
  },
];
```
