xlsxrb 0.1.17 → 0.1.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +93 -1
  3. data/README.md +79 -19
  4. data/lib/ruby_lsp/xlsxrb/completion_listener.rb +31 -61
  5. data/lib/xlsxrb/chart_builder.rb +595 -113
  6. data/lib/xlsxrb/dsl_helpers.rb +72 -20
  7. data/lib/xlsxrb/elements/cell.rb +243 -56
  8. data/lib/xlsxrb/elements/column.rb +94 -5
  9. data/lib/xlsxrb/elements/coordinate_access.rb +108 -10
  10. data/lib/xlsxrb/elements/image.rb +81 -15
  11. data/lib/xlsxrb/elements/metadata.rb +2733 -0
  12. data/lib/xlsxrb/elements/row.rb +130 -46
  13. data/lib/xlsxrb/elements/styles.rb +184 -76
  14. data/lib/xlsxrb/elements/types.rb +242 -7
  15. data/lib/xlsxrb/elements/workbook.rb +171 -82
  16. data/lib/xlsxrb/elements/worksheet.rb +598 -102
  17. data/lib/xlsxrb/elements.rb +1 -0
  18. data/lib/xlsxrb/ooxml/reader/listeners/core_listeners.rb +12 -4
  19. data/lib/xlsxrb/ooxml/reader/listeners/drawing_listeners.rb +7 -2
  20. data/lib/xlsxrb/ooxml/reader/listeners/feature_listeners.rb +264 -17
  21. data/lib/xlsxrb/ooxml/reader/listeners/style_listeners.rb +17 -3
  22. data/lib/xlsxrb/ooxml/reader.rb +4 -0
  23. data/lib/xlsxrb/ooxml/styles_parser.rb +10 -3
  24. data/lib/xlsxrb/ooxml/workbook_writer.rb +90 -36
  25. data/lib/xlsxrb/ooxml/worksheet_parser.rb +2 -2
  26. data/lib/xlsxrb/ooxml/worksheet_writer.rb +64 -19
  27. data/lib/xlsxrb/ooxml/writer/drawing_xml.rb +5 -2
  28. data/lib/xlsxrb/ooxml/writer/features_xml.rb +26 -5
  29. data/lib/xlsxrb/ooxml/writer/styles_xml.rb +19 -9
  30. data/lib/xlsxrb/ooxml/writer.rb +22 -6
  31. data/lib/xlsxrb/ooxml/zip_generator.rb +2 -0
  32. data/lib/xlsxrb/ooxml/zip_reader.rb +47 -10
  33. data/lib/xlsxrb/stream_row.rb +97 -18
  34. data/lib/xlsxrb/stream_sheet.rb +706 -190
  35. data/lib/xlsxrb/stream_writer.rb +1893 -374
  36. data/lib/xlsxrb/style_builder.rb +774 -111
  37. data/lib/xlsxrb/utils.rb +66 -106
  38. data/lib/xlsxrb/version.rb +1 -1
  39. data/lib/xlsxrb/workbook_builder.rb +380 -83
  40. data/lib/xlsxrb/worksheet_builder.rb +1210 -233
  41. data/lib/xlsxrb.rb +1266 -326
  42. data/sig/generated/xlsxrb/chart_builder.rbs +319 -90
  43. data/sig/generated/xlsxrb/dsl_helpers.rbs +20 -2
  44. data/sig/generated/xlsxrb/elements/cell.rbs +92 -20
  45. data/sig/generated/xlsxrb/elements/column.rbs +61 -2
  46. data/sig/generated/xlsxrb/elements/coordinate_access.rbs +49 -7
  47. data/sig/generated/xlsxrb/elements/image.rbs +30 -8
  48. data/sig/generated/xlsxrb/elements/metadata.rbs +1587 -0
  49. data/sig/generated/xlsxrb/elements/row.rbs +61 -21
  50. data/sig/generated/xlsxrb/elements/styles.rbs +96 -58
  51. data/sig/generated/xlsxrb/elements/types.rbs +27 -0
  52. data/sig/generated/xlsxrb/elements/workbook.rbs +63 -52
  53. data/sig/generated/xlsxrb/elements/worksheet.rbs +192 -51
  54. data/sig/generated/xlsxrb/ooxml/reader/listeners/feature_listeners.rbs +61 -0
  55. data/sig/generated/xlsxrb/ooxml/reader.rbs +3 -0
  56. data/sig/generated/xlsxrb/ooxml/workbook_writer.rbs +1 -1
  57. data/sig/generated/xlsxrb/ooxml/worksheet_writer.rbs +1 -1
  58. data/sig/generated/xlsxrb/ooxml/writer.rbs +3 -0
  59. data/sig/generated/xlsxrb/ooxml/zip_generator.rbs +2 -0
  60. data/sig/generated/xlsxrb/ooxml/zip_reader.rbs +2 -2
  61. data/sig/generated/xlsxrb/stream_row.rbs +48 -14
  62. data/sig/generated/xlsxrb/stream_sheet.rbs +324 -115
  63. data/sig/generated/xlsxrb/stream_writer.rbs +1068 -255
  64. data/sig/generated/xlsxrb/style_builder.rbs +389 -79
  65. data/sig/generated/xlsxrb/utils.rbs +34 -18
  66. data/sig/generated/xlsxrb/workbook_builder.rbs +234 -34
  67. data/sig/generated/xlsxrb/worksheet_builder.rbs +628 -126
  68. data/sig/generated/xlsxrb.rbs +257 -49
  69. metadata +3 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '021999337251e5676fd32d18d0f9f4f6bfd1379a7ee0d7caf8e1a4dba0ba4188'
4
- data.tar.gz: e0985f7acd53f4d4945f2ff05d06d6e59595e683297f2d4701040947536169cd
3
+ metadata.gz: f63edc4ff06e7c40608175b89fbcb822f121bae1b485ea689885540806498bec
4
+ data.tar.gz: c26a8000287eb1ff23ffc6987be404dbc7a34ea1f634b3d063faac6481a57e81
5
5
  SHA512:
6
- metadata.gz: 1c5689e894d657a94af63b2805b2cf24010bfc1de01b5794661b34c30d7252040da2a506b188f1cf9f3849878cd07b3187f7755bc1daa653161faf69c88d2be0
7
- data.tar.gz: cefcef0cad4c356681ef2e3634dcd785a88dfde02beaee0b517411d7c79b4088a58647a8f5c89323ced13dbd7fbc4157e76caf6a50b32b40539e3ae6a68a8cb5
6
+ metadata.gz: a7980f5301fe23f6bc7577447d8d924ab6c17f2ad5f5849e9023b95cb74ac86a15d9c61d9113bbb7b4c517a8961a14e3f7c4b96e533f4e8fb6010897f21b5bed
7
+ data.tar.gz: cbf3e1bdee2d617da99c32c7a5ad8e4acb4d6cd81d6cc662b6d4d46783dd0592185c142d7a4d26ca0300b66478d93780e2fde45f6ad5e29deaec80910338e245
data/CHANGELOG.md CHANGED
@@ -1,4 +1,96 @@
1
- ## [Unreleased]
1
+ ## [0.1.18] - 2026-11-07
2
+
3
+ ### Added
4
+ - Add Value Object factory delegator methods (`formula`, `array_formula`, `shared_formula`, `rich_text`, `comment`, `cell_error`, `hyperlink`) across `WorkbookBuilder`, `WorksheetBuilder`, `StreamWriter`, and `StreamWriter::WorksheetProxy`.
5
+ - Add canonical coordinate conversion facade methods `Xlsxrb.parse_ref`, `Xlsxrb.cell_to_ref`, `Xlsxrb.column_index`, and `Xlsxrb.column_letter`.
6
+ - Add `Xlsxrb.format_value` as the canonical value formatting method.
7
+ - Add `Xlsxrb.time_to_serial` (and `Utils.time_to_serial`) for converting Time/Date objects to Excel numeric serial numbers.
8
+ - Add `Xlsxrb::MAX_COLUMN` constant (16,384) representing the maximum column count supported by Excel / OpenXML.
9
+ - Support passing nested bounding coordinate arrays `[[top_row, left_col], [bottom_row, right_col]]` (as returned by `parse_range`) to `Xlsxrb.range_to_ref`.
10
+ - Support `column_delta:` keyword in `Xlsxrb::Utils.expand_formula`.
11
+ - Support `ref:` keyword argument in `Xlsxrb.array_formula` and include `Elements::CellError` in `cached_value:` types.
12
+ - Support `new_password:` and writer/reader option forwarding in `Xlsxrb.modify`, and return the block result.
13
+ - Define Ractor-shareable frozen `Elements::CellError` constants (`DIV0`, `NA`, `NAME`, `NULL`, `NUM`, `REF`, `VALUE`, `GETTING_DATA`) on `Elements::CellError`.
14
+ - Add canonical cell-level and row-level style keywords `cell_styles:` and `row_style:` across `WorksheetBuilder#row`, `StreamWriter#row`, and `StreamWriter::WorksheetProxy#row`.
15
+ - Expose `:style_index` as a canonical `Data.define` member on `Elements::Row`.
16
+ - Add `style:` keyword to `Elements::Cell.new` and `Elements::Worksheet#update_cell` for style names and inline style definitions.
17
+ - Add 1-based `row_range` and `column_range` boundaries to `Elements::Worksheet` (via `CoordinateAccess`) and `StreamSheet` (from sheet dimension bounds), returning idiomatic `Range[Integer]` boundaries.
18
+ - Support 2D coordinate indexing `sheet[row, col]` and letter column indexing `sheet[row, "A"]` on `Elements::Worksheet` and `CoordinateAccess`.
19
+ - Add `column` and `columns` builder methods across `WorksheetBuilder`, `StreamWriter`, and `WorksheetProxy` with unified options.
20
+ - Support 0-based page break indices (`row_breaks`, `column_breaks`) across builders and readers.
21
+ - Add `Elements::WorkbookProperties#active_sheet` and `Elements::Workbook#active_sheet_index`.
22
+ - Add `Elements::FilterColumn#column_id`.
23
+ - Add structured Hash access for `category_axis` and `value_axis` titles on `Elements::Chart`.
24
+ - Add dedicated assignment setters returning assigned value (`active_sheet=`, `first_sheet=`, `show_sheet_tabs=`, `tab_ratio=`, `code_name=`, `fit_to_page=`, `tab_color=`, `phonetic_properties=`, `sheet_calc_properties=`, `background_image=`, `totals_row=`, `totals_row_count=`, `state=`, `print_area=`, `print_titles=`) across `WorkbookBuilder`, `WorksheetBuilder`, `StreamWriter`, and `StreamWriter::WorksheetProxy`.
25
+ - Add zero-argument property getters across builders and `StyleBuilder`.
26
+ - Add predicate methods (`bold?`, `italic?`, `strike?`, `wrap_text?`, `shrink_to_fit?`, `locked?`, `hidden?`, `superscript?`, `subscript?`) and assignment setters (`font=`, `fill=`, `border=`, `vert_align=`, `superscript=`, `subscript=`, `wrap_text=`, `shrink_to_fit=`, `locked=`, `hidden=`, `protection=`, `number_format=`) on `StyleBuilder`.
27
+ - Re-affirm `totals_row`, `totals_row=`, `totals_row_count`, and `totals_row_count=` as canonical on `TableBuilder` to align with ECMA-376 `totalsRowCount`.
28
+ - Promote reader metadata to immutable Data value objects across `Elements::Styles`, `Elements::Workbook`, and `Elements::Cell`.
29
+ - Add `Elements::Styles#number_format_code(id)`.
30
+ - Support Symbol sheet lookup in `Elements::Workbook#sheet` and `Elements::Workbook#[]`.
31
+ - Freeze `Elements::Cell` instances on instantiation (`initialize` and `fast_create`).
32
+ - Return frozen `Array[Elements::IgnoredError]` from `WorksheetBuilder#ignored_errors`, `StreamWriter#ignored_errors`, and `WorksheetProxy#ignored_errors`.
33
+ - Add XML element existence guards for `merged_cells`, `data_validations`, `conditional_formats` on `StreamSheet`.
34
+ - Establish four-pillar I/O architecture: `Xlsxrb.read`, `Xlsxrb.write`, `Xlsxrb.load`, and `Xlsxrb.build`.
35
+ - Direct worksheet materialization in `Xlsxrb.load` without intermediate `StreamSheet` allocations.
36
+ - Support on-demand zip reopen after close in `Ooxml::ZipReader`.
37
+ - Clarify `@api private` on `Ooxml::Reader`, `Ooxml::Writer`, and `Ooxml::ZipGenerator`.
38
+
39
+ ### Changed
40
+ - Update `Elements::Row#[]` and `StreamRow#[]` to resolve column indices and column letters via `cell_at` instead of indexing the raw sparse `cells` array, returning `nil` when a cell at the specified column is absent.
41
+ - Separate builder getter (`xxx`) and setter (`xxx=`) methods, allowing explicit `nil` resets.
42
+ - Encapsulate `StyleBuilder#resolve_color` as `private`.
43
+ - Encapsulate `StreamSheet#auto_filter_data` as `private`.
44
+ - Make `Xlsxrb._read_workbook` `private_class_method`.
45
+
46
+ ### Deprecated
47
+ - `DslHelpers.sheet_name` is deprecated in favor of `DslHelpers.sanitize_sheet_name`; will be removed in version 0.2.0.
48
+ - Positional `pos_ref` in `Xlsxrb.array_formula` is deprecated in favor of keyword `ref:`; will be removed in version 0.2.0.
49
+ - Top-level aliases `Xlsxrb.stream`, `Xlsxrb.sheet_name`, `Xlsxrb.color_to_hex`, `Xlsxrb.serial_to_datetime`, and `Xlsxrb::Utils.serial_to_datetime` are deprecated in favor of `Xlsxrb.read`, `Xlsxrb.sanitize_sheet_name`, `Xlsxrb.to_hex_color`, and `Xlsxrb.serial_to_time`; will be removed in version 0.2.0.
50
+ - `Xlsxrb.format` is deprecated in favor of `Xlsxrb.format_value`; will be removed in version 0.2.0.
51
+ - `Xlsxrb.datetime_to_serial` and `Xlsxrb::Utils.datetime_to_serial` are deprecated in favor of `Xlsxrb.time_to_serial`; will be removed in version 0.2.0.
52
+ - `Xlsxrb::MAX_COL` is deprecated in favor of `Xlsxrb::MAX_COLUMN`; will be removed in version 0.2.0.
53
+ - `Xlsxrb::Utils` coordinate and date conversion methods (`col_name_to_index`, `col_index_to_name`, `ref_to_row_col`, `row_col_to_ref`, `parse_range`, `range_to_ref`, `date_to_serial`, `serial_to_date`, `serial_to_time`, `time_to_serial`) and `Elements::Cell.column_index`, `column_letter`, `parse_ref` are deprecated in favor of top-level `Xlsxrb.*` helpers; will be removed in version 0.2.0.
54
+ - Keyword `:col_delta` in `Xlsxrb::Utils.expand_formula` is deprecated in favor of `:column_delta`; will be removed in version 0.2.0.
55
+ - Keyword `:si` in `Xlsxrb.shared_formula` is deprecated in favor of `:shared_index`; will be removed in version 0.2.0.
56
+ - `Xlsxrb::Error::DIV0`..`VALUE` cell error constants on the exception class are deprecated in favor of `Elements::CellError::DIV0`..`VALUE`; will be removed in version 0.2.0.
57
+ - Redundant method and setter aliases across builders and element readers (`add_row`, `skip_row`, `group_column`, `group_cols`, `group_col`, `group_row`, `outline_pr`, `add_threaded_comment`, `background_picture`, `picture`, `background_picture=`, `picture=`, `add_protected_range`, `add_cell_watch`, `phonetic_pr`, `phonetic_pr=`, `set_default_font`, `add_column`, `first_col`, `last_col`, `range`, `range=`, `col`, `col=`, `row`, `row=`, `sz`, `sz=`, `error`, `error=`, `prompt`, `prompt=`) are deprecated and will be removed in version 0.2.0.
58
+ - Singular `column:` and `row:` keywords in `defined_name` are deprecated in favor of plural `columns:` and `rows:`; will be removed in version 0.2.0.
59
+ - `show_symbols:` keyword in `outline_properties` is deprecated in favor of `show_outline_symbols:`; will be removed in version 0.2.0.
60
+ - `fit_to_page?` on builders is deprecated in favor of `fit_to_page`; will be removed in version 0.2.0.
61
+ - Keywords `styles:` and `style:` on `WorksheetBuilder#row`, `StreamWriter#row`, and `WorksheetProxy#row` are deprecated in favor of `cell_styles:` and `row_style:`; will be removed in version 0.2.0.
62
+ - Passing non-Integer style names or Hash definitions to `style_index:` on `Elements::Cell.new` and `Elements::Worksheet#update_cell` is deprecated in favor of `style:`; will be removed in version 0.2.0.
63
+ - `Elements::Worksheet#cell` is deprecated in favor of bracket access (`sheet["A1"]` or `sheet[row, col]`) and will be removed in version 0.2.0.
64
+ - `StreamSheet#cell` is deprecated in favor of materializing an `Elements::Worksheet` via `sheet.load` and using coordinate bracket access; will be removed in version 0.2.0.
65
+ - `StreamSheet#first_row` and `StreamSheet#last_row` returning integer row numbers are deprecated in favor of `row_range` or `dimension_bounds`; will be removed in version 0.2.0.
66
+ - Passing coordinate keyword arguments (`row:`, `col_start:`, `col_end:`, `row_start:`, `row_end:`) to `merge` on `WorksheetBuilder`, `StreamWriter`, and `WorksheetProxy` is deprecated in favor of coordinate range strings (e.g. `"A1:C1"`); coordinate kwargs will be removed in version 0.2.0.
67
+ - `Elements::FilterColumn#col_id` is deprecated in favor of `#column_id`; will be removed in version 0.2.0.
68
+ - `Elements::WorkbookProperties#active_tab` is deprecated in favor of `#active_sheet`, and `Elements::Workbook#active_tab` is deprecated in favor of `#active_sheet_index`; will be removed in version 0.2.0.
69
+ - `Elements::Chart#cat_axis_title` and `#val_axis_title` are deprecated in favor of `category_axis[:title]` and `value_axis[:title]`; will be removed in version 0.2.0.
70
+ - `Elements::Worksheet` constructor keywords `sheet_calc_pr:`, `calc_pr:`, `phonetic_pr:`, `background_picture:`, `picture:` are deprecated in favor of canonical keyword arguments; will be removed in version 0.2.0.
71
+ - Calling builder getter methods with arguments to set values or mutate state (`active_sheet`, `first_sheet`, `show_sheet_tabs`, `tab_ratio`, `code_name`, `tab_color`, `sheet_calc_properties`, `phonetic_properties`, `background_image`, `state`, and subbuilders `TableBuilder`, `DataValidationBuilder`, `ConditionalFormatBuilder`) is deprecated and will become 0-argument getters in version 0.2.0; use dedicated setters (`xxx=`) instead.
72
+ - Calling `fit_to_page` with arguments is deprecated and will become a 0-argument boolean getter in version 0.2.0; use `fit_to_page = true/false` or `page_setup(fit_to_width: ..., fit_to_height: ...)` instead.
73
+ - Calling `StyleBuilder` boolean mutator methods (`bold`, `italic`, `underline`, `strike`, `superscript`, `subscript`, `wrap_text`, `shrink_to_fit`, `locked`, `hidden`) with zero arguments to mutate state is deprecated; pass `true` explicitly (e.g. `bold(true)`).
74
+ - `TableBuilder#[]` and `#[]=` are deprecated in favor of `#column(name)` and `#add_column`; will be removed in version 0.2.0.
75
+ - `TableBuilder#total_row`, `#total_row=`, `#total_row_count`, and `#total_row_count=` are deprecated in favor of `totals_row`, `totals_row=`, `totals_row_count`, and `totals_row_count=`; will be removed in version 0.2.0.
76
+ - `Elements::Styles#num_fmt` is deprecated in favor of `Styles#number_format_code`; will be removed in version 0.2.0.
77
+ - `Elements::Dxf#num_fmt` is deprecated in favor of `Dxf#number_format`; will be removed in version 0.2.0.
78
+ - `Elements::SheetProperties#page_setup_pr` is deprecated in favor of `SheetProperties#page_setup_properties`; will be removed in version 0.2.0.
79
+ - `StreamSheet#first_column` and `StreamSheet#last_column` are deprecated in favor of `column_range`; will be removed in version 0.2.0.
80
+ - `StreamSheet#sheet_views`, `#first_column_index`, `#last_column_index`, `#legacy_drawing`, and `#ext_lst` are deprecated in favor of `#sheet_view` and `#column_range`; will be removed in version 0.2.0.
81
+ - `Elements::Worksheet#conditional_formatting` and `StreamSheet#conditional_formatting` are deprecated in favor of `conditional_formats`; will be removed in version 0.2.0.
82
+ - `Elements::Row#to_a` and `StreamRow#to_a` returning cell values are deprecated in favor of `row.values`; in version 0.2.0, `to_a` will return `Array[Elements::Cell]` to conform to `Enumerable#to_a`.
83
+ - Non-predicate boolean queries on element readers (`trim_empty_rows`, `pad_empty_rows`, `pad_empty_cells`, `fit_to_page`, `show_sheet_tabs`, `full_calc_on_load`) are deprecated in favor of `?`-suffixed methods (`trim_empty_rows?`, `pad_empty_rows?`, `pad_empty_cells?`, `fit_to_page?`, `show_sheet_tabs?`, `full_calc_on_load?`); will be removed in version 0.2.0.
84
+ - Transitional aliases `to_workbook` on `Workbook`, `to_worksheet` on `Worksheet` and `StreamSheet`, and `each_sheet` on `Workbook` are deprecated in favor of `load` and `each`; will be removed in version 0.2.0.
85
+ - Style aliases `Styles#xf`, `Styles#format_code_for`, `Styles#classification_for`, and `StyleBuilder#num_fmt` are deprecated in favor of `cell_xf`, `number_format`, and `format_type`; will be removed in version 0.2.0.
86
+ - `Xlsxrb.modify` is deprecated in favor of explicit `Xlsxrb.load` -> mutate -> `Xlsxrb.write` pipeline; will be removed in version 0.2.0.
87
+ - `Xlsxrb.write_workbook` and `Xlsxrb.workbook_to_data` are deprecated in favor of `Xlsxrb.write`; will be removed in version 0.2.0.
88
+ - In-memory `Elements::Workbook#close`, `Elements::Worksheet#close`, and `Elements::Worksheet#load` are deprecated; will be removed in version 0.2.0 (`StreamSheet#close` and `StreamSheet#load` remain supported).
89
+ - Returning non-`Elements::Workbook` values from `Xlsxrb.modify` blocks is deprecated and will raise `TypeError` in version 0.2.0.
90
+
91
+ ### Fixed
92
+ - Prevent attribute loss in `Elements::PivotTable`, `Elements::TableColumn`, `Elements::ThreadedComment`, `Elements::Comment`, and `Elements::FilterColumn` by retaining full schema attributes and capturing unmapped keyword options into `options:`.
93
+ - Eliminate internal calls to deprecated `MetadataRecord#[]`, `#merge`, and `cols:` across `WorksheetBuilder`, `WorkbookBuilder`, `StreamSheet`, `Elements::Worksheet`, and `Elements::Styles`.
2
94
 
3
95
  ## [0.1.17] - 2026-11-01
4
96
 
data/README.md CHANGED
@@ -63,9 +63,37 @@ You can also browse 80+ rendered visual examples across all features in the [Vis
63
63
 
64
64
  ## Usage
65
65
 
66
- ### Quick Start: Streaming (Recommended for Large Files)
66
+ ### I/O Architecture Matrix
67
+
68
+ xlsxrb provides four canonical entry points organized along two axes:
69
+
70
+ | Axis | Streaming ($O(1)$ Memory) | In-Memory (Full Random Access) |
71
+ | :--- | :--- | :--- |
72
+ | Read / Input | `Xlsxrb.read(source) { \|sheet\| ... }` | `Xlsxrb.load(source) -> Elements::Workbook` |
73
+ | Write / Output | `Xlsxrb.write(dest) { \|writer\| ... }` | `Xlsxrb.build { \|builder\| ... } -> Elements::Workbook` |
74
+
75
+ ---
76
+
77
+ ### Streaming Read ($O(1)$ Memory)
78
+
79
+ Iterates rows sequentially without loading the full document into memory. Closes the underlying archive automatically upon block completion:
80
+
81
+ ```ruby
82
+ require "xlsxrb"
83
+
84
+ Xlsxrb.read("large_file.xlsx") do |sheet|
85
+ sheet.each_row do |row|
86
+ row.each_cell do |cell|
87
+ puts "#{cell.ref}: #{cell.value}"
88
+ end
89
+ end
90
+ end
91
+ ```
92
+
93
+ ### Streaming Write (Low Memory)
94
+
95
+ Pipes row and cell XML directly to the archive without buffering rows in memory:
67
96
 
68
- #### Streaming Write (Low Memory)
69
97
  ```ruby
70
98
  require "xlsxrb"
71
99
 
@@ -78,25 +106,25 @@ Xlsxrb.write("large_output.xlsx") do |writer|
78
106
  end
79
107
  ```
80
108
 
81
- > [!NOTE]
82
- > Streaming writes pipe row and cell XML directly to the archive without buffering rows, keeping cell data memory constant. Because shared strings are indexed across the workbook to minimize output file size, memory scales with the count of distinct strings.
109
+ ### In-Memory Load (Full Random Access)
110
+
111
+ Parses the workbook into an immutable document model (`Elements::Workbook`) and immediately closes the underlying file:
83
112
 
84
- #### Streaming Read ($O(1)$ Memory)
85
113
  ```ruby
86
114
  require "xlsxrb"
87
115
 
88
- Xlsxrb.read("large_file.xlsx") do |sheet|
89
- sheet.each_row do |row|
90
- row.each_cell do |cell|
91
- puts "#{cell.ref}: #{cell.value}"
92
- end
93
- end
94
- end
116
+ wb = Xlsxrb.load("workbook.xlsx")
117
+ sheet = wb["Sheet1"]
118
+
119
+ puts sheet["A1"].value
120
+ puts sheet.page_setup.orientation
121
+ puts sheet.hyperlinks["B2"].url
95
122
  ```
96
123
 
97
- ### In-Memory Building & Modifying
124
+ ### In-Memory Build (Document Creation)
125
+
126
+ Constructs an in-memory `Elements::Workbook` using the declarative builder DSL:
98
127
 
99
- #### Creating & Exporting (Rails / Mailers)
100
128
  ```ruby
101
129
  require "xlsxrb"
102
130
 
@@ -112,18 +140,50 @@ Xlsxrb.write("report.xlsx", wb)
112
140
  binary_data = Xlsxrb.write(wb)
113
141
  ```
114
142
 
115
- #### Modifying an Existing File
143
+ ---
144
+
145
+ ### Constant-Memory Streaming Transformation
146
+
147
+ To transform or filter data from an existing spreadsheet, stream rows from reader to writer in $O(1)$ memory:
148
+
116
149
  ```ruby
117
150
  require "xlsxrb"
118
151
 
119
- Xlsxrb.modify("template.xlsx", "output.xlsx") do |workbook|
120
- workbook.update_sheet("Invoice") do |sheet|
121
- sheet.update_cell("C4", value: "INV-10042")
122
- .update_cell("C5", value: Date.today)
152
+ Xlsxrb.write("output.xlsx") do |out_wb|
153
+ out_wb.sheet("Processed") do |out_sheet|
154
+ Xlsxrb.read("input.xlsx") do |in_sheet|
155
+ in_sheet.each_row do |row|
156
+ out_sheet.row(row.cells.map { |c| c.value.is_a?(Numeric) ? c.value * 1.1 : c.value })
157
+ end
158
+ end
123
159
  end
124
160
  end
125
161
  ```
126
162
 
163
+ ---
164
+
165
+ ### Template Migration & AI Code Generation
166
+
167
+ > [!NOTE]
168
+ > `Xlsxrb.modify` is deprecated. Runtime data transformations are handled with streaming pipelines (`Xlsxrb.read` -> `Xlsxrb.write`), while template-based report generation is performed by converting templates into declarative `Xlsxrb.write` DSL code.
169
+
170
+ To migrate an existing Excel template (`template.xlsx`) into reproducible Ruby code, inspect the template structure with `Xlsxrb.load` and provide it to an AI coding assistant:
171
+
172
+ ```ruby
173
+ require "xlsxrb"
174
+
175
+ wb = Xlsxrb.load("template.xlsx")
176
+ sheet = wb.sheets.first
177
+
178
+ # Inspect layout, formulas, and column widths
179
+ puts "Columns: #{sheet.columns.map { |c| [c.index, c.width] }}"
180
+ puts "Merged: #{sheet.merged_cells}"
181
+ puts "Formulas: #{sheet.rows.flat_map(&:cells).select(&:formula?).map { |c| [c.ref, c.formula] }}"
182
+ ```
183
+
184
+ **Recommended AI Prompt for Template Migration:**
185
+ > "Convert this Excel template into an `Xlsxrb.write` builder script using xlsxrb DSL methods (`row`, `column`, `merge`, `style`, `formula`). Ensure cell styles, column widths, number formats, and formulas match the inspected template layout."
186
+
127
187
  ### Password Protection & Encryption ([MS-OFFCRYPTO])
128
188
 
129
189
  Natively supports reading and writing encrypted XLSX files (Standard & Agile Encryption) with zero external C-extensions:
@@ -13,12 +13,12 @@ module RubyLsp
13
13
  STREAM_WRITER_ITEMS = [
14
14
  {
15
15
  label: "sheet",
16
- detail: "(name = nil, **opts) { |sheet| ... } -> void",
17
- documentation: "Adds a new worksheet to the streaming XLSX writer and yields a `WorksheetProxy`.\n\n```ruby\nwb.sheet(\"Sales\") do |s|\n s.row([\"Product\", \"Price\"], styles: :bold)\nend\n```"
16
+ detail: "(name = nil, state: nil, tab_color: nil, code_name: nil, **opts) { |sheet| ... } -> String",
17
+ documentation: "Adds a new worksheet to the streaming XLSX writer and yields a `WorksheetProxy`.\n\n```ruby\nwb.sheet(\"Sales\") do |s|\n s.row([\"Product\", \"Price\"], cell_styles: :bold)\nend\n```"
18
18
  },
19
19
  {
20
20
  label: "style",
21
- detail: "(name, **options) -> Symbol",
21
+ detail: "(name, **opts) { |style_builder| ... } -> StyleBuilder",
22
22
  documentation: "Registers a reusable named cell style (font, fill, border, alignment, number_format).\n\n```ruby\nwb.style(:bold_blue, font: { bold: true, color: \"0000FF\" })\n```"
23
23
  },
24
24
  {
@@ -27,7 +27,7 @@ module RubyLsp
27
27
  documentation: "Sets a workbook-level property (e.g. `:update_links`).\n\n```ruby\nwb.workbook_property(:update_links, \"never\")\n```"
28
28
  },
29
29
  {
30
- label: "protect_workbook",
30
+ label: "workbook_protection",
31
31
  detail: "(**opts) -> void",
32
32
  documentation: "Configures workbook protection options (e.g. `structure: true`, `windows: true`)."
33
33
  },
@@ -43,7 +43,7 @@ module RubyLsp
43
43
  },
44
44
  {
45
45
  label: "print_titles",
46
- detail: "(rows: nil, cols: nil, sheet: nil) -> void",
46
+ detail: "(rows: nil, columns: nil, sheet: nil) -> void",
47
47
  documentation: "Sets repeating title rows or columns for printing (e.g. `rows: \"1:2\"`)."
48
48
  },
49
49
  {
@@ -76,12 +76,12 @@ module RubyLsp
76
76
  WORKBOOK_BUILDER_ITEMS = [
77
77
  {
78
78
  label: "sheet",
79
- detail: "(name = nil, **opts) { |sheet_builder| ... } -> WorksheetBuilder",
79
+ detail: "(name = nil, state: nil, tab_color: nil, code_name: nil, **opts) { |sheet_builder| ... } -> Elements::Worksheet",
80
80
  documentation: "Adds a new worksheet to the workbook builder and yields a `WorksheetBuilder`.\n\n```ruby\nwb.sheet(\"Summary\") do |s|\n s.row([\"Item\", \"Total\"])\nend\n```"
81
81
  },
82
82
  {
83
83
  label: "style",
84
- detail: "(name, **opts) { |style_builder| ... } -> Symbol",
84
+ detail: "(name, **opts) { |style_builder| ... } -> StyleBuilder",
85
85
  documentation: "Defines a named style in the workbook builder."
86
86
  },
87
87
  {
@@ -95,7 +95,7 @@ module RubyLsp
95
95
  documentation: "Sets a workbook property."
96
96
  },
97
97
  {
98
- label: "protect_workbook",
98
+ label: "workbook_protection",
99
99
  detail: "(**opts) -> void",
100
100
  documentation: "Sets workbook protection options."
101
101
  },
@@ -111,7 +111,7 @@ module RubyLsp
111
111
  },
112
112
  {
113
113
  label: "print_titles",
114
- detail: "(rows: nil, cols: nil, sheet: nil) -> void",
114
+ detail: "(rows: nil, columns: nil, sheet: nil) -> void",
115
115
  documentation: "Sets repeating print titles."
116
116
  },
117
117
  {
@@ -139,8 +139,8 @@ module RubyLsp
139
139
  WORKSHEET_PROXY_ITEMS = [
140
140
  {
141
141
  label: "row",
142
- detail: "(values, styles: nil, height: nil, hidden: false, outline_level: nil) -> void",
143
- documentation: "Writes a single row of cells with optional style name, height, and outline level.\n\n```ruby\ns.row([\"Product\", \"Price\"], styles: :bold)\ns.row([\"Laptop\", 1200])\n```"
142
+ detail: "(values, cell_styles: nil, row_style: nil, height: nil, hidden: false, outline_level: nil) -> void",
143
+ documentation: "Writes a single row of cells with optional style name, height, and outline level.\n\n```ruby\ns.row([\"Product\", \"Price\"], cell_styles: :bold)\ns.row([\"Laptop\", 1200])\n```"
144
144
  },
145
145
  {
146
146
  label: "column",
@@ -149,13 +149,13 @@ module RubyLsp
149
149
  },
150
150
  {
151
151
  label: "merge",
152
- detail: "(range = nil, row: nil, col_start: nil, col_end: nil) -> void",
153
- documentation: "Merges a range of cells.\n\n```ruby\ns.merge(\"A1:C1\")\ns.merge(row: 0, col_start: 0, col_end: 2)\n```"
152
+ detail: "(range) -> void",
153
+ documentation: "Merges a range of cells.\n\n```ruby\ns.merge(\"A1:C1\")\n```"
154
154
  },
155
155
  {
156
156
  label: "freeze_pane",
157
- detail: "(row: 0, col: 0) -> void",
158
- documentation: "Freezes rows and columns from scrolling (0-based indices).\n\n```ruby\ns.freeze_pane(row: 1, col: 0) # Freeze top header row\n```"
157
+ detail: "(row: 0, column: 0) -> void",
158
+ documentation: "Freezes rows and columns from scrolling (0-based indices).\n\n```ruby\ns.freeze_pane(row: 1, column: 0) # Freeze top header row\n```"
159
159
  },
160
160
  {
161
161
  label: "auto_filter",
@@ -183,13 +183,13 @@ module RubyLsp
183
183
  documentation: "Adds conditional formatting rules (cellIs, colorScale, dataBar, expression)."
184
184
  },
185
185
  {
186
- label: "validate_data",
186
+ label: "data_validation",
187
187
  detail: "(range, type: \"list\", **opts) -> void",
188
188
  documentation: "Adds data validation rules (dropdown list, whole number, decimal, date range, custom formula)."
189
189
  },
190
190
  {
191
191
  label: "image",
192
- detail: "(file_data, ext: \"png\", from_col: 0, from_row: 0, to_col: 5, to_row: 10, **opts) -> void",
192
+ detail: "(file_data, ext: \"png\", from_column: 0, from_row: 0, to_column: 5, to_row: 10, **opts) -> void",
193
193
  documentation: "Inserts an image into the worksheet."
194
194
  },
195
195
  {
@@ -209,7 +209,7 @@ module RubyLsp
209
209
  },
210
210
  {
211
211
  label: "shape",
212
- detail: "(preset: \"rect\", text: nil, from_col: 0, from_row: 0, to_col: 5, to_row: 5, **opts) -> void",
212
+ detail: "(preset: \"rect\", text: nil, from_column: 0, from_row: 0, to_column: 5, to_row: 5, **opts) -> void",
213
213
  documentation: "Adds a drawing shape to the sheet."
214
214
  },
215
215
  {
@@ -233,7 +233,7 @@ module RubyLsp
233
233
  documentation: "Configures print options (e.g. `s.print_options(:grid_lines, true)`)."
234
234
  },
235
235
  {
236
- label: "protect_sheet",
236
+ label: "sheet_protection",
237
237
  detail: "(**opts) -> void",
238
238
  documentation: "Protects worksheet with optional password hashing and capability flags."
239
239
  },
@@ -248,7 +248,7 @@ module RubyLsp
248
248
  documentation: "Sets sheet properties (e.g. `s.sheet_properties(:tab_color, \"FF0000\")`)."
249
249
  },
250
250
  {
251
- label: "select_cell",
251
+ label: "selection",
252
252
  detail: "(active_cell, sqref: nil, pane: nil) -> void",
253
253
  documentation: "Sets the active / selected cell when opening the worksheet in Excel."
254
254
  },
@@ -268,12 +268,12 @@ module RubyLsp
268
268
  documentation: "Configures sort state conditions on a cell range."
269
269
  },
270
270
  {
271
- label: "page_break_row",
271
+ label: "row_break",
272
272
  detail: "(row_num) -> void",
273
273
  documentation: "Adds a horizontal page break before the given row index."
274
274
  },
275
275
  {
276
- label: "page_break_col",
276
+ label: "column_break",
277
277
  detail: "(col_index) -> void",
278
278
  documentation: "Adds a vertical page break before the given column index."
279
279
  }
@@ -283,7 +283,7 @@ module RubyLsp
283
283
  {
284
284
  label: "each_row",
285
285
  detail: "() { |row| ... } -> void",
286
- documentation: "Yields each row in the streaming sheet as an `Elements::Row`.\n\n```ruby\nsheet.each_row do |row|\n puts row.to_a.inspect\nend\n```"
286
+ documentation: "Yields each row in the streaming sheet as an `Elements::Row`.\n\n```ruby\nsheet.each_row do |row|\n puts row.values.inspect\nend\n```"
287
287
  },
288
288
  {
289
289
  label: "each",
@@ -308,11 +308,6 @@ module RubyLsp
308
308
  detail: "(index_or_name) -> Elements::Worksheet?",
309
309
  documentation: "Returns the worksheet by 0-based index or name.\n\n```ruby\nsheet = workbook[\"Sheet1\"]\n```"
310
310
  },
311
- {
312
- label: "update_sheet",
313
- detail: "(name_or_index, sheet) -> Elements::Workbook",
314
- documentation: "Replaces or updates a sheet and returns a new `Elements::Workbook`."
315
- },
316
311
  {
317
312
  label: "sheet_names",
318
313
  detail: "() -> Array<String>",
@@ -354,7 +349,7 @@ module RubyLsp
354
349
  {
355
350
  label: "each_row",
356
351
  detail: "() { |row| ... } -> void",
357
- documentation: "Yields each row in the worksheet as an `Elements::Row`.\n\n```ruby\nsheet.each_row do |row|\n puts row.to_a.inspect\nend\n```"
352
+ documentation: "Yields each row in the worksheet as an `Elements::Row`.\n\n```ruby\nsheet.each_row do |row|\n puts row.values.inspect\nend\n```"
358
353
  },
359
354
  {
360
355
  label: "each",
@@ -366,11 +361,6 @@ module RubyLsp
366
361
  detail: "() { |cell| ... } -> void",
367
362
  documentation: "Yields every `Elements::Cell` across all rows."
368
363
  },
369
- {
370
- label: "update_cell",
371
- detail: "(ref, new_value) -> Elements::Worksheet",
372
- documentation: "Returns a new worksheet with the updated cell value."
373
- },
374
364
  {
375
365
  label: "row_at",
376
366
  detail: "(row_index) -> Elements::Row?",
@@ -391,11 +381,6 @@ module RubyLsp
391
381
  detail: "() -> Array<Elements::Cell>",
392
382
  documentation: "Returns a flat array of all cells in the sheet."
393
383
  },
394
- {
395
- label: "cells_hash",
396
- detail: "() -> Hash<String, Elements::Cell>",
397
- documentation: "Returns a hash mapping A1 references to `Elements::Cell` objects."
398
- },
399
384
  {
400
385
  label: "name",
401
386
  detail: "() -> String",
@@ -416,13 +401,13 @@ module RubyLsp
416
401
  ROW_ELEMENT_ITEMS = [
417
402
  {
418
403
  label: "[]",
419
- detail: "(col_index_or_symbol) -> Elements::Cell? | Object?",
420
- documentation: "Returns the cell at 0-based column index, or access property symbol (`:cells`, `:index`, `:height`).\n\n```ruby\ncell = row[0]\n```"
404
+ detail: "(col_index_or_letter) -> Elements::Cell?",
405
+ documentation: "Returns the cell at 0-based column index or column letter/Symbol.\n\n```ruby\ncell = row[0]\n```"
421
406
  },
422
407
  {
423
408
  label: "to_a",
424
- detail: "() -> Array<Object?>",
425
- documentation: "Returns an array containing the values of all cells in this row.\n\n```ruby\nvalues = row.to_a\n```"
409
+ detail: "() -> Array<Elements::Cell>",
410
+ documentation: "Returns an array of all `Elements::Cell` objects in this row.\n\n```ruby\ncells = row.to_a\n```"
426
411
  },
427
412
  {
428
413
  label: "values",
@@ -507,11 +492,6 @@ module RubyLsp
507
492
  detail: "() -> Time?",
508
493
  documentation: "Converts cell value to Time."
509
494
  },
510
- {
511
- label: "column_letter",
512
- detail: "() -> String",
513
- documentation: "Returns the column letters (e.g. `\"A\"`, `\"AA\"`)."
514
- },
515
495
  {
516
496
  label: "row_index",
517
497
  detail: "() -> Integer",
@@ -527,16 +507,6 @@ module RubyLsp
527
507
  detail: "() -> Integer?",
528
508
  documentation: "Returns the 0-based index into stylesheet formatting."
529
509
  },
530
- {
531
- label: "content",
532
- detail: "() -> String",
533
- documentation: "Returns string content of cell value."
534
- },
535
- {
536
- label: "[]",
537
- detail: "(symbol) -> Object?",
538
- documentation: "Hash-style access to cell attributes (`:value`, `:ref`, `:style_index`)."
539
- },
540
510
  {
541
511
  label: "valid?",
542
512
  detail: "() -> Boolean",
@@ -605,12 +575,12 @@ module RubyLsp
605
575
  },
606
576
  {
607
577
  label: "border",
608
- detail: "(left: nil, right: nil, top: nil, bottom: nil) -> void",
578
+ detail: "(all: nil, left: nil, right: nil, top: nil, bottom: nil, diagonal: nil) -> self",
609
579
  documentation: "Sets cell border lines and colors."
610
580
  },
611
581
  {
612
582
  label: "alignment",
613
- detail: "(horizontal: nil, vertical: nil, wrap_text: false, rotation: 0) -> void",
583
+ detail: "(horizontal: nil, vertical: nil, wrap_text: nil, text_rotation: nil, indent: nil, shrink_to_fit: nil, ...) -> Hash | self",
614
584
  documentation: "Sets cell text alignment and text wrap."
615
585
  },
616
586
  {
@@ -696,7 +666,7 @@ module RubyLsp
696
666
  when :write then return :stream_writer
697
667
  when :read then return :stream_sheet
698
668
  when :build then return :workbook_builder
699
- when :modify then return :workbook
669
+ when :load then return :workbook
700
670
  end
701
671
  end
702
672