Getting Started - Excel

Excel Configuration

The following steps are necessary to include the Excel Service with your OpenFin Application.

Manifest declaration

Declare the Excel Service by including the following declaration in your application manifest:

"services":
[
   { "name": "excel" }
]

Include the Excel API client

The Excel API client is only provided as a script tag. Include the following script tag on each page that requires API access:

<script src="https://openfin.github.io/excel-api-example/client/fin.desktop.Excel.js"></script>

Wait for Excel Service

During startup, an application utilizing the Excel Service should ensure the service is running and ready to receive commands by invoking:

await fin.desktop.ExcelService.init();

📘

Note

OpenFin advises Application Providers to place this call before any calls on the fin.desktop.Excel namespace.

Excel Service Usage

We cover 2 fundamental functions below, for a complete list of functions click the button below (note, the link opens in a new window)

Excel API Docs

Read/Write with Excel Worksheets

Post connection between Excel and an OpenFin application, pushing data to a spreadsheet and reading back the calculated values can be performed as follows:

var sheet1 = fin.desktop.Excel.getWorkbookByName('Book1').getWorksheetByName('Sheet1');

// A little fun with Pythagorean triples:
sheet1.setCells([
  ["A", "B", "C"],
  [  3,   4, "=SQRT(A2^2+B2^2)"],
  [  5,  12, "=SQRT(A3^2+B3^2)"],
  [  8,  15, "=SQRT(A4^2+B4^2)"],
], "A1");

// Write the computed values to console:
sheet1.getCells("C2", 0, 2, cells => {
  console.log(cells[0][0].value);
  console.log(cells[1][0].value);
  console.log(cells[2][0].value);
});

Subscribing to events

Monitoring various applications, workbooks, and sheet events are done via the addEventListener functions on their respective objects.

sheet1.getCells("C2", 0, 2, cells => {
  var lastValue = cells[0][0].value;
  
  fin.desktop.Excel.addEventListener('afterCalculation', () => {
    sheet1.getCells("C2", 0, 2, cells => {
      if(cells[0][0].value !== lastValue) {
        console.log('Value Changed!');
      }

      lastValue = cells[0][0].value;
    });
  });
})

Run Locally

For development purposes you may wish to clone our Excel repository and run on a local computer. The Excel Add-In is only compatible with Excel for Windows.

📘

Prerequisites

Node and NPM must be installed in order to clone and run the Excel Service locally.

Clone the repository and in the Command Prompt, navigate into the excel-api-example directory created.

In the Command Prompt run:

npm install

Once the Node packages have installed, it is now possible to make modifications to files in the excel-api-example\src folder and rebuild the project by running:

npm run webpack

After rebuilding, start the application by running:

npm start

Did this page help you?