xlsxrb 0.1.13 → 0.1.15

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 (71) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +104 -0
  3. data/README.md +17 -14
  4. data/lib/xlsxrb/colors.rb +118 -0
  5. data/lib/xlsxrb/elements/cell.rb +205 -16
  6. data/lib/xlsxrb/elements/column.rb +6 -4
  7. data/lib/xlsxrb/elements/coordinate_access.rb +32 -0
  8. data/lib/xlsxrb/elements/image.rb +128 -0
  9. data/lib/xlsxrb/elements/row.rb +206 -9
  10. data/lib/xlsxrb/elements/styles.rb +157 -0
  11. data/lib/xlsxrb/elements/types.rb +95 -1
  12. data/lib/xlsxrb/elements/workbook.rb +121 -4
  13. data/lib/xlsxrb/elements/worksheet.rb +519 -29
  14. data/lib/xlsxrb/elements.rb +2 -0
  15. data/lib/xlsxrb/number_formatter.rb +429 -0
  16. data/lib/xlsxrb/ooxml/cfb.rb +1 -1
  17. data/lib/xlsxrb/ooxml/reader/listeners/core_listeners.rb +7 -5
  18. data/lib/xlsxrb/ooxml/reader/listeners/drawing_listeners.rb +11 -4
  19. data/lib/xlsxrb/ooxml/reader/listeners/feature_listeners.rb +7 -1
  20. data/lib/xlsxrb/ooxml/reader.rb +14 -17
  21. data/lib/xlsxrb/ooxml/shared_strings_parser.rb +7 -1
  22. data/lib/xlsxrb/ooxml/styles_parser.rb +39 -9
  23. data/lib/xlsxrb/ooxml/utils.rb +34 -18
  24. data/lib/xlsxrb/ooxml/workbook_parser.rb +74 -16
  25. data/lib/xlsxrb/ooxml/workbook_writer.rb +82 -23
  26. data/lib/xlsxrb/ooxml/worksheet_parser.rb +319 -79
  27. data/lib/xlsxrb/ooxml/worksheet_writer.rb +263 -66
  28. data/lib/xlsxrb/ooxml/writer/features_xml.rb +5 -3
  29. data/lib/xlsxrb/ooxml/writer.rb +14 -0
  30. data/lib/xlsxrb/ooxml/xml_builder.rb +14 -2
  31. data/lib/xlsxrb/ooxml/zip_reader.rb +144 -28
  32. data/lib/xlsxrb/stream_row.rb +243 -16
  33. data/lib/xlsxrb/stream_sheet.rb +647 -16
  34. data/lib/xlsxrb/stream_writer.rb +375 -34
  35. data/lib/xlsxrb/style_builder.rb +308 -22
  36. data/lib/xlsxrb/utils.rb +211 -0
  37. data/lib/xlsxrb/version.rb +1 -1
  38. data/lib/xlsxrb/workbook_builder.rb +72 -11
  39. data/lib/xlsxrb/worksheet_builder.rb +738 -24
  40. data/lib/xlsxrb.rb +1073 -83
  41. data/sig/generated/xlsxrb/colors.rbs +40 -0
  42. data/sig/generated/xlsxrb/elements/cell.rbs +113 -8
  43. data/sig/generated/xlsxrb/elements/column.rbs +3 -2
  44. data/sig/generated/xlsxrb/elements/coordinate_access.rbs +18 -0
  45. data/sig/generated/xlsxrb/elements/image.rbs +82 -0
  46. data/sig/generated/xlsxrb/elements/row.rbs +83 -4
  47. data/sig/generated/xlsxrb/elements/styles.rbs +79 -0
  48. data/sig/generated/xlsxrb/elements/types.rbs +43 -0
  49. data/sig/generated/xlsxrb/elements/workbook.rbs +79 -2
  50. data/sig/generated/xlsxrb/elements/worksheet.rbs +282 -18
  51. data/sig/generated/xlsxrb/number_formatter.rbs +132 -0
  52. data/sig/generated/xlsxrb/ooxml/reader.rbs +6 -0
  53. data/sig/generated/xlsxrb/ooxml/shared_strings_parser.rbs +2 -0
  54. data/sig/generated/xlsxrb/ooxml/styles_parser.rbs +5 -2
  55. data/sig/generated/xlsxrb/ooxml/utils.rbs +17 -8
  56. data/sig/generated/xlsxrb/ooxml/workbook_parser.rbs +9 -3
  57. data/sig/generated/xlsxrb/ooxml/workbook_writer.rbs +1 -1
  58. data/sig/generated/xlsxrb/ooxml/worksheet_parser.rbs +28 -6
  59. data/sig/generated/xlsxrb/ooxml/worksheet_writer.rbs +13 -3
  60. data/sig/generated/xlsxrb/ooxml/writer.rbs +2 -0
  61. data/sig/generated/xlsxrb/ooxml/xml_builder.rbs +3 -1
  62. data/sig/generated/xlsxrb/ooxml/zip_reader.rbs +13 -0
  63. data/sig/generated/xlsxrb/stream_row.rbs +100 -6
  64. data/sig/generated/xlsxrb/stream_sheet.rbs +358 -14
  65. data/sig/generated/xlsxrb/stream_writer.rbs +220 -30
  66. data/sig/generated/xlsxrb/style_builder.rbs +55 -18
  67. data/sig/generated/xlsxrb/utils.rbs +151 -0
  68. data/sig/generated/xlsxrb/workbook_builder.rbs +26 -0
  69. data/sig/generated/xlsxrb/worksheet_builder.rbs +356 -18
  70. data/sig/generated/xlsxrb.rbs +223 -27
  71. metadata +11 -1
@@ -10,20 +10,32 @@ module Xlsxrb
10
10
 
11
11
  EMPTY_HASH: untyped
12
12
 
13
+ TAG_DELIM_BYTES: untyped
14
+
15
+ ROW_ATTR_START_BYTES: untyped
16
+
13
17
  # Parses all rows from a worksheet XML string.
14
18
  # Returns an Array of raw row hashes:
15
19
  # { index:, cells: [{ ref:, type:, style_index:, value:, formula: }], attrs:, unmapped: }
16
- def self.parse: (untyped xml_string, ?shared_strings: untyped) -> untyped
20
+ def self.parse: (untyped xml_string, ?shared_strings: untyped, ?styles: untyped) -> untyped
17
21
 
18
22
  # Streaming parse: yields one raw row hash at a time.
19
- def self.each_row: (untyped xml_source, ?shared_strings: untyped, ?part_name: untyped) ?{ (?) -> untyped } -> untyped
23
+ def self.each_row: (untyped xml_source, ?shared_strings: untyped, ?part_name: untyped, ?styles: untyped, ?date1904: untyped, ?trim_empty_rows: untyped, ?pad_empty_rows: untyped, ?pad_empty_cells: untyped) ?{ (?) -> untyped } -> untyped
20
24
 
21
25
  # Parses column definitions (<cols>) from a worksheet.
22
- def self.parse_columns: (untyped xml_string, ?part_name: untyped) -> untyped
26
+ def self.parse_columns: (untyped xml_string, ?untyped _part_name) -> untyped
23
27
 
24
28
  # Yields Event objects for columns, rows, cells, and hyperlinks.
25
29
  def self.each_event: (untyped xml_string, ?shared_strings: untyped, ?part_name: untyped) ?{ (?) -> untyped } -> untyped
26
30
 
31
+ # Parses all hyperlink elements from worksheet XML.
32
+ #
33
+ # @param xml_string [String, nil]
34
+ # @return [Array<Hash[Symbol, untyped]>]
35
+ # @api public
36
+ # : (String?) -> Array[Hash[Symbol, untyped]]
37
+ def self.parse_hyperlinks: (String?) -> Array[Hash[Symbol, untyped]]
38
+
27
39
  def self.fast_scan_events: (untyped xml_src, untyped shared_strings, untyped part_name) ?{ (?) -> untyped } -> untyped
28
40
 
29
41
  def self.extract_row_attrs: (untyped row_tag) -> untyped
@@ -43,6 +55,9 @@ module Xlsxrb
43
55
  # : (String str) -> String
44
56
  def self.decode_xml_entities: (String str) -> String
45
57
 
58
+ # : (String str) -> String
59
+ def self.normalize_text: (String str) -> String
60
+
46
61
  # Parses <cols> section for column definitions.
47
62
  class ColumnsListener
48
63
  include REXML::SAX2Listener
@@ -58,9 +73,11 @@ module Xlsxrb
58
73
  def characters: (untyped _text) -> untyped
59
74
  end
60
75
 
61
- def self.fast_scan_rows_direct: (untyped xml_src, untyped shared_strings, untyped _part_name) ?{ (?) -> untyped } -> untyped
76
+ # rubocop:disable Style/OptionalBooleanParameter
77
+ def self.fast_scan_rows_direct: (untyped xml_src, untyped shared_strings, untyped _part_name, ?untyped styles, ?untyped date1904, ?untyped pad_empty_cells) ?{ (?) -> untyped } -> untyped
62
78
 
63
- def self.scan_rows_stream: (untyped source, untyped shared_strings, untyped _part_name) ?{ (?) -> untyped } -> untyped
79
+ # rubocop:disable Style/OptionalBooleanParameter
80
+ def self.scan_rows_stream: (untyped source, untyped shared_strings, untyped _part_name, ?untyped styles, ?untyped date1904, ?untyped pad_empty_cells) ?{ (?) -> untyped } -> untyped
64
81
 
65
82
  COL_LETTERS: untyped
66
83
 
@@ -78,7 +95,12 @@ module Xlsxrb
78
95
 
79
96
  def self.fast_parse_cells_direct: (untyped xml, untyped from, untyped to, untyped shared_strings, untyped row_source, ?untyped prefix) -> untyped
80
97
 
81
- def self.fast_scan_cells_direct: (untyped xml, untyped from, untyped to, untyped shared_strings, untyped row_source, ?untyped _prefix) ?{ (?) -> untyped } -> untyped
98
+ # rubocop:disable Style/OptionalBooleanParameter
99
+ def self.fast_scan_cells_direct: (untyped xml, untyped from, untyped to, untyped shared_strings, untyped row_source, ?untyped _prefix, ?untyped styles, ?untyped date1904) ?{ (?) -> untyped } -> untyped
100
+
101
+ # rubocop:disable Style/OptionalBooleanParameter
102
+ # : (String xml, Integer from, Integer to, Array[String] shared_strings, ?untyped styles, ?bool date1904, ?type_cast: bool) -> Array[untyped]
103
+ def self.fast_scan_row_values: (String xml, Integer from, Integer to, Array[String] shared_strings, ?untyped styles, ?bool date1904, ?type_cast: bool) -> Array[untyped]
82
104
  end
83
105
  end
84
106
  end
@@ -13,7 +13,9 @@ module Xlsxrb
13
13
 
14
14
  INTEGER_STRINGS: untyped
15
15
 
16
- def initialize: (untyped io) -> untyped
16
+ def initialize: (untyped io, ?date1904: untyped) -> untyped
17
+
18
+ def set_column_style: (untyped col_index, untyped style_id) -> untyped
17
19
 
18
20
  # Write the worksheet header. Call once before writing rows.
19
21
  # Options for pre-sheetData elements:
@@ -22,7 +24,7 @@ module Xlsxrb
22
24
  # split_pane: { x_split:, y_split:, top_left_cell: }
23
25
  # selection: { active_cell:, sqref:, pane: }
24
26
  # sheet_view: Hash of sheet view properties
25
- def start: (?columns: untyped, ?sheet_properties: untyped, ?freeze_pane: untyped, ?split_pane: untyped, ?selection: untyped, ?sheet_view: untyped) -> untyped
27
+ def start: (?columns: untyped, ?sheet_properties: untyped, ?freeze_pane: untyped, ?split_pane: untyped, ?selection: untyped, ?sheet_view: untyped, ?sheet_format: untyped) -> untyped
26
28
 
27
29
  # Write a single row. Automatically calls start if needed.
28
30
  def write_row: (untyped row_index, untyped cells, ?attrs: untyped, ?unmapped: untyped, ?sst_index: untyped) -> untyped
@@ -32,16 +34,22 @@ module Xlsxrb
32
34
 
33
35
  # Write the worksheet footer. Call once after all rows.
34
36
  # Options for post-sheetData elements (in OOXML order):
35
- def finish: (?drawing_rid: untyped, ?sheet_protection: untyped, ?auto_filter: untyped, ?filter_columns: untyped, ?sort_state: untyped, ?merge_cells: untyped, ?conditional_formats: untyped, ?data_validations: untyped, ?hyperlinks: untyped, ?print_options: untyped, ?page_margins: untyped, ?page_setup: untyped, ?header_footer: untyped, ?row_breaks: untyped, ?col_breaks: untyped, ?tables: untyped, ?table_start_rid: untyped, ?legacy_drawing_rid: untyped, ?sparkline_groups: untyped) -> untyped
37
+ def finish: (?drawing_rid: untyped, ?sheet_protection: untyped, ?protected_ranges: untyped, ?auto_filter: untyped, ?filter_columns: untyped, ?sort_state: untyped, ?merge_cells: untyped, ?conditional_formats: untyped, ?data_validations: untyped, ?hyperlinks: untyped, ?print_options: untyped, ?page_margins: untyped, ?page_setup: untyped, ?header_footer: untyped, ?row_breaks: untyped, ?col_breaks: untyped, ?cell_watches: untyped, ?tables: untyped, ?table_start_rid: untyped, ?legacy_drawing_rid: untyped, ?sparkline_groups: untyped) -> untyped
36
38
 
37
39
  private
38
40
 
41
+ def resolve_style_id: (untyped style, untyped style_map) -> untyped
42
+
39
43
  def write_sheet_properties: (untyped props) -> untyped
40
44
 
41
45
  def write_sheet_views: (?freeze_pane: untyped, ?split_pane: untyped, ?selection: untyped, ?sheet_view: untyped) -> untyped
42
46
 
47
+ def write_sheet_format_pr: (untyped fmt) -> untyped
48
+
43
49
  def write_sheet_protection: (untyped opts) -> untyped
44
50
 
51
+ def write_protected_ranges: (untyped ranges) -> untyped
52
+
45
53
  def write_auto_filter: (untyped range, untyped filter_columns, untyped sort_state) -> untyped
46
54
 
47
55
  def write_filter_column: (untyped col_id, untyped filter) -> untyped
@@ -66,6 +74,8 @@ module Xlsxrb
66
74
 
67
75
  def write_col_breaks: (untyped breaks) -> untyped
68
76
 
77
+ def write_cell_watches: (untyped watches) -> untyped
78
+
69
79
  def write_table_parts: (untyped tables, untyped start_rid) -> untyped
70
80
 
71
81
  def write_sparklines: (untyped groups) -> untyped
@@ -432,6 +432,8 @@ module Xlsxrb
432
432
  # : (untyped name, untyped value) -> untyped
433
433
  def set_workbook_property: (untyped name, untyped value) -> untyped
434
434
 
435
+ alias workbook_property set_workbook_property
436
+
435
437
  # Returns workbook properties hash.
436
438
  # : () -> untyped
437
439
  def workbook_properties: () -> untyped
@@ -46,7 +46,9 @@ module Xlsxrb
46
46
  # : (untyped value) -> String
47
47
  def self.escape: (untyped value) -> String
48
48
 
49
- # Unescapes predefined XML entities in a string in a single pass.
49
+ NUM_ENTITY_RE: ::Regexp
50
+
51
+ # Unescapes predefined and numeric/hex XML entities in a string.
50
52
  #
51
53
  # @param value [Object]
52
54
  # @return [String]
@@ -62,6 +62,8 @@ module Xlsxrb
62
62
  private
63
63
 
64
64
  def fetch_chunk: (untyped chunk_size) -> untyped
65
+
66
+ def check_bom_encoding!: () -> untyped
65
67
  end
66
68
 
67
69
  # Opens a ZIP from a file path or IO and yields the reader.
@@ -128,6 +130,17 @@ module Xlsxrb
128
130
  def decompress: (untyped raw, untyped method) -> untyped
129
131
 
130
132
  def safe_inflate: (untyped raw, untyped wbits) -> untyped
133
+
134
+ def normalize_entry_name: (untyped name) -> untyped
135
+
136
+ def lookup_entry: (untyped name) -> untyped
137
+
138
+ def ci_catalog: () -> untyped
139
+
140
+ def normalize_text_encoding: (untyped data) -> untyped
141
+
142
+ # : (String extra_data, Integer usize, Integer csize, Integer offset) -> [Integer, Integer, Integer]
143
+ def parse_zip64_extra: (String extra_data, Integer usize, Integer csize, Integer offset) -> [ Integer, Integer, Integer ]
131
144
  end
132
145
  end
133
146
  end
@@ -23,8 +23,14 @@ module Xlsxrb
23
23
 
24
24
  attr_reader custom_height: untyped
25
25
 
26
+ attr_reader collapsed: untyped
27
+
26
28
  attr_reader outline_level: untyped
27
29
 
30
+ attr_reader style_index: untyped
31
+
32
+ attr_reader pad_empty_cells: untyped
33
+
28
34
  # @param index [Integer] 0-based row index.
29
35
  # @param xml_bytes [String] Raw ASCII-8BIT XML bytes.
30
36
  # @param from [Integer] Byte offset where cells start.
@@ -34,12 +40,58 @@ module Xlsxrb
34
40
  # @param height [Float, Integer, nil] Row height in points.
35
41
  # @param hidden [Boolean] Whether the row is hidden.
36
42
  # @param custom_height [Boolean] Whether custom height is set.
43
+ # @param collapsed [Boolean] Whether the row is collapsed.
37
44
  # @param outline_level [Integer, nil] Grouping/outline level.
38
- # : (index: Integer, xml_bytes: String, from: Integer, to: Integer, shared_strings: Array[String], ?prefix: String, ?height: Float | Integer | nil, ?hidden: bool, ?custom_height: bool, ?outline_level: Integer | nil) -> void
39
- def initialize: (index: Integer, xml_bytes: String, from: Integer, to: Integer, shared_strings: Array[String], ?prefix: String, ?height: Float | Integer | nil, ?hidden: bool, ?custom_height: bool, ?outline_level: Integer | nil) -> void
45
+ # @param style_index [Integer, nil] Style index.
46
+ # @param date1904 [Boolean] Whether the 1904 date system is active.
47
+ # @param pad_empty_cells [Boolean] Whether missing cells in this row are padded.
48
+ # : (index: Integer, xml_bytes: String, from: Integer, to: Integer, shared_strings: Array[String], ?prefix: String, ?height: Float | Integer | nil, ?hidden: bool, ?custom_height: bool, ?collapsed: bool, ?outline_level: Integer | nil, ?style_index: Integer | nil, ?styles: Hash[untyped, untyped]?, ?date1904: bool, ?pad_empty_cells: bool) -> void
49
+ def initialize: (index: Integer, xml_bytes: String, from: Integer, to: Integer, shared_strings: Array[String], ?prefix: String, ?height: Float | Integer | nil, ?hidden: bool, ?custom_height: bool, ?collapsed: bool, ?outline_level: Integer | nil, ?style_index: Integer | nil, ?styles: Hash[untyped, untyped]?, ?date1904: bool, ?pad_empty_cells: bool) -> void
40
50
 
41
51
  # rubocop:disable Style/OptionalBooleanParameter
42
- def self.fast_create: (untyped index, untyped xml_bytes, untyped from, untyped to, untyped shared_strings, ?untyped prefix, ?untyped height, ?untyped hidden, ?untyped custom_height, ?untyped outline_level) -> untyped
52
+ def self.fast_create: (untyped index, untyped xml_bytes, untyped from, untyped to, untyped shared_strings, ?untyped prefix, ?untyped height, ?untyped hidden, ?untyped custom_height, ?untyped outline_level, ?untyped style_index, ?untyped styles, ?untyped date1904, ?untyped collapsed, ?untyped pad_empty_cells) -> untyped
53
+
54
+ # Returns whether the row is hidden.
55
+ #
56
+ # @return [Boolean]
57
+ # @api public
58
+ # : () -> bool
59
+ def hidden?: () -> bool
60
+
61
+ # Returns whether the row is collapsed.
62
+ #
63
+ # @return [Boolean]
64
+ # @api public
65
+ # : () -> bool
66
+ def collapsed?: () -> bool
67
+
68
+ # Returns whether custom height is set.
69
+ #
70
+ # @return [Boolean]
71
+ # @api public
72
+ # : () -> bool
73
+ def custom_height?: () -> bool
74
+
75
+ # Returns a frozen Hash of row attributes.
76
+ #
77
+ # @return [Hash{Symbol => Object}]
78
+ # @api public
79
+ # : () -> Hash[Symbol, untyped]
80
+ def attributes: () -> Hash[Symbol, untyped]
81
+
82
+ # Returns whether the row uses the 1904 date system.
83
+ #
84
+ # @return [Boolean]
85
+ # @api public
86
+ # : () -> bool
87
+ def date1904?: () -> bool
88
+
89
+ # Returns whether missing cells in this row are padded.
90
+ #
91
+ # @return [Boolean]
92
+ # @api public
93
+ # : () -> bool
94
+ def pad_empty_cells?: () -> bool
43
95
 
44
96
  # Iterate over cells in this streaming row one by one.
45
97
  #
@@ -86,6 +138,14 @@ module Xlsxrb
86
138
  # : (Integer col_index) -> Elements::Cell?
87
139
  def cell_at: (Integer col_index) -> Elements::Cell?
88
140
 
141
+ # Convert row cells to a coordinate-keyed Hash (e.g. {"A1" => "value", "B1" => 123}).
142
+ #
143
+ # @param type_cast [Boolean] Whether to coerce date/time serial numbers into Date/Time instances.
144
+ # @return [Hash{String => Object}]
145
+ # @api public
146
+ # : (?type_cast: bool) -> Hash[String, untyped]
147
+ def to_h: (?type_cast: bool) -> Hash[String, untyped]
148
+
89
149
  # Convert row cells to an Array of raw values (sparse columns get nil).
90
150
  #
91
151
  # @return [Array<Object>]
@@ -93,12 +153,34 @@ module Xlsxrb
93
153
  # : () -> Array[untyped]
94
154
  def to_a: () -> Array[untyped]
95
155
 
96
- # Returns cell values as an Array.
156
+ # Returns cell values as an Array (sparse columns get nil).
97
157
  #
158
+ # @param type_cast [Boolean] Whether to coerce date/time serial numbers into Date/Time instances.
98
159
  # @return [Array<Object>]
99
160
  # @api public
100
- # : () -> Array[untyped]
101
- def values: () -> Array[untyped]
161
+ # : (?type_cast: bool) -> Array[untyped]
162
+ def values: (?type_cast: bool) -> Array[untyped]
163
+
164
+ # Convert row cells to an Array of raw string values (sparse columns get nil).
165
+ #
166
+ # @return [Array<String, nil>]
167
+ # @api public
168
+ # : () -> Array[String?]
169
+ def raw_values: () -> Array[String?]
170
+
171
+ # Convert row cells to an Array of formatted string representations (sparse columns get nil).
172
+ #
173
+ # @return [Array<String, nil>]
174
+ # @api public
175
+ # : () -> Array[String?]
176
+ def formatted_values: () -> Array[String?]
177
+
178
+ # Convert row cells to an Array of formula expressions without leading '=' (sparse columns get nil).
179
+ #
180
+ # @return [Array<String, nil>]
181
+ # @api public
182
+ # : () -> Array[String?]
183
+ def formulas: () -> Array[String?]
102
184
 
103
185
  # Returns whether the row is valid according to OOXML specifications.
104
186
  #
@@ -107,6 +189,13 @@ module Xlsxrb
107
189
  # : () -> bool
108
190
  def valid?: () -> bool
109
191
 
192
+ # Returns whether the row contains no cell values (or all cell values are nil or empty strings).
193
+ #
194
+ # @return [Boolean]
195
+ # @api public
196
+ # : () -> bool
197
+ def empty?: () -> bool
198
+
110
199
  # Unmapped metadata for compatibility with Elements::Row.
111
200
  #
112
201
  # @return [Hash]
@@ -127,5 +216,10 @@ module Xlsxrb
127
216
  # @api public
128
217
  # : () -> String
129
218
  def inspect: () -> String
219
+
220
+ private
221
+
222
+ # : (bool) -> Array[untyped]
223
+ def values_from_cells: (bool) -> Array[untyped]
130
224
  end
131
225
  end