Skip to content

Commit aa811fa

Browse files
committed
updates
1 parent 2b3c47c commit aa811fa

File tree

2 files changed

+35
-9
lines changed

2 files changed

+35
-9
lines changed

components/microsoft_excel/actions/add-row/add-row.mjs

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import microsoftExcel from "../../microsoft_excel.app.mjs";
2-
import {
3-
parseObject, getColumnLetter,
4-
} from "../../common/utils.mjs";
2+
import { getColumnLetter } from "../../common/utils.mjs";
53

64
export default {
75
key: "microsoft_excel-add-row",
@@ -41,6 +39,34 @@ export default {
4139
description: "An array of values for the new row. Each item in the array represents one cell. E.g. `[1, 2, 3]`",
4240
},
4341
},
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+
},
4470
async run({ $ }) {
4571
const {
4672
address, columnCount,
@@ -53,10 +79,7 @@ export default {
5379
// get next row range
5480
const match = address.match(/^(.+!)?([A-Z]+)(\d+):([A-Z]+)(\d+)$/);
5581
const nextRow = parseInt(match[5], 10) + 1;
56-
const values = parseObject(this.values);
57-
if (values.length < columnCount) {
58-
values.length = columnCount;
59-
}
82+
const values = this.parseValues(columnCount);
6083
const colEnd = getColumnLetter(values.length);
6184
const range = `A${nextRow}:${colEnd}${nextRow}`;
6285

components/microsoft_excel/actions/find-row/find-row.mjs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export default {
4040
value: {
4141
type: "string",
4242
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",
43+
description: "The value to search for",
4444
},
4545
},
4646
async run({ $ }) {
@@ -60,7 +60,10 @@ export default {
6060
range: `${this.column}1:${this.column}${rowCount}`,
6161
});
6262
const values = rangeValues.map((v) => v[0]);
63-
const index = values.indexOf(this.value);
63+
let index = values.indexOf(this.value);
64+
if (index === -1 && !isNaN(this.value)) {
65+
index = values.indexOf(+this.value);
66+
}
6467

6568
if (index === -1) {
6669
$.export("$summary", "No matching rows found");

0 commit comments

Comments
 (0)