# API

**Kind**: interface | **Module**: [Excel](https://docs.interop.io/adapters/reference/javascript/excel/index.md) | **Access**: `io.excel`

**Source**: https://docs.interop.io/adapters/reference/javascript/excel/api/index.html

Excel API.

## Properties

- **`addinStatus`** (`boolean`, required)
  Flag indicating the status of the Excel Adapter.
  If `true`, the Excel Adapter is available and you can use the Excel API.
- **`sheets`** (`Sheet[]`, required)
  Retrieves all Excel worksheets currently tracked by the Excel Adapter, including worksheets opened by the app and worksheets discovered in Excel.

## Methods

### getWorkbooks

Retrieves all open workbooks in Excel.

```ts
() => Promise<Book[]>
```

**Returns**: `Promise<Book[]>`

### getWorksheets

Retrieves all worksheets from all open workbooks in Excel.

```ts
() => Promise<Sheet[]>
```

**Returns**: `Promise<Sheet[]>`

### onAddinStatusChanged

Notifies when the Excel Adapter status has changed. Returns an unsubscribe function.

```ts
(callback: (connected: boolean) => void) => UnsubscribeFunction
```

**Parameters**

- **`callback`** (`(connected: boolean) => void`, required)
  Callback function for handling the event.
  Receives as an argument a Boolean value indicating the status of the Excel Adapter.

**Returns**: `UnsubscribeFunction`

**Example**

```ts
```javascript
office.excel.onAddinStatusChanged((connected) => {
    if (connected) {
        console.log("Excel is available");
    } else {
        console.log("Excel is closed or addin is not working");
    }
});
```
```

### onNewWorksheet

Notifies when a new worksheet is discovered in Excel that wasn't previously opened by the app. Returns an unsubscribe function.

```ts
(callback: (sheet: Sheet) => void) => UnsubscribeFunction
```

**Parameters**

- **`callback`** (`(sheet: Sheet) => void`, required)
  Callback function for handling the event. Receives the new worksheet as an argument.

**Returns**: `UnsubscribeFunction`

### openSheet

Opens a new Excel worksheet.

```ts
(sheetData: OpenSheetConfig) => Promise<Sheet>
```

**Parameters**

- **`sheetData`** (`OpenSheetConfig`, required)
  Configuration for opening the Excel worksheet.

**Returns**: `Promise<Sheet>`

**Example**

```ts
```javascript
const options = {
    columnConfig: [
        { header: "Symbol", fieldName: "symbol" },
        { header: "Price", fieldName: "price" }
    ],
    data: [
        { price: 100, symbol: "AAPL" },
        { price: 200, symbol: "GOOG" }
    ],
    options: {
        workbook: "MyWorkbook",
        worksheet: "MyWorksheet",
    }
};

const mySheet = await office.excel.openSheet(options);
console.log(mySheet);
```
```

### ready

Resolves when the Excel Adapter has finished registering its internal Interop methods
that provide the Excel API functionality. Resolves with the Excel API object.

```ts
() => Promise<API>
```

**Returns**: `Promise<API>`

## Related types

- [Book](https://docs.interop.io/adapters/reference/javascript/excel/book/index.md)
- [OpenSheetConfig](https://docs.interop.io/adapters/reference/javascript/excel/opensheetconfig/index.md)
- [Sheet](https://docs.interop.io/adapters/reference/javascript/excel/sheet/index.md)
