---
title: "Excel Export - Page Setup"
enterprise: true
framework: javascript
version: "36.1.0"
---

# Excel Export - Page Setup

Excel Export allows you to configure the page settings for the exported Excel file.

## Page Setup

You can customise the Excel export page settings such as **page size**, **orientation**, and **margin**, using the `pageSetup` and `margins` configs of the [Excel Export Params](https://www.ag-grid.com/javascript-data-grid/excel-export-api/#excelexportparams). These settings are visible when printing the exported Excel file or exporting to PDF.

```js
const gridOptions = {
    defaultExcelExportParams: {
        pageSetup: {
            orientation: 'Landscape',
            pageSize: 'A3'
        },
        margins: {
            top: 1,
            right: 1,
            bottom: 1,
            left: 1,
            header: 0.5,
            footer: 0.5,
        }
    },

    // other grid options ...
}
```

> **Warning**
>
> The value of the margins must be provided in `inches`.

Note the following:

- The sample below allow you to configure the page size, orientation and margin values.
- Page size and orientation are stored in the `pageSetup` object.
- Margin values are stored in the `margins` object.

#### Excel Export - Page Setup

```ts
import {
  ClientSideRowModelModule,
  GridApi,
  GridOptions,
  ModuleRegistry,
  NumberFilterModule,
  TextFilterModule,
  createGrid,
  enableDevValidations,
} from "ag-grid-community";
import {
  ColumnMenuModule,
  ContextMenuModule,
  ExcelExportModule,
} from "ag-grid-enterprise";
import { IOlympicData } from "./interfaces";

// Enable extended validations only for development
if (process.env.NODE_ENV !== "production") {
  enableDevValidations();
}

ModuleRegistry.registerModules([
  TextFilterModule,
  NumberFilterModule,
  ClientSideRowModelModule,
  ExcelExportModule,
  ColumnMenuModule,
  ContextMenuModule,
]);

let gridApi: GridApi<IOlympicData>;

const gridOptions: GridOptions<IOlympicData> = {
  columnDefs: [
    { field: "athlete", minWidth: 200 },
    { field: "country", minWidth: 200 },
    { field: "sport", minWidth: 150 },
    { field: "gold" },
    { field: "silver" },
    { field: "bronze" },
    { field: "total" },
  ],

  defaultColDef: {
    filter: true,
    minWidth: 100,
    flex: 1,
  },

  popupParent: document.body,
};

function getNumber(id: string) {
  const el = document.querySelector(id) as any;

  if (!el || isNaN(el.value)) {
    return 0;
  }

  return parseFloat(el.value);
}

function getValue(id: string) {
  return (document.querySelector(id) as any).value;
}

function getSheetConfig() {
  return {
    pageSetup: {
      orientation: getValue("#pageOrientation"),
      pageSize: getValue("#pageSize"),
    },
    margins: {
      top: getNumber("#top"),
      right: getNumber("#right"),
      bottom: getNumber("#bottom"),
      left: getNumber("#left"),
      header: getNumber("#header"),
      footer: getNumber("#footer"),
    },
  };
}

function onFormSubmit(e: any) {
  e.preventDefault();
  const { pageSetup, margins } = getSheetConfig();
  gridApi!.exportDataAsExcel({ pageSetup, margins });
}

const gridDiv = document.querySelector<HTMLElement>("#myGrid");
const form = document.querySelector<HTMLFormElement>("form");

form?.addEventListener("submit", (e) => onFormSubmit(e));

if (gridDiv) {
  gridApi = createGrid(gridDiv, gridOptions);
  fetch("https://www.ag-grid.com/example-assets/small-olympic-winners.json")
    .then((response) => response.json())
    .then((data) =>
      gridApi!.setGridOption(
        "rowData",
        data.filter((rec: any) => rec.country != null),
      ),
    );
}
```

[Live example: Excel Export - Page Setup](https://www.ag-grid.com/examples/excel-export-page-setup/excel-export-page-setup/typescript)

## Interfaces

### ExcelExportParams

```ts
interface ExcelExportParams {
    // ...
    margins?: ExcelSheetMargin;
    pageSetup?: ExcelSheetPageSetup
}
```

### ExcelSheetMargin

Properties available on the `ExcelSheetMargin` interface.

| Property | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `top` | `number` |  | `0.75` | The sheet top margin. |
| `right` | `number` |  | `0.7` | The sheet right margin. |
| `bottom` | `number` |  | `0.75` | The sheet bottom margin. |
| `left` | `number` |  | `0.7` | The sheet left margin. |
| `header` | `number` |  | `0.3` | The sheet header margin. |
| `footer` | `number` |  | `0.3` | The sheet footer margin. |

### ExcelSheetPageSetup

Properties available on the `ExcelSheetPageSetup` interface.

| Property | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `orientation` | `'Portrait' \| 'Landscape'` |  | `'Portrait'` | Use this property to change the print orientation. |
| `pageSize` | `\| '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'` |  | `'Letter'` | Use this property to set the sheet size. |
