summaryrefslogtreecommitdiff
path: root/Base
diff options
context:
space:
mode:
Diffstat (limited to 'Base')
-rw-r--r--Base/res/js/Spreadsheet/runtime.js25
1 files changed, 19 insertions, 6 deletions
diff --git a/Base/res/js/Spreadsheet/runtime.js b/Base/res/js/Spreadsheet/runtime.js
index ab9ab9f05d..1519c879c6 100644
--- a/Base/res/js/Spreadsheet/runtime.js
+++ b/Base/res/js/Spreadsheet/runtime.js
@@ -1,10 +1,8 @@
-const sheet = this;
-
function range(start, end, columnStep, rowStep) {
columnStep = integer(columnStep ?? 1);
rowStep = integer(rowStep ?? 1);
- start = sheet.parse_cell_name(start) ?? { column: "A", row: 0 };
- end = sheet.parse_cell_name(end) ?? start;
+ start = parse_cell_name(start) ?? { column: "A", row: 0 };
+ end = parse_cell_name(end) ?? start;
if (end.column.length > 1 || start.column.length > 1)
throw new TypeError("Only single-letter column names are allowed (TODO)");
@@ -58,7 +56,7 @@ function select(criteria, t, f) {
function sumIf(condition, cells) {
let sum = null;
for (let name of cells) {
- let cell = sheet[name];
+ let cell = thisSheet[name];
if (condition(cell)) sum = sum === null ? cell : sum + cell;
}
return sum;
@@ -67,7 +65,7 @@ function sumIf(condition, cells) {
function countIf(condition, cells) {
let count = 0;
for (let name of cells) {
- let cell = sheet[name];
+ let cell = thisSheet[name];
if (condition(cell)) count++;
}
return count;
@@ -89,6 +87,10 @@ function integer(value) {
return value | 0;
}
+function sheet(name) {
+ return workbook.sheet(name);
+}
+
// Cheat the system and add documentation
range.__documentation = JSON.stringify({
name: "range",
@@ -172,3 +174,14 @@ integer.__documentation = JSON.stringify({
"A1 = integer(A0)": "Sets the value of the cell A1 to the integer value of the cell A0",
},
});
+
+sheet.__documentation = JSON.stringify({
+ name: "sheet",
+ argc: 1,
+ argnames: ["name or index"],
+ doc: "Returns a reference to another sheet, identified by _name_ or _index_",
+ examples: {
+ "sheet('Sheet 1').A4": "Read the value of the cell A4 in a sheet named 'Sheet 1'",
+ "sheet(0).A0 = 123": "Set the value of the cell A0 in the first sheet to 123",
+ },
+});