diff options
author | AnotherTest <ali.mpfard@gmail.com> | 2020-08-26 07:32:38 +0430 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-08-27 10:27:20 +0200 |
commit | cb7fe4fe7c50dc3c9da8f129aa60c74e93ef1304 (patch) | |
tree | e22ee7d77c29e0f412c43555a422b438de9d5806 /Base/res/js/Spreadsheet | |
parent | e1f5f709eeecdd9aea0714b924f6bbb2096abdbf (diff) | |
download | serenity-cb7fe4fe7c50dc3c9da8f129aa60c74e93ef1304.zip |
Spreadsheet: Add support for multiple sheets
This also refactors the js integration stuff to allow sheets to
reference each other safely.
Diffstat (limited to 'Base/res/js/Spreadsheet')
-rw-r--r-- | Base/res/js/Spreadsheet/runtime.js | 25 |
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", + }, +}); |