Class: Rbxl::EditableCell
- Inherits:
-
Object
- Object
- Rbxl::EditableCell
- Defined in:
- lib/rbxl/editable_cell.rb
Overview
A view onto a single <c> element inside an EditableWorksheet.
Cells are not stored — each call to Rbxl::EditableWorksheet#cell returns a fresh EditableCell that resolves the underlying <c> node on demand. Reads decode the current XML; writes mutate the worksheet’s DOM and mark the sheet dirty so the next Rbxl::EditableWorkbook#save re-serializes it.
Type matrix on write
-
nil— clears the cell’s value (children +tattribute removed), leaving an empty <c> that retains itss(style index) -
true/false— boolean cell (+t=“b”+) -
Integer/Float— number cell (notattribute) -
String— inline string cell (+t=“inlineStr”+);xl/sharedStrings.xmlis never mutated, so this round-trips deterministically without a second pass over the SST -
Date/Time/DateTime— raises EditableCellTypeError; convert to a numeric serial yourself if you need a date cell. Date support is intentionally deferred so 1.4.0 doesn’t ship a half-baked numFmt write
When overwriting an existing cell, the s (style index) attribute is preserved so template formatting (number format, font, fill, alignment) carries through to the new value. Any <f> (formula) and cached <v> are dropped — assigning a value means the cell is no longer a formula.
Constant Summary collapse
- MAIN_NS =
Namespace for the main SpreadsheetML schema.
"http://schemas.openxmlformats.org/spreadsheetml/2006/main".freeze
Instance Attribute Summary collapse
-
#coordinate ⇒ String
readonly
Excel-style coordinate, e.g.
Instance Method Summary collapse
-
#initialize(worksheet:, coordinate:) ⇒ EditableCell
constructor
private
Construct via Rbxl::EditableWorksheet#cell; not for direct use.
-
#value ⇒ String, ...
Decodes the current value of the cell.
-
#value=(new_value) ⇒ Object
Sets the cell’s value.
Constructor Details
#initialize(worksheet:, coordinate:) ⇒ EditableCell
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Construct via Rbxl::EditableWorksheet#cell; not for direct use.
39 40 41 42 |
# File 'lib/rbxl/editable_cell.rb', line 39 def initialize(worksheet:, coordinate:) @worksheet = worksheet @coordinate = coordinate end |
Instance Attribute Details
#coordinate ⇒ String (readonly)
Returns Excel-style coordinate, e.g. “B5”.
32 33 34 |
# File 'lib/rbxl/editable_cell.rb', line 32 def coordinate @coordinate end |
Instance Method Details
#value ⇒ String, ...
Decodes the current value of the cell.
52 53 54 55 56 57 |
# File 'lib/rbxl/editable_cell.rb', line 52 def value node = @worksheet.find_or_create_cell_node(@coordinate, create: false) return nil unless node decode(node) end |
#value=(new_value) ⇒ Object
Sets the cell’s value. See the class-level “Type matrix on write” documentation for accepted Ruby types and how each is serialized.
66 67 68 69 70 71 72 73 |
# File 'lib/rbxl/editable_cell.rb', line 66 def value=(new_value) reject_unsupported_type!(new_value) node = @worksheet.find_or_create_cell_node(@coordinate, create: true) apply_value(node, new_value) @worksheet.mark_dirty! new_value end |