Skip to content

Commit 82900f8

Browse files
committed
updates & new components
1 parent 75da6d2 commit 82900f8

File tree

15 files changed

+649
-15
lines changed

15 files changed

+649
-15
lines changed

components/microsoft_excel/actions/add-a-worksheet-tablerow/add-a-worksheet-tablerow.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export default {
7171
values,
7272
} = this;
7373

74-
const response = await microsoftExcel.addRow({
74+
const response = await microsoftExcel.addTableRow({
7575
$,
7676
sheetId,
7777
tableId,
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import microsoftExcel from "../../microsoft_excel.app.mjs";
2+
3+
export default {
4+
key: "microsoft_excel-add-row",
5+
name: "Add Row",
6+
description: "Insert a new row into a specified Excel worksheet. [See the documentation](https://learn.microsoft.com/en-us/graph/api/range-insert?view=graph-rest-1.0&tabs=http)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
microsoftExcel,
11+
folderId: {
12+
propDefinition: [
13+
microsoftExcel,
14+
"folderId",
15+
],
16+
},
17+
sheetId: {
18+
propDefinition: [
19+
microsoftExcel,
20+
"sheetId",
21+
({ folderId }) => ({
22+
folderId,
23+
}),
24+
],
25+
},
26+
worksheet: {
27+
propDefinition: [
28+
microsoftExcel,
29+
"worksheet",
30+
({ sheetId }) => ({
31+
sheetId,
32+
}),
33+
],
34+
},
35+
values: {
36+
type: "string[]",
37+
label: "Values",
38+
description: "An array of values for the new row. Each item in the array represents one cell. E.g. `[1, 2, 3]`",
39+
},
40+
},
41+
async run({ $ }) {
42+
const { address } = await this.microsoftExcel.getUsedRange({
43+
$,
44+
sheetId: this.sheetId,
45+
worksheet: this.worksheet,
46+
});
47+
48+
// get next row range
49+
const match = address.match(/^(.+!)?([A-Z]+)(\d+):([A-Z]+)(\d+)$/);
50+
const [
51+
, sheet = "",
52+
colStart,
53+
/* eslint-disable no-unused-vars */
54+
rowStart,
55+
colEnd,
56+
] = match;
57+
const nextRow = parseInt(match[5], 10) + 1;
58+
const range = `${sheet}${colStart}${nextRow}:${colEnd}${nextRow}`;
59+
60+
// insert range
61+
await this.microsoftExcel.insertRange({
62+
$,
63+
sheetId: this.sheetId,
64+
worksheet: this.worksheet,
65+
range,
66+
data: {
67+
shift: "Down",
68+
},
69+
});
70+
71+
// update range
72+
const response = await this.microsoftExcel.updateRange({
73+
$,
74+
sheetId: this.sheetId,
75+
worksheet: this.worksheet,
76+
range,
77+
data: {
78+
values: [
79+
this.values,
80+
],
81+
},
82+
});
83+
84+
$.export("$summary", "Successfully added new row");
85+
return response;
86+
},
87+
};
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import microsoftExcel from "../../microsoft_excel.app.mjs";
2+
3+
export default {
4+
key: "microsoft_excel-find-row",
5+
name: "Find Row",
6+
description: "Find a row by column and value in an Excel worksheet. [See the documentation](https://learn.microsoft.com/en-us/graph/api/range-get?view=graph-rest-1.0&tabs=http)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
microsoftExcel,
11+
folderId: {
12+
propDefinition: [
13+
microsoftExcel,
14+
"folderId",
15+
],
16+
},
17+
sheetId: {
18+
propDefinition: [
19+
microsoftExcel,
20+
"sheetId",
21+
({ folderId }) => ({
22+
folderId,
23+
}),
24+
],
25+
},
26+
worksheet: {
27+
propDefinition: [
28+
microsoftExcel,
29+
"worksheet",
30+
({ sheetId }) => ({
31+
sheetId,
32+
}),
33+
],
34+
},
35+
column: {
36+
type: "string[]",
37+
label: "Column",
38+
description: "The column to search. E.g. `A`",
39+
},
40+
value: {
41+
type: "string",
42+
label: "Value",
43+
description: "The value to search for. For non-string values, use a custom expression. For example: `{{ 1 }}` for the numeric value 1",
44+
},
45+
},
46+
async run({ $ }) {
47+
const {
48+
rowCount, address,
49+
} = await this.microsoftExcel.getUsedRange({
50+
$,
51+
sheetId: this.sheetId,
52+
worksheet: this.worksheet,
53+
});
54+
const lastColumn = address.match(/:([A-Z]+)\d+$/)[1];
55+
56+
const { values: rangeValues } = await this.microsoftExcel.getRange({
57+
$,
58+
sheetId: this.sheetId,
59+
worksheet: this.worksheet,
60+
range: `${this.worksheet}!${this.column}1:${this.column}${rowCount}`,
61+
});
62+
const values = rangeValues.map((v) => v[0]);
63+
const index = values.indexOf(this.value);
64+
65+
if (index === -1) {
66+
$.export("$summary", "No matching rows found");
67+
return values;
68+
}
69+
70+
const row = index + 1;
71+
const response = await this.microsoftExcel.getRange({
72+
$,
73+
sheetId: this.sheetId,
74+
worksheet: this.worksheet,
75+
range: `${this.worksheet}!A${row}:${lastColumn}${row}`,
76+
});
77+
78+
$.export("$summary", `Found value in row ${row}`);
79+
return response;
80+
},
81+
};
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import microsoftExcel from "../../microsoft_excel.app.mjs";
2+
3+
export default {
4+
key: "microsoft_excel-get-columns",
5+
name: "Get Columns",
6+
description: "Get the values of the specified columns in an Excel worksheet. [See the documentation](https://learn.microsoft.com/en-us/graph/api/range-get?view=graph-rest-1.0&tabs=http)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
microsoftExcel,
11+
folderId: {
12+
propDefinition: [
13+
microsoftExcel,
14+
"folderId",
15+
],
16+
},
17+
sheetId: {
18+
propDefinition: [
19+
microsoftExcel,
20+
"sheetId",
21+
({ folderId }) => ({
22+
folderId,
23+
}),
24+
],
25+
},
26+
worksheet: {
27+
propDefinition: [
28+
microsoftExcel,
29+
"worksheet",
30+
({ sheetId }) => ({
31+
sheetId,
32+
}),
33+
],
34+
},
35+
columns: {
36+
type: "string[]",
37+
label: "Columns",
38+
description: "An array of column labels to retrieve. E.g. [\"A\", \"C\"]",
39+
},
40+
},
41+
async run({ $ }) {
42+
const { rowCount } = await this.microsoftExcel.getUsedRange({
43+
$,
44+
sheetId: this.sheetId,
45+
worksheet: this.worksheet,
46+
});
47+
48+
const values = {};
49+
for (const column of this.columns) {
50+
const response = await this.microsoftExcel.getRange({
51+
$,
52+
sheetId: this.sheetId,
53+
worksheet: this.worksheet,
54+
range: `${this.worksheet}!${column}1:${column}${rowCount}`,
55+
});
56+
values[column] = response.values.map((v) => v[0]);
57+
}
58+
59+
$.export("$summary", "Successfully retrieved column values");
60+
61+
return values;
62+
},
63+
};
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import microsoftExcel from "../../microsoft_excel.app.mjs";
2+
import { json2csv } from "json-2-csv";
3+
4+
export default {
5+
key: "microsoft_excel-get-spreadsheet",
6+
name: "Get Spreadsheet",
7+
description: "Get the values of a specified Excel worksheet. [See the documentation](https://learn.microsoft.com/en-us/graph/api/range-get?view=graph-rest-1.0&tabs=http)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
microsoftExcel,
12+
folderId: {
13+
propDefinition: [
14+
microsoftExcel,
15+
"folderId",
16+
],
17+
},
18+
sheetId: {
19+
propDefinition: [
20+
microsoftExcel,
21+
"sheetId",
22+
({ folderId }) => ({
23+
folderId,
24+
}),
25+
],
26+
},
27+
worksheet: {
28+
propDefinition: [
29+
microsoftExcel,
30+
"worksheet",
31+
({ sheetId }) => ({
32+
sheetId,
33+
}),
34+
],
35+
},
36+
range: {
37+
type: "string",
38+
label: "Range",
39+
description: "The range within the worksheet to retrieve. E.g. `A1:C4`. If not specified, entire \"usedRange\" will be returned",
40+
optional: true,
41+
},
42+
},
43+
async run({ $ }) {
44+
const response = this.range
45+
? await this.microsoftExcel.getRange({
46+
$,
47+
sheetId: this.sheetId,
48+
worksheet: this.worksheet,
49+
range: `${this.worksheet}!${this.range}`,
50+
})
51+
: await this.microsoftExcel.getUsedRange({
52+
$,
53+
sheetId: this.sheetId,
54+
worksheet: this.worksheet,
55+
});
56+
57+
const csv = await json2csv(response.values);
58+
response.csv = csv;
59+
60+
$.export("$summary", "Successfully retrieved spreadsheet values");
61+
return response;
62+
},
63+
};
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import microsoftExcel from "../../microsoft_excel.app.mjs";
2+
3+
export default {
4+
key: "microsoft_excel-get-table-rows",
5+
name: "Get Table Rows",
6+
description: "Retrieve rows from a specified table in an Excel worksheet. [See the documentation](https://learn.microsoft.com/en-us/graph/api/tablerow-list?view=graph-rest-1.0&tabs=http)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
microsoftExcel,
11+
folderId: {
12+
propDefinition: [
13+
microsoftExcel,
14+
"folderId",
15+
],
16+
},
17+
sheetId: {
18+
propDefinition: [
19+
microsoftExcel,
20+
"sheetId",
21+
({ folderId }) => ({
22+
folderId,
23+
}),
24+
],
25+
},
26+
tableId: {
27+
propDefinition: [
28+
microsoftExcel,
29+
"tableId",
30+
({ sheetId }) => ({
31+
sheetId,
32+
}),
33+
],
34+
},
35+
},
36+
async run({ $ }) {
37+
const rows = [];
38+
const params = {
39+
$top: 100,
40+
$skip: 0,
41+
};
42+
let total;
43+
44+
do {
45+
const { value } = await this.microsoftExcel.listTableRows({
46+
$,
47+
sheetId: this.sheetId,
48+
tableId: this.tableId,
49+
params,
50+
});
51+
rows.push(...value);
52+
total = value.length;
53+
params["$skip"] += params["$top"];
54+
} while (total);
55+
56+
$.export("$summary", `Successfully retrieved ${rows.length} row${rows.length === 1
57+
? ""
58+
: "s"}`);
59+
return rows;
60+
},
61+
};

0 commit comments

Comments
 (0)