Skip to content

Microsoft Excel - Updates and New Components #16369

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

Merged
merged 10 commits into from
Apr 23, 2025
Merged
Show file tree
Hide file tree
Changes from 7 commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import microsoftExcel from "../../microsoft_excel.app.mjs";

export default {
key: "microsoft_excel-add-a-worksheet-tablerow",
name: "Add A Worksheet Tablerow",
version: "0.0.4",
name: "Add a Worksheet Tablerow",
version: "0.0.5",
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)",
type: "action",
props: {
Expand All @@ -15,10 +15,10 @@ export default {
"folderId",
],
},
itemId: {
sheetId: {
propDefinition: [
microsoftExcel,
"itemId",
"sheetId",
({ folderId }) => ({
folderId,
}),
Expand All @@ -29,8 +29,8 @@ export default {
propDefinition: [
microsoftExcel,
"tableId",
({ itemId }) => ({
itemId,
({ sheetId }) => ({
sheetId,
}),
],
hidden: true,
Expand All @@ -49,10 +49,10 @@ export default {
},
},
async additionalProps(props) {
if (this.itemId) {
if (this.sheetId) {
try {
await this.microsoftExcel.listTables({
itemId: this.itemId,
sheetId: this.sheetId,
});
} catch {
props.tableName.hidden = false;
Expand All @@ -65,15 +65,15 @@ export default {
async run({ $ }) {
const {
microsoftExcel,
itemId,
sheetId,
tableId,
tableName,
values,
} = this;

const response = await microsoftExcel.addRow({
const response = await microsoftExcel.addTableRow({
$,
itemId,
sheetId,
tableId,
tableName,
data: {
Expand Down
90 changes: 90 additions & 0 deletions components/microsoft_excel/actions/add-row/add-row.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import microsoftExcel from "../../microsoft_excel.app.mjs";
import {
parseObject, getColumnLetter,
} from "../../common/utils.mjs";

export default {
key: "microsoft_excel-add-row",
name: "Add Row",
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)",
version: "0.0.1",
type: "action",
props: {
microsoftExcel,
folderId: {
propDefinition: [
microsoftExcel,
"folderId",
],
},
sheetId: {
propDefinition: [
microsoftExcel,
"sheetId",
({ folderId }) => ({
folderId,
}),
],
},
worksheet: {
propDefinition: [
microsoftExcel,
"worksheet",
({ sheetId }) => ({
sheetId,
}),
],
},
values: {
type: "string[]",
label: "Values",
description: "An array of values for the new row. Each item in the array represents one cell. E.g. `[1, 2, 3]`",
},
},
async run({ $ }) {
const {
address, columnCount,
} = await this.microsoftExcel.getUsedRange({
$,
sheetId: this.sheetId,
worksheet: this.worksheet,
});

// get next row range
const match = address.match(/^(.+!)?([A-Z]+)(\d+):([A-Z]+)(\d+)$/);
const nextRow = parseInt(match[5], 10) + 1;
const values = parseObject(this.values);
if (values.length < columnCount) {
values.length = columnCount;
}
const colEnd = getColumnLetter(values.length);
const range = `A${nextRow}:${colEnd}${nextRow}`;

// insert range
await this.microsoftExcel.insertRange({
$,
sheetId: this.sheetId,
worksheet: this.worksheet,
range,
data: {
shift: "Down",
},
});

// update range
const response = await this.microsoftExcel.updateRange({
$,
sheetId: this.sheetId,
worksheet: this.worksheet,
range,
data: {
values: [
values,
],
},
});

$.export("$summary", "Successfully added new row");
return response;
},
};
81 changes: 81 additions & 0 deletions components/microsoft_excel/actions/find-row/find-row.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import microsoftExcel from "../../microsoft_excel.app.mjs";

export default {
key: "microsoft_excel-find-row",
name: "Find Row",
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)",
version: "0.0.1",
type: "action",
props: {
microsoftExcel,
folderId: {
propDefinition: [
microsoftExcel,
"folderId",
],
},
sheetId: {
propDefinition: [
microsoftExcel,
"sheetId",
({ folderId }) => ({
folderId,
}),
],
},
worksheet: {
propDefinition: [
microsoftExcel,
"worksheet",
({ sheetId }) => ({
sheetId,
}),
],
},
column: {
type: "string",
label: "Column",
description: "The column to search. E.g. `A`",
},
value: {
type: "string",
label: "Value",
description: "The value to search for. For non-string values, use a custom expression. For example: `{{ 1 }}` for the numeric value 1",
},
},
async run({ $ }) {
const {
rowCount, address,
} = await this.microsoftExcel.getUsedRange({
$,
sheetId: this.sheetId,
worksheet: this.worksheet,
});
const lastColumn = address.match(/:([A-Z]+)\d+$/)[1];

const { values: rangeValues } = await this.microsoftExcel.getRange({
$,
sheetId: this.sheetId,
worksheet: this.worksheet,
range: `${this.column}1:${this.column}${rowCount}`,
});
const values = rangeValues.map((v) => v[0]);
const index = values.indexOf(this.value);

if (index === -1) {
$.export("$summary", "No matching rows found");
return values;
}

const row = index + 1;
const response = await this.microsoftExcel.getRange({
$,
sheetId: this.sheetId,
worksheet: this.worksheet,
range: `A${row}:${lastColumn}${row}`,
});

$.export("$summary", `Found value in row ${row}`);
return response;
},
};
65 changes: 65 additions & 0 deletions components/microsoft_excel/actions/get-columns/get-columns.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import microsoftExcel from "../../microsoft_excel.app.mjs";
import { parseObject } from "../../common/utils.mjs";

export default {
key: "microsoft_excel-get-columns",
name: "Get Columns",
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)",
version: "0.0.1",
type: "action",
props: {
microsoftExcel,
folderId: {
propDefinition: [
microsoftExcel,
"folderId",
],
},
sheetId: {
propDefinition: [
microsoftExcel,
"sheetId",
({ folderId }) => ({
folderId,
}),
],
},
worksheet: {
propDefinition: [
microsoftExcel,
"worksheet",
({ sheetId }) => ({
sheetId,
}),
],
},
columns: {
type: "string[]",
label: "Columns",
description: "An array of column labels to retrieve. E.g. [\"A\", \"C\"]",
},
},
async run({ $ }) {
const { rowCount } = await this.microsoftExcel.getUsedRange({
$,
sheetId: this.sheetId,
worksheet: this.worksheet,
});

const values = {};
const columns = parseObject(this.columns);
for (const column of columns) {
const response = await this.microsoftExcel.getRange({
$,
sheetId: this.sheetId,
worksheet: this.worksheet,
range: `${column}1:${column}${rowCount}`,
});
values[column] = response.values.map((v) => v[0]);
}

$.export("$summary", "Successfully retrieved column values");

return values;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import microsoftExcel from "../../microsoft_excel.app.mjs";
import { json2csv } from "json-2-csv";

export default {
key: "microsoft_excel-get-spreadsheet",
name: "Get Spreadsheet",
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)",
version: "0.0.1",
type: "action",
props: {
microsoftExcel,
folderId: {
propDefinition: [
microsoftExcel,
"folderId",
],
},
sheetId: {
propDefinition: [
microsoftExcel,
"sheetId",
({ folderId }) => ({
folderId,
}),
],
},
worksheet: {
propDefinition: [
microsoftExcel,
"worksheet",
({ sheetId }) => ({
sheetId,
}),
],
},
range: {
type: "string",
label: "Range",
description: "The range within the worksheet to retrieve. E.g. `A1:C4`. If not specified, entire \"usedRange\" will be returned",
optional: true,
},
},
async run({ $ }) {
const response = this.range
? await this.microsoftExcel.getRange({
$,
sheetId: this.sheetId,
worksheet: this.worksheet,
range: `${this.range}`,
})
: await this.microsoftExcel.getUsedRange({
$,
sheetId: this.sheetId,
worksheet: this.worksheet,
});

const csv = await json2csv(response.values);
response.csv = csv;

$.export("$summary", "Successfully retrieved spreadsheet values");
return response;
},
};
Loading
Loading