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:
- Create a Microsoft Office 365 account
- Obtain tokens
Follow the steps here
To use the Microsoft Excel connector in your Ballerina application, update the .bal file as follows:
Import the ballerinax/microsoft.excel
module into the Ballerina project.
import ballerinax/microsoft.excel;
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);
-
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"); }
-
Use
bal run
command to compile and run the Ballerina program.