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
@@ -3,6 +3,7 @@
3
3
  # rbs_inline: enabled
4
4
 
5
5
  require_relative "elements/types"
6
+ require_relative "elements/metadata"
6
7
  require_relative "elements/cell"
7
8
  require_relative "elements/row"
8
9
  require_relative "elements/column"
@@ -58,7 +58,11 @@ module Xlsxrb
58
58
  when "vertAlign"
59
59
  @current_font[:vert_align] = attributes["val"] if @inside_rpr && attributes["val"]
60
60
  when "sz"
61
- @current_font[:sz] = attributes["val"]&.to_f if @inside_rpr
61
+ if @inside_rpr
62
+ sz_val = attributes["val"]&.to_f
63
+ @current_font[:sz] = sz_val
64
+ @current_font[:size] = sz_val
65
+ end
62
66
  when "color"
63
67
  if @inside_rpr
64
68
  if attributes["rgb"]
@@ -228,7 +232,11 @@ module Xlsxrb
228
232
  when "vertAlign"
229
233
  @is_current_font[:vert_align] = attributes["val"] if @inside_is_rpr && attributes["val"]
230
234
  when "sz"
231
- @is_current_font[:sz] = attributes["val"]&.to_f if @inside_is_rpr
235
+ if @inside_is_rpr
236
+ sz_val = attributes["val"]&.to_f
237
+ @is_current_font[:sz] = sz_val
238
+ @is_current_font[:size] = sz_val
239
+ end
232
240
  when "color"
233
241
  if @inside_is_rpr
234
242
  if attributes["rgb"]
@@ -347,7 +355,7 @@ module Xlsxrb
347
355
  if !expr.empty?
348
356
  @shared_formula_masters[@formula_si] = { cell: @current_cell_ref, expression: expr }
349
357
  elsif (master = @shared_formula_masters[@formula_si])
350
- expr = Xlsxrb::Utils.expand_formula(master[:expression], from_ref: master[:cell], to_ref: @current_cell_ref)
358
+ expr = Xlsxrb.expand_formula(master[:expression], from_ref: master[:cell], to_ref: @current_cell_ref)
351
359
  end
352
360
  end
353
361
  @cells[@current_cell_ref] = Xlsxrb::Elements::Formula.new(
@@ -393,7 +401,7 @@ module Xlsxrb
393
401
  next unless val.is_a?(Xlsxrb::Elements::Formula) && val.type == :shared && (val.expression.nil? || val.expression.empty?)
394
402
  next unless val.shared_index && (master = @shared_formula_masters[val.shared_index])
395
403
 
396
- expanded = Xlsxrb::Utils.expand_formula(master[:expression], from_ref: master[:cell], to_ref: ref)
404
+ expanded = Xlsxrb.expand_formula(master[:expression], from_ref: master[:cell], to_ref: ref)
397
405
  @cells[ref] = val.with(expression: expanded)
398
406
  end
399
407
  end
@@ -3529,7 +3529,8 @@ module Xlsxrb
3529
3529
  @text_buffer = +""
3530
3530
  when "comment"
3531
3531
  @inside_comment = true
3532
- @current_comment = { ref: attributes["ref"], author_id: attributes["authorId"]&.to_i }
3532
+ r = attributes["ref"]
3533
+ @current_comment = { ref: r, author_id: attributes["authorId"]&.to_i }
3533
3534
  @current_comment[:guid] = attributes["guid"] if attributes["guid"]
3534
3535
  sid = attributes["shapeId"]
3535
3536
  @current_comment[:shape_id] = sid.to_i if sid
@@ -3562,7 +3563,11 @@ module Xlsxrb
3562
3563
  when "vertAlign"
3563
3564
  @current_font[:vert_align] = attributes["val"] if @inside_rpr && attributes["val"]
3564
3565
  when "sz"
3565
- @current_font[:sz] = attributes["val"]&.to_f if @inside_rpr
3566
+ if @inside_rpr
3567
+ sz_val = attributes["val"]&.to_f
3568
+ @current_font[:sz] = sz_val
3569
+ @current_font[:size] = sz_val
3570
+ end
3566
3571
  when "color"
3567
3572
  if @inside_rpr
3568
3573
  if attributes["rgb"]
@@ -105,6 +105,7 @@ module Xlsxrb
105
105
  @inside_custom_filters = false
106
106
  when "filterColumn"
107
107
  if @current_col_id && @current_filter
108
+ @current_filter[:hidden] = true if @fc_hidden_button
108
109
  @current_filter[:hidden_button] = true if @fc_hidden_button
109
110
  @current_filter[:show_button] = false if @fc_show_button == false
110
111
  @filter_columns[@current_col_id] = @current_filter
@@ -227,7 +228,9 @@ module Xlsxrb
227
228
  name = element_name(local_name, qname)
228
229
  case name
229
230
  when "Application"
230
- @properties[:application] = @text_buffer.dup
231
+ val = @text_buffer.dup
232
+ @properties[:application] = val
233
+ @properties[:app_name] = val
231
234
  @current_field = nil
232
235
  when "AppVersion"
233
236
  @properties[:app_version] = @text_buffer.dup
@@ -782,13 +785,22 @@ module Xlsxrb
782
785
  drh = attributes["defaultRowHeight"]
783
786
  @properties[:default_row_height] = drh.to_f if drh
784
787
  dcw = attributes["defaultColWidth"]
785
- @properties[:default_col_width] = dcw.to_f if dcw
788
+ if dcw
789
+ @properties[:default_column_width] = dcw.to_f
790
+ @properties[:default_col_width] = dcw.to_f
791
+ end
786
792
  bcw = attributes["baseColWidth"]
787
- @properties[:base_col_width] = bcw.to_i if bcw
793
+ if bcw
794
+ @properties[:base_column_width] = bcw.to_i
795
+ @properties[:base_col_width] = bcw.to_i
796
+ end
788
797
  olr = attributes["outlineLevelRow"]
789
798
  @properties[:outline_level_row] = olr.to_i if olr
790
799
  olc = attributes["outlineLevelCol"]
791
- @properties[:outline_level_col] = olc.to_i if olc
800
+ if olc
801
+ @properties[:outline_level_column] = olc.to_i
802
+ @properties[:outline_level_col] = olc.to_i
803
+ end
792
804
  ch = attributes["customHeight"]
793
805
  @properties[:custom_height] = true if %w[1 true].include?(ch)
794
806
  zh = attributes["zeroHeight"]
@@ -875,18 +887,22 @@ module Xlsxrb
875
887
  frozen = attributes["state"] == "frozen"
876
888
  tlc = attributes["topLeftCell"]
877
889
  ap = attributes["activePane"]
890
+ col_val = xs ? xs.to_i : 0
891
+ row_val = ys ? ys.to_i : 0
878
892
  p = if frozen
879
893
  {
880
- row: ys ? ys.to_i : 0,
881
- col: xs ? xs.to_i : 0,
894
+ row: row_val,
895
+ column: col_val,
896
+ col: col_val,
882
897
  state: :frozen
883
898
  }
884
899
  else
885
900
  {
886
- row: ys ? ys.to_i : 0,
887
- col: xs ? xs.to_i : 0,
888
- x_split: xs ? xs.to_i : 0,
889
- y_split: ys ? ys.to_i : 0,
901
+ row: row_val,
902
+ column: col_val,
903
+ col: col_val,
904
+ x_split: col_val,
905
+ y_split: row_val,
890
906
  top_left_cell: tlc,
891
907
  state: :split
892
908
  }
@@ -1039,7 +1055,11 @@ module Xlsxrb
1039
1055
  @current_rule[:pivot] = true if @current_pivot
1040
1056
  @current_rule[:priority] = attributes["priority"].to_i if attributes["priority"]
1041
1057
  @current_rule[:operator] = attributes["operator"] if attributes["operator"]
1042
- @current_rule[:format_id] = attributes["dxfId"].to_i if attributes["dxfId"]
1058
+ if attributes["dxfId"]
1059
+ did = attributes["dxfId"].to_i
1060
+ @current_rule[:dxf_id] = did
1061
+ @current_rule[:format_id] = did
1062
+ end
1043
1063
  @current_rule[:stop_if_true] = true if attributes["stopIfTrue"] == "1"
1044
1064
  @current_rule[:above_average] = false if attributes["aboveAverage"] == "0"
1045
1065
  @current_rule[:equal_average] = true if attributes["equalAverage"] == "1"
@@ -1108,7 +1128,11 @@ module Xlsxrb
1108
1128
  name = element_name(local_name, qname)
1109
1129
  case name
1110
1130
  when "formula"
1111
- (@current_rule[:formulas] ||= []) << @text_buffer.dup if @current_rule
1131
+ if @current_rule
1132
+ val = @text_buffer.dup
1133
+ (@current_rule[:formulas] ||= []) << val
1134
+ @current_rule[:formula] = @current_rule[:formulas]
1135
+ end
1112
1136
  @inside_formula = false
1113
1137
  when "cfRule"
1114
1138
  @rules << @current_rule if @current_rule
@@ -1154,7 +1178,7 @@ module Xlsxrb
1154
1178
  class PrintPageListener
1155
1179
  include REXML::SAX2Listener
1156
1180
 
1157
- attr_reader :print_options, :page_margins, :page_setup, :header_footer, :row_breaks, :col_breaks
1181
+ attr_reader :print_options, :page_margins, :page_setup, :header_footer, :row_breaks, :col_breaks, :column_breaks
1158
1182
 
1159
1183
  def initialize
1160
1184
  @print_options = {}
@@ -1163,6 +1187,7 @@ module Xlsxrb
1163
1187
  @header_footer = {}
1164
1188
  @row_breaks = []
1165
1189
  @col_breaks = []
1190
+ @column_breaks = @col_breaks
1166
1191
  @inside_header_footer = false
1167
1192
  @inside_row_breaks = false
1168
1193
  @inside_col_breaks = false
@@ -1491,7 +1516,11 @@ module Xlsxrb
1491
1516
  @pivot_table[:data_caption] = attributes["dataCaption"] if attributes["dataCaption"]
1492
1517
  @pivot_table[:data_on_rows] = attributes["dataOnRows"] == "1" if attributes["dataOnRows"]
1493
1518
  @pivot_table[:row_grand_totals] = attributes["rowGrandTotals"] != "0" if attributes["rowGrandTotals"]
1494
- @pivot_table[:col_grand_totals] = attributes["colGrandTotals"] != "0" if attributes["colGrandTotals"]
1519
+ if attributes["colGrandTotals"]
1520
+ cgt = attributes["colGrandTotals"] != "0"
1521
+ @pivot_table[:column_grand_totals] = cgt
1522
+ @pivot_table[:col_grand_totals] = cgt
1523
+ end
1495
1524
  @pivot_table[:compact] = attributes["compact"] != "0" if attributes["compact"]
1496
1525
  @pivot_table[:outline] = attributes["outline"] != "0" if attributes["outline"]
1497
1526
  @pivot_table[:outline_data] = attributes["outlineData"] == "1" if attributes["outlineData"]
@@ -1544,7 +1573,11 @@ module Xlsxrb
1544
1573
  when "location"
1545
1574
  @pivot_table[:ref] = attributes["ref"] if @pivot_table
1546
1575
  @pivot_table[:row_page_count] = attributes["rowPageCount"]&.to_i if attributes["rowPageCount"]
1547
- @pivot_table[:col_page_count] = attributes["colPageCount"]&.to_i if attributes["colPageCount"]
1576
+ if attributes["colPageCount"]
1577
+ cpc = attributes["colPageCount"].to_i
1578
+ @pivot_table[:column_page_count] = cpc
1579
+ @pivot_table[:col_page_count] = cpc
1580
+ end
1548
1581
  when "pivotField"
1549
1582
  @inside_pivot_field = true
1550
1583
  @current_field = {}
@@ -1601,11 +1634,19 @@ module Xlsxrb
1601
1634
  srh = attributes["showRowHeaders"]
1602
1635
  psi[:show_row_headers] = srh == "1" unless srh.nil?
1603
1636
  sch = attributes["showColHeaders"]
1604
- psi[:show_col_headers] = sch == "1" unless sch.nil?
1637
+ unless sch.nil?
1638
+ val = sch == "1"
1639
+ psi[:show_column_headers] = val
1640
+ psi[:show_col_headers] = val
1641
+ end
1605
1642
  srs = attributes["showRowStripes"]
1606
1643
  psi[:show_row_stripes] = srs == "1" unless srs.nil?
1607
1644
  scs = attributes["showColStripes"]
1608
- psi[:show_col_stripes] = scs == "1" unless scs.nil?
1645
+ unless scs.nil?
1646
+ val = scs == "1"
1647
+ psi[:show_column_stripes] = val
1648
+ psi[:show_col_stripes] = val
1649
+ end
1609
1650
  slc = attributes["showLastColumn"]
1610
1651
  psi[:show_last_column] = slc == "1" unless slc.nil?
1611
1652
  @pivot_table[:pivot_table_style] = psi
@@ -1626,6 +1667,7 @@ module Xlsxrb
1626
1667
  if @pivot_table
1627
1668
  @pivot_table[:fields] = @fields
1628
1669
  @pivot_table[:row_fields] = @row_fields
1670
+ @pivot_table[:column_fields] = @col_fields
1629
1671
  @pivot_table[:col_fields] = @col_fields
1630
1672
  @pivot_table[:data_fields] = @data_fields
1631
1673
  end
@@ -1910,6 +1952,211 @@ module Xlsxrb
1910
1952
  end
1911
1953
  end
1912
1954
  end
1955
+
1956
+ # SAX2 listener for parsing <x14:sparklineGroups> and child <x14:sparklineGroup> elements.
1957
+ class SparklineGroupsListener
1958
+ include REXML::SAX2Listener
1959
+
1960
+ COLOR_TAG_MAP = {
1961
+ "colorSeries" => :color_series,
1962
+ "colorNegative" => :color_negative,
1963
+ "colorAxis" => :color_axis,
1964
+ "colorMarkers" => :color_markers,
1965
+ "colorFirst" => :color_first,
1966
+ "colorLast" => :color_last,
1967
+ "colorHigh" => :color_high,
1968
+ "colorLow" => :color_low
1969
+ }.freeze
1970
+
1971
+ # @return [Array<Hash[Symbol, untyped]>]
1972
+ #: Array[Hash[Symbol, untyped]]
1973
+ attr_reader :groups
1974
+ alias sparkline_groups groups
1975
+
1976
+ #: () -> void
1977
+ def initialize
1978
+ @groups = []
1979
+ @current_group = nil
1980
+ @current_sparkline = nil
1981
+ @inside_f = false
1982
+ @inside_sqref = false
1983
+ @text_buffer = +""
1984
+ end
1985
+
1986
+ #: (untyped _uri, String? local_name, String? qname, Hash[String, String] attributes) -> void
1987
+ def start_element(_uri, local_name, qname, attributes)
1988
+ name = element_name(local_name, qname)
1989
+ case name
1990
+ when "sparklineGroup"
1991
+ disp = attributes["displayEmptyCellsAs"]
1992
+ max_attr = attributes["manualMax"]
1993
+ min_attr = attributes["manualMin"]
1994
+ lw_attr = attributes["lineWeight"]
1995
+ max = parse_numeric(max_attr)
1996
+ min = parse_numeric(min_attr)
1997
+ line_weight = parse_numeric(lw_attr)
1998
+
1999
+ @current_group = {
2000
+ type: attributes["type"] || "line",
2001
+ display_empty: disp,
2002
+ display_empty_cells_as: disp,
2003
+ markers: %w[1 true].include?(attributes["markers"]),
2004
+ high: %w[1 true].include?(attributes["high"]),
2005
+ low: %w[1 true].include?(attributes["low"]),
2006
+ first: %w[1 true].include?(attributes["first"]),
2007
+ last: %w[1 true].include?(attributes["last"]),
2008
+ negative: %w[1 true].include?(attributes["negative"]),
2009
+ max: max,
2010
+ manual_max: max,
2011
+ min: min,
2012
+ manual_min: min,
2013
+ line_weight: line_weight,
2014
+ sparklines: []
2015
+ }
2016
+ when "colorSeries", "colorNegative", "colorAxis", "colorMarkers", "colorFirst", "colorLast", "colorHigh", "colorLow"
2017
+ if @current_group
2018
+ color = parse_color(attributes)
2019
+ key = COLOR_TAG_MAP[name]
2020
+ @current_group[key] = color if color && key
2021
+ end
2022
+ when "sparkline"
2023
+ @current_sparkline = {}
2024
+ when "f"
2025
+ if @current_sparkline
2026
+ @inside_f = true
2027
+ @text_buffer = +""
2028
+ end
2029
+ when "sqref"
2030
+ if @current_sparkline
2031
+ @inside_sqref = true
2032
+ @text_buffer = +""
2033
+ end
2034
+ end
2035
+ end
2036
+
2037
+ #: (String text) -> void
2038
+ def characters(text)
2039
+ @text_buffer << text if @inside_f || @inside_sqref
2040
+ end
2041
+
2042
+ #: (untyped _uri, String? local_name, String? qname) -> void
2043
+ def end_element(_uri, local_name, qname)
2044
+ name = element_name(local_name, qname)
2045
+ case name
2046
+ when "f"
2047
+ if @current_sparkline && @inside_f
2048
+ val = @text_buffer.strip
2049
+ @current_sparkline[:data_ref] = val
2050
+ @current_sparkline[:formula] = val
2051
+ @inside_f = false
2052
+ end
2053
+ when "sqref"
2054
+ if @current_sparkline && @inside_sqref
2055
+ val = @text_buffer.strip
2056
+ @current_sparkline[:location_ref] = val
2057
+ @current_sparkline[:sqref] = val
2058
+ @inside_sqref = false
2059
+ end
2060
+ when "sparkline"
2061
+ if @current_group && @current_sparkline
2062
+ @current_group[:sparklines] << @current_sparkline
2063
+ @current_sparkline = nil
2064
+ end
2065
+ when "sparklineGroup"
2066
+ if @current_group
2067
+ @groups << @current_group
2068
+ @current_group = nil
2069
+ end
2070
+ end
2071
+ end
2072
+
2073
+ private
2074
+
2075
+ #: (String? str) -> (Integer | Float | nil)
2076
+ def parse_numeric(str)
2077
+ return nil if str.nil? || str.empty?
2078
+
2079
+ str.include?(".") ? str.to_f : str.to_i
2080
+ end
2081
+
2082
+ #: (Hash[String, String] attributes) -> (String | Hash[Symbol, untyped] | nil)
2083
+ def parse_color(attributes)
2084
+ if attributes["rgb"]
2085
+ attributes["rgb"]
2086
+ elsif attributes["theme"] || attributes["tint"]
2087
+ c = {}
2088
+ c[:theme] = attributes["theme"].to_i if attributes["theme"]
2089
+ c[:tint] = attributes["tint"].to_f if attributes["tint"]
2090
+ c
2091
+ end
2092
+ end
2093
+
2094
+ #: (String? local_name, String? qname) -> String
2095
+ def element_name(local_name, qname)
2096
+ if local_name.nil? || local_name.empty?
2097
+ qname.to_s.split(":").last
2098
+ else
2099
+ local_name
2100
+ end
2101
+ end
2102
+ end
2103
+
2104
+ # SAX2 listener for parsing VML drawings of header and footer images (<v:shape> and <v:imagedata>).
2105
+ class VmlHeaderFooterListener
2106
+ include REXML::SAX2Listener
2107
+
2108
+ # @return [Array<Hash[Symbol, untyped]>]
2109
+ #: Array[Hash[Symbol, untyped]]
2110
+ attr_reader :shapes
2111
+
2112
+ #: () -> void
2113
+ def initialize
2114
+ @shapes = []
2115
+ @current_shape = nil
2116
+ end
2117
+
2118
+ #: (untyped _uri, String? local_name, String? qname, Hash[String, String] attributes) -> void
2119
+ def start_element(_uri, local_name, qname, attributes)
2120
+ name = element_name(local_name, qname)
2121
+ case name
2122
+ when "shape"
2123
+ @current_shape = {
2124
+ id: attributes["id"]
2125
+ }
2126
+ when "imagedata"
2127
+ if @current_shape
2128
+ rel_id = attributes["o:relid"] || attributes["relid"] || attributes["r:id"] ||
2129
+ attributes.find { |k, _| k.to_s.end_with?(":relid") }&.last ||
2130
+ attributes.find { |k, _| k.to_s.end_with?(":id") }&.last
2131
+ title = attributes["o:title"] || attributes["title"] ||
2132
+ attributes.find { |k, _| k.to_s.end_with?(":title") }&.last
2133
+ @current_shape[:rel_id] = rel_id
2134
+ @current_shape[:title] = title if title
2135
+ end
2136
+ end
2137
+ end
2138
+
2139
+ #: (untyped _uri, String? local_name, String? qname) -> void
2140
+ def end_element(_uri, local_name, qname)
2141
+ name = element_name(local_name, qname)
2142
+ case name
2143
+ when "shape"
2144
+ @shapes << @current_shape if @current_shape && @current_shape[:rel_id]
2145
+ @current_shape = nil
2146
+ end
2147
+ end
2148
+
2149
+ private
2150
+
2151
+ #: (String? local_name, String? qname) -> String
2152
+ def element_name(local_name, qname)
2153
+ if local_name.nil? || local_name.empty?
2154
+ qname.to_s.split(":").last
2155
+ else
2156
+ local_name
2157
+ end
2158
+ end
2159
+ end
1913
2160
  end
1914
2161
  end
1915
2162
  end
@@ -55,7 +55,11 @@ module Xlsxrb
55
55
  id = attributes["numFmtId"]&.to_i
56
56
  code = attributes["formatCode"]
57
57
  if @inside_dxfs && @current_dxf
58
- @current_dxf[:num_fmt] = { num_fmt_id: id, format_code: code } if id && code
58
+ if id && code
59
+ nf = { num_fmt_id: id, format_code: code }
60
+ @current_dxf[:number_format] = nf
61
+ @current_dxf[:num_fmt] = nf
62
+ end
59
63
  elsif id && code
60
64
  @num_fmts[id] = code
61
65
  end
@@ -162,7 +166,11 @@ module Xlsxrb
162
166
  when "charset"
163
167
  @current_font[:charset] = attributes["val"].to_i if @current_font && attributes["val"]
164
168
  when "sz"
165
- @current_font[:sz] = attributes["val"]&.to_f if @current_font
169
+ if @current_font
170
+ sz_val = attributes["val"]&.to_f
171
+ @current_font[:sz] = sz_val
172
+ @current_font[:size] = sz_val
173
+ end
166
174
  when "color"
167
175
  parse_color(attributes)
168
176
  when "fills"
@@ -170,7 +178,13 @@ module Xlsxrb
170
178
  when "fill"
171
179
  @current_fill = {} if @inside_fills || @inside_dxfs
172
180
  when "patternFill"
173
- @current_fill[:pattern] = attributes["patternType"] if @current_fill
181
+ if @current_fill
182
+ pt = attributes["patternType"]
183
+ if pt
184
+ @current_fill[:pattern_type] = pt
185
+ @current_fill[:pattern] = pt
186
+ end
187
+ end
174
188
  when "gradientFill"
175
189
  if @current_fill
176
190
  gradient = {}
@@ -10,6 +10,8 @@ require_relative "../number_formatter"
10
10
  module Xlsxrb
11
11
  module Ooxml
12
12
  # Reads cells from an XLSX file.
13
+ #
14
+ # @api private
13
15
  class Reader
14
16
  def initialize(filepath)
15
17
  @filepath = filepath
@@ -333,6 +335,7 @@ module Xlsxrb
333
335
  show_outline_symbols: props[:show_outline_symbols]
334
336
  }.compact
335
337
  end
338
+ # @deprecated Use {#outline_properties} instead. Will be removed in 0.2.0.
336
339
  alias outline_pr outline_properties
337
340
 
338
341
  # Returns phonetic properties for the given sheet, or nil if not present.
@@ -1044,6 +1047,7 @@ module Xlsxrb
1044
1047
  "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument",
1045
1048
  "http://purl.oclc.org/ooxml/officeDocument/relationships/officeDocument"
1046
1049
  ].freeze
1050
+ private_constant :OFFICE_DOC_REL_TYPES
1047
1051
 
1048
1052
  # Returns :strict or :transitional based on the namespace of the workbook XML.
1049
1053
  def format_variant
@@ -56,7 +56,7 @@ module Xlsxrb
56
56
  id = attrs["numFmtId"]&.to_i
57
57
  code = attrs["formatCode"]
58
58
  if @current_dxf
59
- @current_dxf[:num_fmt] = { num_fmt_id: id, format_code: code } if id && code
59
+ @current_dxf[:number_format] = { num_fmt_id: id, format_code: code } if id && code
60
60
  elsif parent_context?("numFmts") && id && code
61
61
  @result[:num_fmts][id] = code
62
62
  end
@@ -83,7 +83,11 @@ module Xlsxrb
83
83
  when "vertAlign"
84
84
  @current_font[:vert_align] = attrs["val"] if @current_font && attrs["val"]
85
85
  when "sz"
86
- @current_font[:sz] = attrs["val"]&.to_f if @current_font
86
+ if @current_font
87
+ sz_val = attrs["val"]&.to_f
88
+ @current_font[:sz] = sz_val
89
+ @current_font[:size] = sz_val
90
+ end
87
91
  when "color"
88
92
  handle_color(attrs)
89
93
  when "name"
@@ -128,7 +132,10 @@ module Xlsxrb
128
132
  end
129
133
  when "fill"
130
134
  if @current_fill
131
- @current_fill[:pattern] = @current_fill_pattern if @current_fill_pattern
135
+ if @current_fill_pattern
136
+ @current_fill[:pattern_type] = @current_fill_pattern
137
+ @current_fill[:pattern] = @current_fill_pattern
138
+ end
132
139
  if @current_dxf
133
140
  @current_dxf[:fill] = @current_fill
134
141
  else