Ballerina connector for Microsoft Excel connects the Microsoft Graph Excel API via Ballerina. It provides the capability to perform CRUD (Create, Read, Update, and Delete) operations on Excel workbooks stored in a Microsoft OneDrive.

This module supports Microsoft Graph API v1.0 version and only allows to perform functions behalf of the currently logged in user.


Before using this connector in your Ballerina application, complete the following:

  1. Create a Microsoft Office 365 account
  2. Obtain tokens
    Follow the steps here


To use the Microsoft Excel connector in your Ballerina application, update the .bal file as follows:

Step 1: Import connector

Import the ballerinax/microsoft.excel module into the Ballerina project.

import ballerinax/microsoft.excel;

Step 2: Create a new connector instance

Create an excel:ConnectionConfig with the OAuth2 tokens obtained and initialize the connector with it.

excel:ConnectionConfig configuration = {
    auth: {
        refreshUrl: <REFRESH_URL>,
        refreshToken : <REFRESH_TOKEN>,
        clientId : <CLIENT_ID>,
        clientSecret : <CLIENT_SECRET>

excel:Client excelClient = check new (configuration);

Step 3: Invoke connector operation

  1. Now you can use the operations available within the connector. Note that they are in the form of remote operations.
    Following is an example on how to add a worksheet using the connector.

    public function main() returns error? {
        excel:Worksheet response = check excelClient->addWorksheet("workbookIdOrPath", "sheetName");
  2. Use bal run command to compile and run the Ballerina program.

You can find a list of samples here

Other versions

See more...