Skip to content

Commit cfbc427

Browse files
Microsoft Excel - Updates and New Components (#16369)
* wip * updates & new components * pnpm-lock.yaml * fix column prop * updates * pnpm-lock.yaml * pnpm-lock.yaml * Update components/microsoft_excel/sources/common/base-webhook.mjs Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * fix * updates --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent ece3898 commit cfbc427

File tree

21 files changed

+1052
-139
lines changed

21 files changed

+1052
-139
lines changed

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

+11-11
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import microsoftExcel from "../../microsoft_excel.app.mjs";
33

44
export default {
55
key: "microsoft_excel-add-a-worksheet-tablerow",
6-
name: "Add A Worksheet Tablerow",
7-
version: "0.0.4",
6+
name: "Add a Worksheet Tablerow",
7+
version: "0.0.5",
88
description: "Adds rows to the end of specific table. [See the documentation](https://learn.microsoft.com/en-us/graph/api/tablerowcollection-add?view=graph-rest-1.0&tabs=http)",
99
type: "action",
1010
props: {
@@ -15,10 +15,10 @@ export default {
1515
"folderId",
1616
],
1717
},
18-
itemId: {
18+
sheetId: {
1919
propDefinition: [
2020
microsoftExcel,
21-
"itemId",
21+
"sheetId",
2222
({ folderId }) => ({
2323
folderId,
2424
}),
@@ -29,8 +29,8 @@ export default {
2929
propDefinition: [
3030
microsoftExcel,
3131
"tableId",
32-
({ itemId }) => ({
33-
itemId,
32+
({ sheetId }) => ({
33+
sheetId,
3434
}),
3535
],
3636
hidden: true,
@@ -49,10 +49,10 @@ export default {
4949
},
5050
},
5151
async additionalProps(props) {
52-
if (this.itemId) {
52+
if (this.sheetId) {
5353
try {
5454
await this.microsoftExcel.listTables({
55-
itemId: this.itemId,
55+
sheetId: this.sheetId,
5656
});
5757
} catch {
5858
props.tableName.hidden = false;
@@ -65,15 +65,15 @@ export default {
6565
async run({ $ }) {
6666
const {
6767
microsoftExcel,
68-
itemId,
68+
sheetId,
6969
tableId,
7070
tableName,
7171
values,
7272
} = this;
7373

74-
const response = await microsoftExcel.addRow({
74+
const response = await microsoftExcel.addTableRow({
7575
$,
76-
itemId,
76+
sheetId,
7777
tableId,
7878
tableName,
7979
data: {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
import microsoftExcel from "../../microsoft_excel.app.mjs";
2+
import { getColumnLetter } from "../../common/utils.mjs";
3+
4+
export default {
5+
key: "microsoft_excel-add-row",
6+
name: "Add Row",
7+
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)",
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+
values: {
37+
type: "string[]",
38+
label: "Values",
39+
description: "An array of values for the new row. Each item in the array represents one cell. E.g. `[1, 2, 3]`",
40+
},
41+
},
42+
methods: {
43+
isArrayString(str) {
44+
return typeof str === "string" && ((str.startsWith("[") && str.endsWith("]")) || ((str.startsWith("[[") || str.startsWith("[ [")) && (str.endsWith("]]") || str.endsWith("] ]"))));
45+
},
46+
convertStringToArray(str) {
47+
const arrayString = str.match(/\[\[?(.*?)\]?\]/)[1];
48+
return arrayString.split(",");
49+
},
50+
parseValues(columnCount) {
51+
let values = this.values;
52+
if (Array.isArray(this.values)) {
53+
if (Array.isArray(this.values[0])) {
54+
values = this.values[0];
55+
} else if (this.isArrayString(this.values[0])) {
56+
values = this.convertStringToArray(this.values[0]);
57+
}
58+
} else {
59+
if (this.isArrayString(this.values)) {
60+
values = this.convertStringToArray(this.values);
61+
}
62+
}
63+
64+
if (values.length < columnCount) {
65+
values.length = columnCount;
66+
}
67+
return values;
68+
},
69+
},
70+
async run({ $ }) {
71+
const {
72+
address, columnCount,
73+
} = await this.microsoftExcel.getUsedRange({
74+
$,
75+
sheetId: this.sheetId,
76+
worksheet: this.worksheet,
77+
});
78+
79+
// get next row range
80+
const match = address.match(/^(.+!)?([A-Z]+)(\d+):([A-Z]+)(\d+)$/);
81+
const nextRow = parseInt(match[5], 10) + 1;
82+
const values = this.parseValues(columnCount);
83+
const colEnd = getColumnLetter(values.length);
84+
const range = `A${nextRow}:${colEnd}${nextRow}`;
85+
86+
// insert range
87+
await this.microsoftExcel.insertRange({
88+
$,
89+
sheetId: this.sheetId,
90+
worksheet: this.worksheet,
91+
range,
92+
data: {
93+
shift: "Down",
94+
},
95+
});
96+
97+
// update range
98+
const response = await this.microsoftExcel.updateRange({
99+
$,
100+
sheetId: this.sheetId,
101+
worksheet: this.worksheet,
102+
range,
103+
data: {
104+
values: [
105+
values,
106+
],
107+
},
108+
});
109+
110+
$.export("$summary", "Successfully added new row");
111+
return response;
112+
},
113+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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",
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.column}1:${this.column}${rowCount}`,
61+
});
62+
const values = rangeValues.map((v) => v[0]);
63+
let index = values.indexOf(this.value);
64+
if (index === -1 && !isNaN(this.value)) {
65+
index = values.indexOf(+this.value);
66+
}
67+
68+
if (index === -1) {
69+
$.export("$summary", "No matching rows found");
70+
return values;
71+
}
72+
73+
const row = index + 1;
74+
const response = await this.microsoftExcel.getRange({
75+
$,
76+
sheetId: this.sheetId,
77+
worksheet: this.worksheet,
78+
range: `A${row}:${lastColumn}${row}`,
79+
});
80+
81+
$.export("$summary", `Found value in row ${row}`);
82+
return response;
83+
},
84+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import microsoftExcel from "../../microsoft_excel.app.mjs";
2+
import { parseObject } from "../../common/utils.mjs";
3+
4+
export default {
5+
key: "microsoft_excel-get-columns",
6+
name: "Get Columns",
7+
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)",
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+
columns: {
37+
type: "string[]",
38+
label: "Columns",
39+
description: "An array of column labels to retrieve. E.g. [\"A\", \"C\"]",
40+
},
41+
},
42+
async run({ $ }) {
43+
const { rowCount } = await this.microsoftExcel.getUsedRange({
44+
$,
45+
sheetId: this.sheetId,
46+
worksheet: this.worksheet,
47+
});
48+
49+
const values = {};
50+
const columns = parseObject(this.columns);
51+
for (const column of columns) {
52+
const response = await this.microsoftExcel.getRange({
53+
$,
54+
sheetId: this.sheetId,
55+
worksheet: this.worksheet,
56+
range: `${column}1:${column}${rowCount}`,
57+
});
58+
values[column] = response.values.map((v) => v[0]);
59+
}
60+
61+
$.export("$summary", "Successfully retrieved column values");
62+
63+
return values;
64+
},
65+
};
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.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+
};

0 commit comments

Comments
 (0)