Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add update row and update column functions and fix Row values field type #10

Merged
merged 2 commits into from
Jul 26, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion excel/Ballerina.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
org= "ballerinax"
name= "microsoft.excel"
version= "1.0.1"
version= "1.0.2"
license= ["Apache-2.0"]
authors = ["Ballerina"]
keywords = ["microsoft", "excel", "workbook", "worksheet", "sheets"]
Expand Down
12 changes: 6 additions & 6 deletions excel/Package.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
Connects to Microsoft Excel from Ballerina

### Package Overview
#### Compatibility
| | Version |
|------------------------------------------------------------------------------------|-----------------------|
| Ballerina Language Version | **Swan Lake Alpha 5** |
| [Microsoft Graph API](https://docs.microsoft.com/en-us/graph/overview) Version | **v1.0** |

The `microsoft.excel` is a [Ballerina](https://ballerina.io/) connector for Microsoft Excel.

This package provides the capability to easily access Microsoft Excel.

#### Compatibility
| | Version |
|------------------------ ----------------------------------------------|-----------------------|
| Ballerina Language | **Swan Lake Alpha5** |
| [Microsoft Graph API](https://docs.microsoft.com/en-us/graph/overview) | **v1.0** |

### Report Issues

To report bugs, request new features, start new discussions, view project boards, etc., go to the [Ballerina Microsoft Excel repository](https://github.com/ballerina-platform/module-ballerinax-microsoft.excel)
Expand Down
125 changes: 92 additions & 33 deletions excel/client.bal

Large diffs are not rendered by default.

44 changes: 36 additions & 8 deletions excel/tests/test.bal
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ function testUpdateTable() {
}
}

int rowInputIndex = 0;
int rowInputIndex = 1;

@test:Config {dependsOn: [testUpdateTable]}
function testCreateRow() {
Expand All @@ -189,14 +189,28 @@ function testListRows() {
log:printInfo("excelClient -> listRows()");
Row[]|error response = excelClient->listRows(workBookId, worksheetName, tableName);
if (response is Row[]) {
int responseIndex = response[0].index;
int responseIndex = response[1].index;
test:assertEquals(responseIndex, rowInputIndex, "Found 0 rows");
} else {
test:assertFail(response.toString());
}
}

@test:Config {dependsOn: [testListRows]}
@test:Config {dependsOn: [testCreateRow]}
function testUpdateRow() {
runtime:sleep(5);
string value = "testValue";
log:printInfo("excelClient -> updateRow()");
Row|error response = excelClient->updateRow(workBookId, worksheetName, tableName, rowInputIndex, [[(), (), value]]);
if (response is Row) {
json updatedValue = response.values[0][2];
test:assertEquals(updatedValue.toString(), value, "Row is not updated");
} else {
test:assertFail(response.toString());
}
}

@test:Config {dependsOn: [testUpdateRow]}
function testDeleteRow() {
log:printInfo("excelClient -> deleteRow()");
error? response = excelClient->deleteRow(workBookId, worksheetName, tableName, rowInputIndex);
Expand All @@ -205,9 +219,9 @@ function testDeleteRow() {
}
}

int columnInputIndex = 3;
int columnInputIndex = 2;

@test:Config {dependsOn: [testUpdateTable]}
@test:Config {dependsOn: [testDeleteRow]}
function testCreateColumn() {
log:printInfo("excelClient -> createColumn()");
Column|error response = excelClient->createColumn(workBookId, worksheetName, tableName, [["a3"], ["c3"], ["aa"]],
Expand All @@ -225,14 +239,28 @@ function testListColumn() {
log:printInfo("excelClient -> listColumns()");
Column[]|error response = excelClient->listColumns(workBookId, worksheetName, tableName);
if (response is Column[]) {
int responseIndex = response[0].index;
test:assertEquals(responseIndex, rowInputIndex, "Found 0 columns");
int responseIndex = response[2].index;
test:assertEquals(responseIndex, columnInputIndex, "Found 0 columns");
} else {
test:assertFail(response.toString());
}
}

@test:Config {dependsOn: [testCreateColumn]}
function testUpdateColumn() {
runtime:sleep(5);
string value = "testName";
log:printInfo("excelClient -> updateColumn()");
Column|error response = excelClient->updateColumn(workBookId, worksheetName, tableName, columnInputIndex, [[()], [()], [value]]);
if (response is Column) {
json updatedValue = response.values[2][0];
test:assertEquals(updatedValue.toString(), value, "Column is not updated");
} else {
test:assertFail(response.toString());
}
}

@test:Config {dependsOn: [testListColumn]}
@test:Config {dependsOn: [testUpdateColumn]}
function testDeleteColumn() {
log:printInfo("excelClient -> deleteColumn()");
error? response = excelClient->deleteColumn(workBookId, worksheetName, tableName, columnInputIndex);
Expand Down
6 changes: 3 additions & 3 deletions excel/types.bal
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public type Cell record {
int rowIndex;
json text;
json valueTypes;
json values;
json[][] values;
};

# Represents the Excel application that manages the workbook.
Expand Down Expand Up @@ -128,7 +128,7 @@ public type Table record {
@display {label: "Row"}
public type Row record {
int index;
json values;
json[][] values;
};

# Chart object in a workbook.
Expand Down Expand Up @@ -168,7 +168,7 @@ public type Column record {
string id;
string name?;
int index;
json values;
json[][] values;
};

# Specifies the calculation type to use in the workbook.
Expand Down
2 changes: 1 addition & 1 deletion samples/create_column.bal
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ excel:ExcelConfiguration configuration = {
excel:Client excelClient = check new (configuration);

public function main() {
json values = [["a3"], ["c3"], ["aa"]];
json[][] values = [["a3"], ["c3"], ["aa"]];
int columnIndex = 1;

excel:Column|error response = excelClient->createColumn(workbookIdOrPath, "sheetName", "tableName", values,
Expand Down
27 changes: 27 additions & 0 deletions samples/update_column.bal
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import ballerina/log;
Chuhaa marked this conversation as resolved.
Show resolved Hide resolved
import ballerinax/microsoft.excel;

configurable string clientId = ?;
configurable string clientSecret = ?;
configurable string refreshToken = ?;
configurable string refreshUrl = ?;
configurable string workbookIdOrPath = ?;

excel:ExcelConfiguration configuration = {
authConfig: {
clientId: clientId,
clientSecret: clientSecret,
refreshToken: refreshToken,
refreshUrl: refreshUrl
}
};

excel:Client excelClient = check new (configuration);

public function main() {
excel:Column|error response = excelClient->updateColumn(workbookIdOrPath, "sheetName", "tableName", 1,
name = "columnName");
if (response is excel:Column) {
log:printInfo(response.toString());
}
}
26 changes: 26 additions & 0 deletions samples/update_row.bal
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import ballerina/log;
import ballerinax/microsoft.excel;

configurable string clientId = ?;
configurable string clientSecret = ?;
configurable string refreshToken = ?;
configurable string refreshUrl = ?;
configurable string workbookIdOrPath = ?;

excel:ExcelConfiguration configuration = {
authConfig: {
clientId: clientId,
clientSecret: clientSecret,
refreshToken: refreshToken,
refreshUrl: refreshUrl
}
};

excel:Client excelClient = check new (configuration);

public function main() {
excel:Row|error response = excelClient->updateRow(workbookIdOrPath, "sheetName", "tableName", 4, [[(), (), 8]]);
if (response is excel:Row) {
log:printInfo(response.toString());
}
}