From f17874ecd23363221c2ae8da34e1ca006165b924 Mon Sep 17 00:00:00 2001 From: AnotherTest Date: Mon, 28 Dec 2020 18:33:45 +0330 Subject: Spreadsheet: Add a 'contents' getter/setter to Position This makes it possible to change the cells' contents programmatically! --- Base/res/js/Spreadsheet/runtime.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'Base/res/js') diff --git a/Base/res/js/Spreadsheet/runtime.js b/Base/res/js/Spreadsheet/runtime.js index 5f9cac58f7..688b8b7a04 100644 --- a/Base/res/js/Spreadsheet/runtime.js +++ b/Base/res/js/Spreadsheet/runtime.js @@ -7,6 +7,16 @@ class Position { this.name = `${column}${row}`; } + get contents() { + return this.sheet.get_real_cell_contents(this.name); + } + + set contents(value) { + value = `${value}`; + this.sheet.set_real_cell_contents(this.name, value); + return value; + } + static from_name(name) { let sheet = thisSheet; let obj = sheet.parse_cell_name(name); @@ -678,8 +688,8 @@ here.__documentation = JSON.stringify({ "- `with_row(row)`: Returns a Position with its column being this object's, and its row being the provided the value.\n" + "- `with_column(column)`: Similar to `with_row()`, but changes the column instead.\n" + "- `in_sheet(the_sheet)`: Returns a Position with the same column and row as this one, but with its sheet being `the_sheet`.\n" + - "- `value()`: Returns the value at the position which it represents, in the object's sheet (current sheet by default).\n\n" + - "**NOTE**: Currently only supports single-letter column names", + "- `value()`: Returns the value at the position which it represents, in the object's sheet (current sheet by default).\n" + + "- `contents`: An accessor for the real contents of the cell (i.e. the text as typed in the cell editor)\n", examples: { "here().up().value()": "Get the value of the cell above this one", "here().up().with_column('A')": -- cgit v1.2.3