xlsxrb 0.1.16 → 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 (79) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +157 -1
  3. data/README.md +81 -21
  4. data/lib/ruby_lsp/xlsxrb/completion_listener.rb +31 -61
  5. data/lib/xlsxrb/chart_builder.rb +619 -98
  6. data/lib/xlsxrb/dsl_helpers.rb +583 -15
  7. data/lib/xlsxrb/elements/cell.rb +265 -53
  8. data/lib/xlsxrb/elements/column.rb +95 -6
  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 +243 -7
  15. data/lib/xlsxrb/elements/workbook.rb +202 -65
  16. data/lib/xlsxrb/elements/worksheet.rb +728 -85
  17. data/lib/xlsxrb/elements.rb +1 -0
  18. data/lib/xlsxrb/ooxml/reader/listeners/core_listeners.rb +32 -3
  19. data/lib/xlsxrb/ooxml/reader/listeners/drawing_listeners.rb +194 -26
  20. data/lib/xlsxrb/ooxml/reader/listeners/feature_listeners.rb +372 -18
  21. data/lib/xlsxrb/ooxml/reader/listeners/style_listeners.rb +33 -14
  22. data/lib/xlsxrb/ooxml/reader.rb +92 -0
  23. data/lib/xlsxrb/ooxml/styles_parser.rb +29 -14
  24. data/lib/xlsxrb/ooxml/workbook_parser.rb +18 -3
  25. data/lib/xlsxrb/ooxml/workbook_writer.rb +351 -77
  26. data/lib/xlsxrb/ooxml/worksheet_parser.rb +18 -4
  27. data/lib/xlsxrb/ooxml/worksheet_writer.rb +349 -103
  28. data/lib/xlsxrb/ooxml/writer/drawing_xml.rb +584 -443
  29. data/lib/xlsxrb/ooxml/writer/features_xml.rb +52 -14
  30. data/lib/xlsxrb/ooxml/writer/styles_xml.rb +42 -18
  31. data/lib/xlsxrb/ooxml/writer.rb +288 -35
  32. data/lib/xlsxrb/ooxml/zip_generator.rb +2 -0
  33. data/lib/xlsxrb/ooxml/zip_reader.rb +47 -10
  34. data/lib/xlsxrb/ooxml/zip_writer.rb +15 -5
  35. data/lib/xlsxrb/stream_row.rb +97 -18
  36. data/lib/xlsxrb/stream_sheet.rb +827 -157
  37. data/lib/xlsxrb/stream_writer.rb +2766 -375
  38. data/lib/xlsxrb/style_builder.rb +821 -105
  39. data/lib/xlsxrb/utils.rb +82 -57
  40. data/lib/xlsxrb/version.rb +1 -1
  41. data/lib/xlsxrb/workbook_builder.rb +542 -62
  42. data/lib/xlsxrb/worksheet_builder.rb +2279 -209
  43. data/lib/xlsxrb.rb +1539 -344
  44. data/sig/generated/xlsxrb/chart_builder.rbs +336 -79
  45. data/sig/generated/xlsxrb/dsl_helpers.rbs +137 -4
  46. data/sig/generated/xlsxrb/elements/cell.rbs +104 -15
  47. data/sig/generated/xlsxrb/elements/column.rbs +62 -3
  48. data/sig/generated/xlsxrb/elements/coordinate_access.rbs +49 -7
  49. data/sig/generated/xlsxrb/elements/image.rbs +30 -8
  50. data/sig/generated/xlsxrb/elements/metadata.rbs +1587 -0
  51. data/sig/generated/xlsxrb/elements/row.rbs +61 -21
  52. data/sig/generated/xlsxrb/elements/styles.rbs +96 -58
  53. data/sig/generated/xlsxrb/elements/types.rbs +29 -0
  54. data/sig/generated/xlsxrb/elements/workbook.rbs +92 -44
  55. data/sig/generated/xlsxrb/elements/worksheet.rbs +259 -38
  56. data/sig/generated/xlsxrb/ooxml/reader/listeners/core_listeners.rbs +2 -0
  57. data/sig/generated/xlsxrb/ooxml/reader/listeners/drawing_listeners.rbs +74 -2
  58. data/sig/generated/xlsxrb/ooxml/reader/listeners/feature_listeners.rbs +97 -0
  59. data/sig/generated/xlsxrb/ooxml/reader/listeners/style_listeners.rbs +3 -0
  60. data/sig/generated/xlsxrb/ooxml/reader.rbs +20 -0
  61. data/sig/generated/xlsxrb/ooxml/styles_parser.rbs +3 -0
  62. data/sig/generated/xlsxrb/ooxml/workbook_parser.rbs +8 -0
  63. data/sig/generated/xlsxrb/ooxml/workbook_writer.rbs +8 -4
  64. data/sig/generated/xlsxrb/ooxml/worksheet_parser.rbs +1 -1
  65. data/sig/generated/xlsxrb/ooxml/worksheet_writer.rbs +12 -1
  66. data/sig/generated/xlsxrb/ooxml/writer/drawing_xml.rbs +16 -0
  67. data/sig/generated/xlsxrb/ooxml/writer.rbs +45 -8
  68. data/sig/generated/xlsxrb/ooxml/zip_generator.rbs +2 -0
  69. data/sig/generated/xlsxrb/ooxml/zip_reader.rbs +2 -2
  70. data/sig/generated/xlsxrb/ooxml/zip_writer.rbs +8 -2
  71. data/sig/generated/xlsxrb/stream_row.rbs +48 -14
  72. data/sig/generated/xlsxrb/stream_sheet.rbs +398 -89
  73. data/sig/generated/xlsxrb/stream_writer.rbs +1601 -219
  74. data/sig/generated/xlsxrb/style_builder.rbs +403 -75
  75. data/sig/generated/xlsxrb/utils.rbs +49 -13
  76. data/sig/generated/xlsxrb/workbook_builder.rbs +308 -26
  77. data/sig/generated/xlsxrb/worksheet_builder.rbs +1142 -96
  78. data/sig/generated/xlsxrb.rbs +321 -52
  79. metadata +3 -1
@@ -11,6 +11,8 @@ require_relative "../dsl_helpers"
11
11
  module Xlsxrb
12
12
  module Ooxml
13
13
  # Writes spreadsheet data into an XLSX file.
14
+ #
15
+ # @api private
14
16
  class Writer
15
17
  include DrawingXml
16
18
  include FeaturesXml
@@ -33,10 +35,10 @@ module Xlsxrb
33
35
  MAX_ROW = 1_048_576
34
36
  MAX_COLUMN_INDEX = 16_384 # XFD
35
37
 
36
- attr_reader :fonts, :fills, :borders, :xf_entries, :num_fmts
38
+ attr_reader :fonts, :fills, :borders, :xf_entries, :num_fmts, :dxfs
37
39
 
38
- # : () -> void
39
- def initialize
40
+ # : (?default_font: untyped?) -> void
41
+ def initialize(default_font: nil)
40
42
  @sheets = { "Sheet1" => {} }
41
43
  @column_widths = { "Sheet1" => {} }
42
44
  @column_attrs = { "Sheet1" => {} }
@@ -50,6 +52,7 @@ module Xlsxrb
50
52
  @sort_state = { "Sheet1" => nil }
51
53
  @num_fmts = []
52
54
  @fonts = [{ sz: 11, name: "Calibri" }]
55
+ default_font(default_font) if default_font
53
56
  @fills = [{ pattern: "none" }, { pattern: "gray125" }]
54
57
  @borders = [{ left: nil, right: nil, top: nil, bottom: nil }]
55
58
  @xf_entries = [{ num_fmt_id: 0, font_id: 0, fill_id: 0, border_id: 0 }]
@@ -96,6 +99,9 @@ module Xlsxrb
96
99
  @charts_data = { "Sheet1" => [] }
97
100
  @shapes_data = { "Sheet1" => [] }
98
101
  @comments_data = { "Sheet1" => [] }
102
+ @threaded_comments_data = { "Sheet1" => [] }
103
+ @threaded_comment_count = 0
104
+ @persons_data = []
99
105
  @pivot_tables_data = { "Sheet1" => [] }
100
106
  @extra_entries = {}
101
107
  @extra_ct_defaults = {}
@@ -146,6 +152,7 @@ module Xlsxrb
146
152
  @charts_data[name] = []
147
153
  @shapes_data[name] = []
148
154
  @comments_data[name] = []
155
+ @threaded_comments_data[name] = []
149
156
  @pivot_tables_data[name] = []
150
157
  @sheet_protection[name] = nil
151
158
  @protected_ranges[name] = []
@@ -542,6 +549,37 @@ module Xlsxrb
542
549
  @dxfs.size - 1
543
550
  end
544
551
 
552
+ # Sets the workbook-wide default font (font 0).
553
+ #
554
+ # @param name [String, Hash, nil] Font name or font options Hash.
555
+ # @param size [Float, Integer, nil] Font size in points.
556
+ # @param opts [Hash] Additional font options (e.g. `bold:`, `italic:`, `family:`, `charset:`, `color:`).
557
+ # @return [void]
558
+ # @api public
559
+ #: (?String | Hash[Symbol, untyped]? name, ?Float | Integer | nil size, **untyped opts) -> void
560
+ def default_font(name = nil, size = nil, **opts)
561
+ if name.is_a?(Hash)
562
+ opts = name.merge(opts)
563
+ name = opts[:name]
564
+ end
565
+
566
+ font = @fonts[0] ? @fonts[0].dup : { name: "Calibri", sz: 11 }
567
+ font[:name] = (name || opts[:name]).to_s if name || opts[:name]
568
+ font[:sz] = size || opts[:size] || opts[:sz] if size || opts[:size] || opts[:sz]
569
+ font[:family] = opts[:family] if opts.key?(:family)
570
+ font[:charset] = opts[:charset] if opts.key?(:charset)
571
+ font[:scheme] = opts[:scheme].to_s if opts.key?(:scheme)
572
+ font[:color] = opts[:color] if opts.key?(:color)
573
+ font[:bold] = opts[:bold] if opts.key?(:bold)
574
+ font[:italic] = opts[:italic] if opts.key?(:italic)
575
+ font[:strike] = opts[:strike] if opts.key?(:strike)
576
+ font[:underline] = opts[:underline] if opts.key?(:underline)
577
+
578
+ @fonts[0] = font
579
+ end
580
+ # @deprecated Use {#default_font} instead. Will be removed in 0.2.0.
581
+ alias set_default_font default_font
582
+
545
583
  # Sets the indexed colors palette (array of ARGB hex strings, e.g. ["FF000000", "FFFFFFFF"]).
546
584
  # rubocop:disable Naming/AccessorMethodName
547
585
  # : (untyped colors) -> untyped
@@ -883,12 +921,25 @@ module Xlsxrb
883
921
  # Adds a conditional formatting rule to the specified range.
884
922
  # Options: type (:cell_is, :expression, :color_scale, :data_bar, :icon_set),
885
923
  # operator, priority, formula/formulas, format_id, color_scale, data_bar, icon_set.
886
- # : (untyped sqref, ?sheet: untyped?, **untyped opts) -> untyped
887
- def add_conditional_format(sqref, sheet: nil, **opts)
924
+ # : (?untyped sqref, ?sheet: untyped?, **untyped opts) ?{ (ConditionalFormatBuilder) -> void } -> untyped
925
+ def add_conditional_format(sqref = nil, sheet: nil, **opts, &)
888
926
  sheet_name = sheet || @sheet_order.first
889
927
  raise ArgumentError, "unknown sheet: #{sheet_name}" unless @conditional_formats.key?(sheet_name)
890
928
 
891
- @conditional_formats[sheet_name] << opts.merge(sqref: sqref)
929
+ normalized_list = DslHelpers.normalize_conditional_format(sqref, **opts, &)
930
+ normalized_list.each do |rule|
931
+ if (rule[:dxf] || rule[:font_color] || rule[:fill_color] || rule[:bold] || rule[:italic]) && (rule[:dxf_id] || rule[:format_id]).nil?
932
+ dxf = rule.delete(:dxf) || DslHelpers.extract_dxf_from_rule!(rule)
933
+ did = @dxfs.index(dxf) || add_dxf(**dxf) if dxf
934
+ rule[:dxf_id] = did
935
+ rule[:format_id] = did
936
+ elsif rule[:dxf_id] && rule[:format_id].nil?
937
+ rule[:format_id] = rule[:dxf_id]
938
+ elsif rule[:format_id] && rule[:dxf_id].nil?
939
+ rule[:dxf_id] = rule[:format_id]
940
+ end
941
+ @conditional_formats[sheet_name] << rule
942
+ end
892
943
  end
893
944
 
894
945
  # Returns conditional formatting rules for the first (or given) sheet.
@@ -916,7 +967,8 @@ module Xlsxrb
916
967
  %i[header_row_count published comment insert_row insert_row_shift
917
968
  header_row_dxf_id data_dxf_id totals_row_dxf_id
918
969
  header_row_border_dxf_id table_border_dxf_id totals_row_border_dxf_id
919
- header_row_cell_style totals_row_cell_style connection_id table_type].each do |key|
970
+ header_row_cell_style totals_row_cell_style connection_id table_type
971
+ auto_filter show_first_column show_last_column show_row_stripes show_column_stripes].each do |key|
920
972
  tbl[key] = opts[key] if opts.key?(key)
921
973
  end
922
974
  @tables[sheet_name] << tbl
@@ -1278,8 +1330,8 @@ module Xlsxrb
1278
1330
  # Adds a chart to the given sheet.
1279
1331
  # type: :bar, :line, :pie. title: chart title string.
1280
1332
  # data_ref: e.g. "Sheet1!$A$1:$B$4". cat_ref/val_ref for explicit series.
1281
- # : (?type: ::Symbol, ?title: untyped?, ?title_overlay: untyped?, ?title_font: untyped?, ?title_fill_color: untyped?, ?title_no_fill: untyped?, ?title_line_color: untyped?, ?title_line_width: untyped?, ?title_line_dash: untyped?, ?title_rotation: untyped?, ?auto_title_deleted: untyped?, ?cat_ref: untyped?, ?val_ref: untyped?, ?series: untyped?, ?legend: untyped?, ?data_labels: untyped?, ?cat_axis_title: untyped?, ?val_axis_title: untyped?, ?cat_axis_title_font: untyped?, ?cat_axis_title_fill: untyped?, ?cat_axis_title_no_fill: untyped?, ?cat_axis_title_line_color: untyped?, ?cat_axis_title_line_width: untyped?, ?cat_axis_title_line_dash: untyped?, ?cat_axis_title_rotation: untyped?, ?val_axis_title_font: untyped?, ?val_axis_title_fill: untyped?, ?val_axis_title_no_fill: untyped?, ?val_axis_title_line_color: untyped?, ?val_axis_title_line_width: untyped?, ?val_axis_title_line_dash: untyped?, ?val_axis_title_rotation: untyped?, ?cat_axis_tick_lbl_pos: untyped?, ?val_axis_tick_lbl_pos: untyped?, ?cat_axis_major_gridlines: untyped?, ?val_axis_major_gridlines: untyped?, ?cat_axis_minor_gridlines: untyped?, ?val_axis_minor_gridlines: untyped?, ?cat_axis_delete: untyped?, ?val_axis_delete: untyped?, ?cat_axis_orientation: untyped?, ?val_axis_orientation: untyped?, ?cat_axis_num_fmt: untyped?, ?val_axis_num_fmt: untyped?, ?cat_axis_major_tick_mark: untyped?, ?cat_axis_minor_tick_mark: untyped?, ?val_axis_major_tick_mark: untyped?, ?val_axis_minor_tick_mark: untyped?, ?cat_axis_crosses: untyped?, ?val_axis_crosses: untyped?, ?cat_axis_crosses_at: untyped?, ?val_axis_crosses_at: untyped?, ?cat_axis_tick_lbl_skip: untyped?, ?cat_axis_tick_mark_skip: untyped?, ?cat_axis_lbl_offset: untyped?, ?cat_axis_auto: untyped?, ?cat_axis_lbl_algn: untyped?, ?cat_axis_no_multi_lvl_lbl: untyped?, ?val_axis_cross_between: untyped?, ?val_axis_major_unit: untyped?, ?val_axis_minor_unit: untyped?, ?cat_axis_scaling_max: untyped?, ?cat_axis_scaling_min: untyped?, ?val_axis_scaling_max: untyped?, ?val_axis_scaling_min: untyped?, ?cat_axis_log_base: untyped?, ?val_axis_log_base: untyped?, ?val_axis_disp_units: untyped?, ?gap_width: untyped?, ?gap_depth: untyped?, ?overlap: untyped?, ?first_slice_ang: untyped?, ?hole_size: untyped?, ?smooth: untyped?, ?marker: untyped?, ?scatter_style: untyped?, ?radar_style: untyped?, ?bar_shape: untyped?, ?bubble_3d: untyped?, ?bubble_scale: untyped?, ?show_neg_bubbles: untyped?, ?size_represents: untyped?, ?wireframe: untyped?, ?grouping: untyped?, ?bar_dir: untyped?, ?vary_colors: untyped?, ?style: untyped?, ?rounded_corners: untyped?, ?view_3d: untyped?, ?cat_axis_pos: untyped?, ?val_axis_pos: untyped?, ?name: untyped?, ?description: untyped?, ?frame_title: untyped?, ?frame_hidden: untyped?, ?frame_macro: untyped?, ?frame_no_grp: untyped?, ?from_col: ::Integer, ?from_row: ::Integer, ?to_col: ::Integer, ?to_row: ::Integer, ?from_col_off: untyped?, ?from_row_off: untyped?, ?to_col_off: untyped?, ?to_row_off: untyped?, ?edit_as: untyped?, ?published: untyped?, ?locks_with_sheet: untyped?, ?prints_with_sheet: untyped?, ?plot_vis_only: untyped?, ?disp_blanks_as: untyped?, ?show_d_lbls_over_max: untyped?, ?data_table: untyped?, ?plot_area_fill: untyped?, ?plot_area_no_fill: untyped?, ?plot_area_line_color: untyped?, ?plot_area_line_width: untyped?, ?plot_area_line_dash: untyped?, ?plot_area_layout: untyped?, ?floor: untyped?, ?side_wall: untyped?, ?back_wall: untyped?, ?drop_lines: untyped?, ?hi_low_lines: untyped?, ?ser_lines: untyped?, ?up_down_bars: untyped?, ?band_fmts: untyped?, ?of_pie_type: untyped?, ?split_type: untyped?, ?split_pos: untyped?, ?cust_split: untyped?, ?second_pie_size: untyped?, ?cat_axis_label_rotation: untyped?, ?val_axis_label_rotation: untyped?, ?cat_axis_font: untyped?, ?val_axis_font: untyped?, ?cat_axis_line_color: untyped?, ?cat_axis_line_width: untyped?, ?cat_axis_line_dash: untyped?, ?val_axis_line_color: untyped?, ?val_axis_line_width: untyped?, ?val_axis_line_dash: untyped?, ?cat_axis_fill: untyped?, ?cat_axis_no_fill: untyped?, ?val_axis_fill: untyped?, ?val_axis_no_fill: untyped?, ?cat_axis_type: untyped?, ?cat_axis_base_time_unit: untyped?, ?cat_axis_major_time_unit: untyped?, ?cat_axis_minor_time_unit: untyped?, ?cat_axis_major_unit: untyped?, ?cat_axis_minor_unit: untyped?, ?chart_fill: untyped?, ?chart_no_fill: untyped?, ?chart_line_color: untyped?, ?chart_line_width: untyped?, ?chart_line_dash: untyped?, ?protection: untyped?, ?print_settings: untyped?, ?chart_font: untyped?, ?sheet: untyped?) -> untyped
1282
- def add_chart(type: :bar, title: nil, title_overlay: nil, title_font: nil, title_fill_color: nil, title_no_fill: nil, title_line_color: nil, title_line_width: nil, title_line_dash: nil, title_rotation: nil, auto_title_deleted: nil, cat_ref: nil, val_ref: nil, series: nil, legend: nil, data_labels: nil, cat_axis_title: nil, val_axis_title: nil, cat_axis_title_font: nil, cat_axis_title_fill: nil, cat_axis_title_no_fill: nil, cat_axis_title_line_color: nil, cat_axis_title_line_width: nil, cat_axis_title_line_dash: nil, cat_axis_title_rotation: nil, val_axis_title_font: nil, val_axis_title_fill: nil, val_axis_title_no_fill: nil, val_axis_title_line_color: nil, val_axis_title_line_width: nil, val_axis_title_line_dash: nil, val_axis_title_rotation: nil, cat_axis_tick_lbl_pos: nil, val_axis_tick_lbl_pos: nil, cat_axis_major_gridlines: nil, val_axis_major_gridlines: nil, cat_axis_minor_gridlines: nil, val_axis_minor_gridlines: nil, cat_axis_delete: nil, val_axis_delete: nil, cat_axis_orientation: nil, val_axis_orientation: nil, cat_axis_num_fmt: nil, val_axis_num_fmt: nil, cat_axis_major_tick_mark: nil, cat_axis_minor_tick_mark: nil, val_axis_major_tick_mark: nil, val_axis_minor_tick_mark: nil, cat_axis_crosses: nil, val_axis_crosses: nil, cat_axis_crosses_at: nil, val_axis_crosses_at: nil, cat_axis_tick_lbl_skip: nil, cat_axis_tick_mark_skip: nil, cat_axis_lbl_offset: nil, cat_axis_auto: nil, cat_axis_lbl_algn: nil, cat_axis_no_multi_lvl_lbl: nil, val_axis_cross_between: nil, val_axis_major_unit: nil, val_axis_minor_unit: nil, cat_axis_scaling_max: nil, cat_axis_scaling_min: nil, val_axis_scaling_max: nil, val_axis_scaling_min: nil, cat_axis_log_base: nil, val_axis_log_base: nil, val_axis_disp_units: nil, gap_width: nil, gap_depth: nil, overlap: nil, first_slice_ang: nil, hole_size: nil, smooth: nil, marker: nil, scatter_style: nil, radar_style: nil, bar_shape: nil, bubble_3d: nil, bubble_scale: nil, show_neg_bubbles: nil, size_represents: nil, wireframe: nil, grouping: nil, bar_dir: nil, vary_colors: nil, style: nil, rounded_corners: nil, view_3d: nil, cat_axis_pos: nil, val_axis_pos: nil, name: nil, description: nil, frame_title: nil, frame_hidden: nil, frame_macro: nil, frame_no_grp: nil, from_col: 0, from_row: 0, to_col: 10, to_row: 15, from_col_off: nil, from_row_off: nil, to_col_off: nil, to_row_off: nil, edit_as: nil, published: nil, locks_with_sheet: nil, prints_with_sheet: nil, plot_vis_only: nil, disp_blanks_as: nil, show_d_lbls_over_max: nil, data_table: nil, plot_area_fill: nil, plot_area_no_fill: nil, plot_area_line_color: nil, plot_area_line_width: nil, plot_area_line_dash: nil, plot_area_layout: nil, floor: nil, side_wall: nil, back_wall: nil, drop_lines: nil, hi_low_lines: nil, ser_lines: nil, up_down_bars: nil, band_fmts: nil, of_pie_type: nil, split_type: nil, split_pos: nil, cust_split: nil, second_pie_size: nil, cat_axis_label_rotation: nil, val_axis_label_rotation: nil, cat_axis_font: nil, val_axis_font: nil, cat_axis_line_color: nil, cat_axis_line_width: nil, cat_axis_line_dash: nil, val_axis_line_color: nil, val_axis_line_width: nil, val_axis_line_dash: nil, cat_axis_fill: nil, cat_axis_no_fill: nil, val_axis_fill: nil, val_axis_no_fill: nil, cat_axis_type: nil, cat_axis_base_time_unit: nil, cat_axis_major_time_unit: nil, cat_axis_minor_time_unit: nil, cat_axis_major_unit: nil, cat_axis_minor_unit: nil, chart_fill: nil, chart_no_fill: nil, chart_line_color: nil, chart_line_width: nil, chart_line_dash: nil, protection: nil, print_settings: nil, chart_font: nil, sheet: nil)
1333
+ # : (?type: ::Symbol, ?title: untyped?, ?title_overlay: untyped?, ?title_font: untyped?, ?title_fill_color: untyped?, ?title_no_fill: untyped?, ?title_line_color: untyped?, ?title_line_width: untyped?, ?title_line_dash: untyped?, ?title_rotation: untyped?, ?auto_title_deleted: untyped?, ?cat_ref: untyped?, ?val_ref: untyped?, ?series: untyped?, ?legend: untyped?, ?data_labels: untyped?, ?cat_axis_title: untyped?, ?val_axis_title: untyped?, ?cat_axis_title_font: untyped?, ?cat_axis_title_fill: untyped?, ?cat_axis_title_no_fill: untyped?, ?cat_axis_title_line_color: untyped?, ?cat_axis_title_line_width: untyped?, ?cat_axis_title_line_dash: untyped?, ?cat_axis_title_rotation: untyped?, ?val_axis_title_font: untyped?, ?val_axis_title_fill: untyped?, ?val_axis_title_no_fill: untyped?, ?val_axis_title_line_color: untyped?, ?val_axis_title_line_width: untyped?, ?val_axis_title_line_dash: untyped?, ?val_axis_title_rotation: untyped?, ?cat_axis_tick_lbl_pos: untyped?, ?val_axis_tick_lbl_pos: untyped?, ?cat_axis_major_gridlines: untyped?, ?val_axis_major_gridlines: untyped?, ?cat_axis_minor_gridlines: untyped?, ?val_axis_minor_gridlines: untyped?, ?cat_axis_delete: untyped?, ?val_axis_delete: untyped?, ?cat_axis_orientation: untyped?, ?val_axis_orientation: untyped?, ?cat_axis_num_fmt: untyped?, ?val_axis_num_fmt: untyped?, ?cat_axis_major_tick_mark: untyped?, ?cat_axis_minor_tick_mark: untyped?, ?val_axis_major_tick_mark: untyped?, ?val_axis_minor_tick_mark: untyped?, ?cat_axis_crosses: untyped?, ?val_axis_crosses: untyped?, ?cat_axis_crosses_at: untyped?, ?val_axis_crosses_at: untyped?, ?cat_axis_tick_lbl_skip: untyped?, ?cat_axis_tick_mark_skip: untyped?, ?cat_axis_lbl_offset: untyped?, ?cat_axis_auto: untyped?, ?cat_axis_lbl_algn: untyped?, ?cat_axis_no_multi_lvl_lbl: untyped?, ?val_axis_cross_between: untyped?, ?val_axis_major_unit: untyped?, ?val_axis_minor_unit: untyped?, ?cat_axis_scaling_max: untyped?, ?cat_axis_scaling_min: untyped?, ?val_axis_scaling_max: untyped?, ?val_axis_scaling_min: untyped?, ?cat_axis_log_base: untyped?, ?val_axis_log_base: untyped?, ?val_axis_disp_units: untyped?, ?gap_width: untyped?, ?gap_depth: untyped?, ?overlap: untyped?, ?first_slice_ang: untyped?, ?hole_size: untyped?, ?smooth: untyped?, ?marker: untyped?, ?scatter_style: untyped?, ?radar_style: untyped?, ?bar_shape: untyped?, ?bubble_3d: untyped?, ?bubble_scale: untyped?, ?show_neg_bubbles: untyped?, ?size_represents: untyped?, ?wireframe: untyped?, ?grouping: untyped?, ?bar_dir: untyped?, ?vary_colors: untyped?, ?style: untyped?, ?rounded_corners: untyped?, ?view_3d: untyped?, ?cat_axis_pos: untyped?, ?val_axis_pos: untyped?, ?name: untyped?, ?description: untyped?, ?frame_title: untyped?, ?frame_hidden: untyped?, ?frame_macro: untyped?, ?frame_no_grp: untyped?, ?from_col: ::Integer, ?from_row: ::Integer, ?to_col: ::Integer, ?to_row: ::Integer, ?from_col_off: untyped?, ?from_row_off: untyped?, ?to_col_off: untyped?, ?to_row_off: untyped?, ?edit_as: untyped?, ?published: untyped?, ?locks_with_sheet: untyped?, ?prints_with_sheet: untyped?, ?plot_vis_only: untyped?, ?disp_blanks_as: untyped?, ?show_d_lbls_over_max: untyped?, ?data_table: untyped?, ?plot_area_fill: untyped?, ?plot_area_no_fill: untyped?, ?plot_area_line_color: untyped?, ?plot_area_line_width: untyped?, ?plot_area_line_dash: untyped?, ?plot_area_layout: untyped?, ?floor: untyped?, ?side_wall: untyped?, ?back_wall: untyped?, ?drop_lines: untyped?, ?hi_low_lines: untyped?, ?ser_lines: untyped?, ?up_down_bars: untyped?, ?band_fmts: untyped?, ?of_pie_type: untyped?, ?split_type: untyped?, ?split_pos: untyped?, ?cust_split: untyped?, ?second_pie_size: untyped?, ?cat_axis_label_rotation: untyped?, ?val_axis_label_rotation: untyped?, ?cat_axis_font: untyped?, ?val_axis_font: untyped?, ?cat_axis_line_color: untyped?, ?cat_axis_line_width: untyped?, ?cat_axis_line_dash: untyped?, ?val_axis_line_color: untyped?, ?val_axis_line_width: untyped?, ?val_axis_line_dash: untyped?, ?cat_axis_fill: untyped?, ?cat_axis_no_fill: untyped?, ?val_axis_fill: untyped?, ?val_axis_no_fill: untyped?, ?cat_axis_type: untyped?, ?cat_axis_base_time_unit: untyped?, ?cat_axis_major_time_unit: untyped?, ?cat_axis_minor_time_unit: untyped?, ?cat_axis_major_unit: untyped?, ?cat_axis_minor_unit: untyped?, ?chart_fill: untyped?, ?chart_no_fill: untyped?, ?chart_line_color: untyped?, ?chart_line_width: untyped?, ?chart_line_dash: untyped?, ?protection: untyped?, ?print_settings: untyped?, ?chart_font: untyped?, ?secondary_value_axis: untyped?, ?secondary_axis: untyped?, ?category_axis: untyped?, ?value_axis: untyped?, ?sheet: untyped?, **untyped extra_options) -> untyped
1334
+ def add_chart(type: :bar, title: nil, title_overlay: nil, title_font: nil, title_fill_color: nil, title_no_fill: nil, title_line_color: nil, title_line_width: nil, title_line_dash: nil, title_rotation: nil, auto_title_deleted: nil, cat_ref: nil, val_ref: nil, series: nil, legend: nil, data_labels: nil, cat_axis_title: nil, val_axis_title: nil, cat_axis_title_font: nil, cat_axis_title_fill: nil, cat_axis_title_no_fill: nil, cat_axis_title_line_color: nil, cat_axis_title_line_width: nil, cat_axis_title_line_dash: nil, cat_axis_title_rotation: nil, val_axis_title_font: nil, val_axis_title_fill: nil, val_axis_title_no_fill: nil, val_axis_title_line_color: nil, val_axis_title_line_width: nil, val_axis_title_line_dash: nil, val_axis_title_rotation: nil, cat_axis_tick_lbl_pos: nil, val_axis_tick_lbl_pos: nil, cat_axis_major_gridlines: nil, val_axis_major_gridlines: nil, cat_axis_minor_gridlines: nil, val_axis_minor_gridlines: nil, cat_axis_delete: nil, val_axis_delete: nil, cat_axis_orientation: nil, val_axis_orientation: nil, cat_axis_num_fmt: nil, val_axis_num_fmt: nil, cat_axis_major_tick_mark: nil, cat_axis_minor_tick_mark: nil, val_axis_major_tick_mark: nil, val_axis_minor_tick_mark: nil, cat_axis_crosses: nil, val_axis_crosses: nil, cat_axis_crosses_at: nil, val_axis_crosses_at: nil, cat_axis_tick_lbl_skip: nil, cat_axis_tick_mark_skip: nil, cat_axis_lbl_offset: nil, cat_axis_auto: nil, cat_axis_lbl_algn: nil, cat_axis_no_multi_lvl_lbl: nil, val_axis_cross_between: nil, val_axis_major_unit: nil, val_axis_minor_unit: nil, cat_axis_scaling_max: nil, cat_axis_scaling_min: nil, val_axis_scaling_max: nil, val_axis_scaling_min: nil, cat_axis_log_base: nil, val_axis_log_base: nil, val_axis_disp_units: nil, gap_width: nil, gap_depth: nil, overlap: nil, first_slice_ang: nil, hole_size: nil, smooth: nil, marker: nil, scatter_style: nil, radar_style: nil, bar_shape: nil, bubble_3d: nil, bubble_scale: nil, show_neg_bubbles: nil, size_represents: nil, wireframe: nil, grouping: nil, bar_dir: nil, vary_colors: nil, style: nil, rounded_corners: nil, view_3d: nil, cat_axis_pos: nil, val_axis_pos: nil, name: nil, description: nil, frame_title: nil, frame_hidden: nil, frame_macro: nil, frame_no_grp: nil, from_col: 0, from_row: 0, to_col: 10, to_row: 15, from_col_off: nil, from_row_off: nil, to_col_off: nil, to_row_off: nil, edit_as: nil, published: nil, locks_with_sheet: nil, prints_with_sheet: nil, plot_vis_only: nil, disp_blanks_as: nil, show_d_lbls_over_max: nil, data_table: nil, plot_area_fill: nil, plot_area_no_fill: nil, plot_area_line_color: nil, plot_area_line_width: nil, plot_area_line_dash: nil, plot_area_layout: nil, floor: nil, side_wall: nil, back_wall: nil, drop_lines: nil, hi_low_lines: nil, ser_lines: nil, up_down_bars: nil, band_fmts: nil, of_pie_type: nil, split_type: nil, split_pos: nil, cust_split: nil, second_pie_size: nil, cat_axis_label_rotation: nil, val_axis_label_rotation: nil, cat_axis_font: nil, val_axis_font: nil, cat_axis_line_color: nil, cat_axis_line_width: nil, cat_axis_line_dash: nil, val_axis_line_color: nil, val_axis_line_width: nil, val_axis_line_dash: nil, cat_axis_fill: nil, cat_axis_no_fill: nil, val_axis_fill: nil, val_axis_no_fill: nil, cat_axis_type: nil, cat_axis_base_time_unit: nil, cat_axis_major_time_unit: nil, cat_axis_minor_time_unit: nil, cat_axis_major_unit: nil, cat_axis_minor_unit: nil, chart_fill: nil, chart_no_fill: nil, chart_line_color: nil, chart_line_width: nil, chart_line_dash: nil, protection: nil, print_settings: nil, chart_font: nil, secondary_value_axis: nil, secondary_axis: nil, category_axis: nil, value_axis: nil, sheet: nil, **extra_options)
1283
1335
  sheet_name = sheet || @sheet_order.first
1284
1336
  raise ArgumentError, "unknown sheet: #{sheet_name}" unless @charts_data.key?(sheet_name)
1285
1337
 
@@ -1438,6 +1490,73 @@ module Xlsxrb
1438
1490
  chart[:protection] = protection if protection
1439
1491
  chart[:print_settings] = print_settings if print_settings
1440
1492
  chart[:chart_font] = chart_font if chart_font
1493
+ chart[:category_axis] = category_axis if category_axis
1494
+ chart[:value_axis] = value_axis if value_axis
1495
+ chart[:secondary_value_axis] = secondary_value_axis || secondary_axis if secondary_value_axis || secondary_axis
1496
+ chart.merge!(extra_options) if extra_options && !extra_options.empty?
1497
+
1498
+ if chart[:category_axis].is_a?(Hash)
1499
+ ca = chart[:category_axis]
1500
+ chart[:cat_axis_title] ||= ca[:title]
1501
+ chart[:cat_axis_num_fmt] ||= ca[:num_fmt]
1502
+ chart[:cat_axis_pos] ||= ca[:pos]
1503
+ chart[:cat_axis_major_gridlines] = ca[:major_gridlines] if chart[:cat_axis_major_gridlines].nil? && !ca[:major_gridlines].nil?
1504
+ chart[:cat_axis_minor_gridlines] = ca[:minor_gridlines] if chart[:cat_axis_minor_gridlines].nil? && !ca[:minor_gridlines].nil?
1505
+ chart[:cat_axis_font] ||= ca[:font]
1506
+ chart[:cat_axis_line_color] ||= ca[:line_color]
1507
+ chart[:cat_axis_line_width] ||= ca[:line_width]
1508
+ chart[:cat_axis_line_dash] ||= ca[:line_dash]
1509
+ chart[:cat_axis_scaling_min] ||= ca[:min]
1510
+ chart[:cat_axis_scaling_max] ||= ca[:max]
1511
+ chart[:cat_axis_label_rotation] ||= ca[:label_rotation] || ca[:rotation]
1512
+ end
1513
+
1514
+ if chart[:value_axis].is_a?(Hash)
1515
+ va = chart[:value_axis]
1516
+ chart[:val_axis_title] ||= va[:title]
1517
+ chart[:val_axis_num_fmt] ||= va[:num_fmt]
1518
+ chart[:val_axis_pos] ||= va[:pos]
1519
+ chart[:val_axis_major_gridlines] = va[:major_gridlines] if chart[:val_axis_major_gridlines].nil? && !va[:major_gridlines].nil?
1520
+ chart[:val_axis_minor_gridlines] = va[:minor_gridlines] if chart[:val_axis_minor_gridlines].nil? && !va[:minor_gridlines].nil?
1521
+ chart[:val_axis_font] ||= va[:font]
1522
+ chart[:val_axis_line_color] ||= va[:line_color]
1523
+ chart[:val_axis_line_width] ||= va[:line_width]
1524
+ chart[:val_axis_line_dash] ||= va[:line_dash]
1525
+ chart[:val_axis_scaling_min] ||= va[:min]
1526
+ chart[:val_axis_scaling_max] ||= va[:max]
1527
+ chart[:val_axis_major_unit] ||= va[:major_unit]
1528
+ chart[:val_axis_minor_unit] ||= va[:minor_unit]
1529
+ chart[:val_axis_label_rotation] ||= va[:label_rotation] || va[:rotation]
1530
+ end
1531
+
1532
+ if chart[:secondary_value_axis].is_a?(Hash)
1533
+ sva = chart[:secondary_value_axis]
1534
+ chart[:sec_val_axis_title] ||= sva[:title]
1535
+ chart[:sec_val_axis_num_fmt] ||= sva[:num_fmt]
1536
+ chart[:sec_val_axis_pos] ||= sva[:pos] || "r"
1537
+ chart[:sec_val_axis_major_gridlines] = sva[:major_gridlines] unless sva[:major_gridlines].nil?
1538
+ chart[:sec_val_axis_minor_gridlines] = sva[:minor_gridlines] unless sva[:minor_gridlines].nil?
1539
+ chart[:sec_val_axis_font] ||= sva[:font]
1540
+ chart[:sec_val_axis_line_color] ||= sva[:line_color]
1541
+ chart[:sec_val_axis_line_width] ||= sva[:line_width]
1542
+ chart[:sec_val_axis_line_dash] ||= sva[:line_dash]
1543
+ chart[:sec_val_axis_scaling_min] ||= sva[:min]
1544
+ chart[:sec_val_axis_scaling_max] ||= sva[:max]
1545
+ chart[:sec_val_axis_major_unit] ||= sva[:major_unit]
1546
+ chart[:sec_val_axis_minor_unit] ||= sva[:minor_unit]
1547
+ chart[:sec_val_axis_label_rotation] ||= sva[:label_rotation] || sva[:rotation]
1548
+ chart[:sec_val_axis_crosses] ||= sva[:crosses] || "max"
1549
+ chart[:sec_val_axis_crosses_at] ||= sva[:crosses_at]
1550
+ chart[:sec_val_axis_cross_between] ||= sva[:cross_between]
1551
+ chart[:sec_val_axis_delete] = sva[:delete] unless sva[:delete].nil?
1552
+ chart[:sec_val_axis_orientation] ||= sva[:orientation]
1553
+ chart[:sec_val_axis_log_base] ||= sva[:log_base]
1554
+ chart[:sec_val_axis_disp_units] ||= sva[:disp_units]
1555
+ chart[:sec_val_axis_major_tick_mark] ||= sva[:major_tick_mark]
1556
+ chart[:sec_val_axis_minor_tick_mark] ||= sva[:minor_tick_mark]
1557
+ chart[:sec_val_axis_tick_lbl_pos] ||= sva[:tick_lbl_pos]
1558
+ end
1559
+
1441
1560
  @charts_data[sheet_name] << chart
1442
1561
  end
1443
1562
 
@@ -1571,6 +1690,81 @@ module Xlsxrb
1571
1690
  @comments_data[sheet_name] || []
1572
1691
  end
1573
1692
 
1693
+ # Adds a threaded comment to a cell in the given sheet.
1694
+ # : (String | Integer cell_address, String text, ?author: untyped, ?timestamp: untyped, ?id: String?, ?parent_id: String?, ?done: bool?, ?user_id: String?, ?provider_id: String?, ?sheet: untyped?) -> Hash[Symbol, untyped]
1695
+ def add_threaded_comment(cell_address, text, author: "Author", timestamp: nil, id: nil, parent_id: nil, done: false, user_id: nil, provider_id: nil, sheet: nil)
1696
+ sheet_name = sheet || @sheet_order.first
1697
+ raise ArgumentError, "unknown sheet: #{sheet_name}" unless @threaded_comments_data.key?(sheet_name)
1698
+
1699
+ person = if author.is_a?(Hash)
1700
+ add_person(author[:display_name] || author[:name] || "Author", id: author[:id], user_id: author[:user_id], provider_id: author[:provider_id])
1701
+ else
1702
+ add_person(author, user_id: user_id, provider_id: provider_id)
1703
+ end
1704
+
1705
+ dt = case timestamp
1706
+ when Time, DateTime
1707
+ timestamp.to_time.utc.strftime("%Y-%m-%dT%H:%M:%SZ")
1708
+ when String
1709
+ timestamp
1710
+ else
1711
+ Time.now.utc.strftime("%Y-%m-%dT%H:%M:%SZ")
1712
+ end
1713
+
1714
+ comment_id = format_guid(id)
1715
+ parent_guid = parent_id ? format_guid(parent_id) : nil
1716
+
1717
+ entry = {
1718
+ cell: cell_address.to_s.upcase,
1719
+ ref: cell_address.to_s.upcase,
1720
+ text: text.to_s,
1721
+ author: person[:display_name],
1722
+ person_id: person[:id],
1723
+ id: comment_id,
1724
+ parent_id: parent_guid,
1725
+ timestamp: dt,
1726
+ dt: dt,
1727
+ done: done ? true : false
1728
+ }.compact
1729
+ @threaded_comments_data[sheet_name] << entry
1730
+ entry
1731
+ end
1732
+ alias threaded_comment add_threaded_comment
1733
+
1734
+ # Returns threaded comments for the first (or given) sheet.
1735
+ # : (?sheet: untyped?) -> Array[Hash[Symbol, untyped]]
1736
+ def threaded_comments(sheet: nil)
1737
+ sheet_name = sheet || @sheet_order.first
1738
+ @threaded_comments_data[sheet_name] || []
1739
+ end
1740
+
1741
+ # Registers a person in the workbook person list.
1742
+ # : (String name, ?id: String?, ?user_id: String?, ?provider_id: String?) -> Hash[Symbol, untyped]
1743
+ def add_person(name, id: nil, user_id: nil, provider_id: nil)
1744
+ person_name = name.to_s
1745
+ person_id = id ? format_guid(id) : nil
1746
+ existing = @persons_data.find do |p|
1747
+ (person_id && p[:id] == person_id) || p[:display_name] == person_name
1748
+ end
1749
+ return existing if existing
1750
+
1751
+ person = {
1752
+ id: person_id || format_guid(nil),
1753
+ display_name: person_name,
1754
+ user_id: user_id || "AD:#{person_name}",
1755
+ provider_id: provider_id || "AD"
1756
+ }
1757
+ @persons_data << person
1758
+ person
1759
+ end
1760
+
1761
+ # Returns the workbook person list.
1762
+ # : () -> Array[Hash[Symbol, untyped]]
1763
+ def persons
1764
+ @persons_data
1765
+ end
1766
+ alias person_list persons
1767
+
1574
1768
  # Adds a pivot table to the given sheet.
1575
1769
  # source_ref: data source range (e.g. "Sheet1!A1:C4").
1576
1770
  # row_fields: array of 0-based field indices for row axis.
@@ -1717,13 +1911,16 @@ module Xlsxrb
1717
1911
  sheet_charts = @charts_data[sheet_name] || []
1718
1912
  sheet_shapes = @shapes_data[sheet_name] || []
1719
1913
  sheet_comments = @comments_data[sheet_name] || []
1914
+ sheet_threaded_comments = @threaded_comments_data[sheet_name] || []
1720
1915
  sheet_pivots = @pivot_tables_data[sheet_name] || []
1721
1916
  has_drawing = sheet_images.any? || sheet_charts.any? || sheet_shapes.any?
1722
1917
  has_comments = sheet_comments.any?
1918
+ has_tc = sheet_threaded_comments.any?
1723
1919
 
1724
1920
  # Pre-increment counters so rels reference correct paths.
1725
1921
  sheet_drawing_idx = has_drawing ? (@drawing_count += 1) : nil
1726
1922
  sheet_comment_idx = has_comments ? (@comment_count += 1) : nil
1923
+ sheet_tc_idx = has_tc ? (@threaded_comment_count += 1) : nil
1727
1924
  sheet_pivot_start = @pivot_table_count
1728
1925
  sheet_cache_start = @pivot_cache_count
1729
1926
  sheet_pivots.each do
@@ -1736,7 +1933,8 @@ module Xlsxrb
1736
1933
  sheet_rels_parts = build_sheet_rels_parts_v2(
1737
1934
  sheet_name, sheet_tables, table_index,
1738
1935
  sheet_drawing_idx, sheet_comment_idx,
1739
- sheet_pivot_start, sheet_pivots.size
1936
+ sheet_pivot_start, sheet_pivots.size,
1937
+ sheet_tc_idx
1740
1938
  )
1741
1939
 
1742
1940
  # Calculate the legacyDrawing rId if comments exist.
@@ -1805,6 +2003,9 @@ module Xlsxrb
1805
2003
  entries["xl/drawings/vmlDrawing#{sheet_comment_idx}.vml"] = generate_vml_drawing_xml(sheet_comments)
1806
2004
  end
1807
2005
 
2006
+ # Generate threaded comments XML.
2007
+ entries["xl/threadedComments/threadedComment#{sheet_tc_idx}.xml"] = generate_threaded_comments_xml(sheet_threaded_comments) if has_tc
2008
+
1808
2009
  # Generate pivot table + cache entries.
1809
2010
  sheet_pivots.each_with_index do |pt, pi|
1810
2011
  cache_idx = sheet_cache_start + pi + 1
@@ -1836,6 +2037,9 @@ module Xlsxrb
1836
2037
  entries["xl/externalLinks/_rels/externalLink#{link_num}.xml.rels"] = generate_external_link_rels(el)
1837
2038
  end
1838
2039
 
2040
+ # Generate persons entry if any persons registered.
2041
+ entries["xl/persons/person.xml"] = generate_persons_xml(@persons_data) if @persons_data.any?
2042
+
1839
2043
  # Generate workbook rels (needs to know pivot cache count).
1840
2044
  entries["xl/_rels/workbook.xml.rels"] = generate_workbook_rels(has_calc_chain: entries.key?("xl/calcChain.xml"))
1841
2045
 
@@ -1866,6 +2070,8 @@ module Xlsxrb
1866
2070
  ends_with: "endsWith",
1867
2071
  contains_blanks: "containsBlanks",
1868
2072
  not_contains_blanks: "notContainsBlanks",
2073
+ contains_errors: "containsErrors",
2074
+ not_contains_errors: "notContainsErrors",
1869
2075
  time_period: "timePeriod"
1870
2076
  }.freeze
1871
2077
 
@@ -1879,7 +2085,8 @@ module Xlsxrb
1879
2085
  pie3d: "pie3DChart", area3d: "area3DChart", surface: "surfaceChart",
1880
2086
  surface3d: "surface3DChart",
1881
2087
  stock: "stockChart", bubble: "bubbleChart",
1882
- of_pie: "ofPieChart"
2088
+ of_pie: "ofPieChart",
2089
+ combo: "comboChart", column: "barChart"
1883
2090
  }.freeze
1884
2091
 
1885
2092
  NO_AXIS_CHARTS = %w[pieChart doughnutChart pie3DChart ofPieChart].freeze
@@ -1959,6 +2166,14 @@ module Xlsxrb
1959
2166
  overrides["/xl/comments#{c}.xml"] = "application/vnd.openxmlformats-officedocument.spreadsheetml.comments+xml"
1960
2167
  end
1961
2168
 
2169
+ # Threaded comments.
2170
+ (1..@threaded_comment_count.to_i).each do |tc|
2171
+ overrides["/xl/threadedComments/threadedComment#{tc}.xml"] = "application/vnd.ms-excel.threadedcomments+xml"
2172
+ end
2173
+
2174
+ # Persons.
2175
+ overrides["/xl/persons/person.xml"] = "application/vnd.ms-excel.person+xml" if @persons_data.any?
2176
+
1962
2177
  # Pivot tables and cache.
1963
2178
  (1..@pivot_table_count.to_i).each do |p|
1964
2179
  overrides["/xl/pivotTables/pivotTable#{p}.xml"] = "application/vnd.openxmlformats-officedocument.spreadsheetml.pivotTable+xml"
@@ -2247,6 +2462,10 @@ module Xlsxrb
2247
2462
  parts << %(<Relationship Id="rId#{next_rid}" Type="#{DOC_REL_NS}/calcChain" Target="calcChain.xml"/>)
2248
2463
  next_rid += 1
2249
2464
  end
2465
+ if @persons_data.any?
2466
+ parts << %(<Relationship Id="rId#{next_rid}" Type="http://schemas.microsoft.com/office/2017/10/relationships/person" Target="persons/person.xml"/>)
2467
+ next_rid += 1
2468
+ end
2250
2469
  parts << "</Relationships>"
2251
2470
  parts.join
2252
2471
  end
@@ -2292,8 +2511,17 @@ module Xlsxrb
2292
2511
  sp_attrs << 'published="0"' if sheet_props[:published] == false
2293
2512
  sp_attrs << 'enableFormatConditionsCalculation="0"' if sheet_props[:enable_format_conditions_calculation] == false
2294
2513
  sp_children = []
2295
- if sheet_props[:tab_color]
2296
- sp_children << %(<tabColor rgb="#{sheet_props[:tab_color]}"/>)
2514
+ tc = sheet_props[:tab_color]
2515
+ if tc.is_a?(Hash)
2516
+ tc_attrs = []
2517
+ tc_attrs << 'auto="1"' if tc[:auto]
2518
+ tc_attrs << %(indexed="#{tc[:indexed]}") if tc[:indexed]
2519
+ tc_attrs << %(rgb="#{tc[:rgb].to_s.delete_prefix("#")}") if tc[:rgb]
2520
+ tc_attrs << %(theme="#{tc[:theme]}") if tc[:theme]
2521
+ tc_attrs << %(tint="#{tc[:tint]}") if tc[:tint]
2522
+ sp_children << "<tabColor #{tc_attrs.join(" ")}/>" unless tc_attrs.empty?
2523
+ elsif tc
2524
+ sp_children << %(<tabColor rgb="#{tc.to_s.delete_prefix("#")}"/>)
2297
2525
  elsif sheet_props[:tab_color_theme]
2298
2526
  tc_attrs = [%(theme="#{sheet_props[:tab_color_theme]}")]
2299
2527
  tc_attrs << %(tint="#{sheet_props[:tab_color_tint]}") if sheet_props[:tab_color_tint]
@@ -2789,7 +3017,7 @@ module Xlsxrb
2789
3017
 
2790
3018
  # Emit <rowBreaks> if defined.
2791
3019
  unless sheet_rb.empty?
2792
- manual_count = sheet_rb.count { |r| r.is_a?(Hash) ? r.fetch(:man, true) : true }
3020
+ manual_count = sheet_rb.count { |r| r.is_a?(Hash) || r.respond_to?(:fetch) ? r.fetch(:man, true) : true }
2793
3021
  parts << %(<rowBreaks count="#{sheet_rb.size}" manualBreakCount="#{manual_count}">)
2794
3022
  sheet_rb.each { |r| parts << emit_brk_xml(r, default_max: 16_383) }
2795
3023
  parts << "</rowBreaks>"
@@ -2797,7 +3025,7 @@ module Xlsxrb
2797
3025
 
2798
3026
  # Emit <colBreaks> if defined.
2799
3027
  unless sheet_cb.empty?
2800
- manual_count = sheet_cb.count { |c| c.is_a?(Hash) ? c.fetch(:man, true) : true }
3028
+ manual_count = sheet_cb.count { |c| c.is_a?(Hash) || c.respond_to?(:fetch) ? c.fetch(:man, true) : true }
2801
3029
  parts << %(<colBreaks count="#{sheet_cb.size}" manualBreakCount="#{manual_count}">)
2802
3030
  sheet_cb.each { |c| parts << emit_brk_xml(c, default_max: 1_048_575) }
2803
3031
  parts << "</colBreaks>"
@@ -2920,24 +3148,34 @@ module Xlsxrb
2920
3148
  table_attrs << %( tableType="#{xml_escape(tbl[:table_type])}") if tbl[:table_type]
2921
3149
  parts = [
2922
3150
  XML_HEADER,
2923
- "<table #{table_attrs}>",
2924
- %(<autoFilter ref="#{tbl[:ref]}"/>),
2925
- %(<tableColumns count="#{tbl[:columns].size}">)
3151
+ "<table #{table_attrs}>"
2926
3152
  ]
3153
+ parts << %(<autoFilter ref="#{tbl[:ref]}"/>) unless tbl[:auto_filter] == false
3154
+ parts << %(<tableColumns count="#{tbl[:columns].size}">)
2927
3155
  tbl[:columns].each_with_index do |col, i|
2928
- col_name = col.is_a?(Hash) ? col[:name] : col
3156
+ col = col.to_h if col.is_a?(Elements::MetadataRecord)
3157
+ col_name = if col.is_a?(Hash)
3158
+ col[:name]
3159
+ elsif col.is_a?(Elements::TableColumn)
3160
+ col.name
3161
+ else
3162
+ col
3163
+ end
2929
3164
  col_attrs = %(id="#{i + 1}" name="#{xml_escape(col_name)}")
2930
- if col.is_a?(Hash)
2931
- col_attrs << %( totalsRowFunction="#{col[:totals_row_function]}") if col[:totals_row_function]
3165
+ if col.is_a?(Hash) || col.is_a?(Elements::TableColumn)
3166
+ calc_formula = col[:calculated_column_formula] || col[:data_formula] || col[:formula]
3167
+ tot_formula = col[:totals_row_formula] || col[:total_row_formula] || col[:total_formula]
3168
+ trf = col[:totals_row_function] || ("custom" if tot_formula)
3169
+ col_attrs << %( totalsRowFunction="#{trf}") if trf
2932
3170
  col_attrs << %( totalsRowLabel="#{xml_escape(col[:totals_row_label])}") if col[:totals_row_label]
2933
3171
  col_attrs << %( dataDxfId="#{col[:data_dxf_id]}") if col[:data_dxf_id]
2934
3172
  col_attrs << %( totalsRowDxfId="#{col[:totals_row_dxf_id]}") if col[:totals_row_dxf_id]
2935
3173
  col_attrs << %( headerRowDxfId="#{col[:header_row_dxf_id]}") if col[:header_row_dxf_id]
2936
3174
  col_attrs << %( dataCellStyle="#{xml_escape(col[:data_cell_style])}") if col[:data_cell_style]
2937
- if col[:calculated_column_formula] || col[:totals_row_formula]
3175
+ if calc_formula || tot_formula
2938
3176
  parts << "<tableColumn #{col_attrs}>"
2939
- parts << "<calculatedColumnFormula>#{xml_escape(col[:calculated_column_formula])}</calculatedColumnFormula>" if col[:calculated_column_formula]
2940
- parts << "<totalsRowFormula>#{xml_escape(col[:totals_row_formula])}</totalsRowFormula>" if col[:totals_row_formula]
3177
+ parts << "<calculatedColumnFormula>#{xml_escape(calc_formula.to_s)}</calculatedColumnFormula>" if calc_formula
3178
+ parts << "<totalsRowFormula>#{xml_escape(tot_formula.to_s)}</totalsRowFormula>" if tot_formula
2941
3179
  parts << "</tableColumn>"
2942
3180
  else
2943
3181
  parts << "<tableColumn #{col_attrs}/>"
@@ -2947,16 +3185,30 @@ module Xlsxrb
2947
3185
  end
2948
3186
  end
2949
3187
  parts << "</tableColumns>"
2950
- style = tbl[:style] || {}
3188
+ raw_style = tbl[:style]
3189
+ style = if raw_style.is_a?(Hash)
3190
+ raw_style
3191
+ elsif raw_style
3192
+ { name: raw_style.to_s }
3193
+ else
3194
+ {}
3195
+ end
2951
3196
  style_name = style[:name] || "TableStyleMedium2"
2952
- sfc = style[:show_first_column] ? "1" : "0"
2953
- slc = style[:show_last_column] ? "1" : "0"
2954
- srs = if style.key?(:show_row_stripes)
2955
- style[:show_row_stripes] ? "1" : "0"
2956
- else
2957
- "1"
2958
- end
2959
- scs = style[:show_column_stripes] ? "1" : "0"
3197
+ show_first_column = style.key?(:show_first_column) ? style[:show_first_column] : tbl[:show_first_column]
3198
+ show_last_column = style.key?(:show_last_column) ? style[:show_last_column] : tbl[:show_last_column]
3199
+ show_row_stripes = if style.key?(:show_row_stripes)
3200
+ style[:show_row_stripes]
3201
+ elsif tbl.key?(:show_row_stripes)
3202
+ tbl[:show_row_stripes]
3203
+ else
3204
+ true
3205
+ end
3206
+ show_column_stripes = style.key?(:show_column_stripes) ? style[:show_column_stripes] : tbl[:show_column_stripes]
3207
+
3208
+ sfc = show_first_column ? "1" : "0"
3209
+ slc = show_last_column ? "1" : "0"
3210
+ srs = show_row_stripes ? "1" : "0"
3211
+ scs = show_column_stripes ? "1" : "0"
2960
3212
  parts << %(<tableStyleInfo name="#{xml_escape(style_name)}" showFirstColumn="#{sfc}" showLastColumn="#{slc}" showRowStripes="#{srs}" showColumnStripes="#{scs}"/>)
2961
3213
  parts << "</table>"
2962
3214
  parts.join
@@ -2983,8 +3235,8 @@ module Xlsxrb
2983
3235
  parts.join
2984
3236
  end
2985
3237
 
2986
- # : (untyped sheet_name, untyped sheet_tables, untyped table_start_index, untyped drawing_idx, untyped comment_idx, untyped pivot_start, untyped pivot_count) -> untyped
2987
- def build_sheet_rels_parts_v2(sheet_name, sheet_tables, table_start_index, drawing_idx, comment_idx, pivot_start, pivot_count)
3238
+ # : (untyped sheet_name, untyped sheet_tables, untyped table_start_index, untyped drawing_idx, untyped comment_idx, untyped pivot_start, untyped pivot_count, ?untyped? threaded_comment_idx) -> untyped
3239
+ def build_sheet_rels_parts_v2(sheet_name, sheet_tables, table_start_index, drawing_idx, comment_idx, pivot_start, pivot_count, threaded_comment_idx = nil)
2988
3240
  rels = []
2989
3241
  @hyperlinks[sheet_name].each do |(_cell_ref, link)|
2990
3242
  next unless link[:url]
@@ -2998,6 +3250,7 @@ module Xlsxrb
2998
3250
  rels << { type: "#{DOC_REL_NS}/comments", target: "../comments#{comment_idx}.xml" }
2999
3251
  rels << { type: "#{DOC_REL_NS}/vmlDrawing", target: "../drawings/vmlDrawing#{comment_idx}.vml" }
3000
3252
  end
3253
+ rels << { type: "http://schemas.microsoft.com/office/2017/10/relationships/threadedComment", target: "../threadedComments/threadedComment#{threaded_comment_idx}.xml" } if threaded_comment_idx
3001
3254
  rels << { type: "#{DOC_REL_NS}/drawing", target: "../drawings/drawing#{drawing_idx}.xml" } if drawing_idx
3002
3255
  pivot_count.times do |i|
3003
3256
  pt_idx = pivot_start + i + 1
@@ -7,6 +7,8 @@ require "zlib"
7
7
  module Xlsxrb
8
8
  module Ooxml
9
9
  # Generates a simple ZIP file using only the standard library.
10
+ #
11
+ # @api private
10
12
  class ZipGenerator
11
13
  def initialize(filepath)
12
14
  @filepath = filepath
@@ -233,7 +233,7 @@ module Xlsxrb
233
233
  else
234
234
  source
235
235
  end
236
- reader = new(io, max_uncompressed_size: max_uncompressed_size, should_close_io: should_close)
236
+ reader = new(io, max_uncompressed_size: max_uncompressed_size, should_close_io: should_close, filepath: (source if should_close))
237
237
  if block_given?
238
238
  begin
239
239
  yield reader
@@ -245,11 +245,12 @@ module Xlsxrb
245
245
  end
246
246
  end
247
247
 
248
- #: (untyped io, ?max_uncompressed_size: Integer, ?should_close_io: bool) -> void
249
- def initialize(io, max_uncompressed_size: MAX_UNCOMPRESSED_SIZE, should_close_io: false)
248
+ #: (untyped io, ?max_uncompressed_size: Integer, ?should_close_io: bool, ?filepath: String?) -> void
249
+ def initialize(io, max_uncompressed_size: MAX_UNCOMPRESSED_SIZE, should_close_io: false, filepath: nil)
250
250
  @raw_io = io
251
251
  @max_uncompressed_size = max_uncompressed_size
252
252
  @should_close_io = should_close_io
253
+ @filepath = filepath
253
254
  @tempfile = nil
254
255
  @io = nil
255
256
  @catalog = nil
@@ -279,8 +280,15 @@ module Xlsxrb
279
280
  cached ||= @cached_entries[entry.name] if @cached_entries&.key?(entry.name)
280
281
  return normalize_text_encoding(cached) if cached
281
282
 
282
- io.seek(entry.data_offset, IO::SEEK_SET)
283
- raw = io.read(entry.compressed_size)
283
+ raw = if @should_close_io && @raw_io.respond_to?(:closed?) && @raw_io.closed? && @filepath
284
+ File.open(@filepath, "rb") do |f|
285
+ f.seek(entry.data_offset, IO::SEEK_SET)
286
+ f.read(entry.compressed_size)
287
+ end
288
+ else
289
+ io.seek(entry.data_offset, IO::SEEK_SET)
290
+ io.read(entry.compressed_size)
291
+ end
284
292
  decompress(raw, entry.method)
285
293
  end
286
294
 
@@ -323,11 +331,40 @@ module Xlsxrb
323
331
  def each_entry_chunk(entry_name, chunk_size: 65_536, encoding: nil, &block)
324
332
  return enum_for(:each_entry_chunk, entry_name, chunk_size: chunk_size, encoding: encoding) unless block
325
333
 
326
- stream = open_entry_io(entry_name, encoding: encoding)
327
- begin
328
- stream.each_chunk(chunk_size, &block)
329
- ensure
330
- stream.close
334
+ if @should_close_io && @raw_io.respond_to?(:closed?) && @raw_io.closed? && @filepath
335
+ File.open(@filepath, "rb") do |f|
336
+ entry = lookup_entry(entry_name)
337
+ raise ZipError, "Entry not found in archive: #{entry_name}" unless entry
338
+
339
+ resolved_encoding = if encoding == false
340
+ nil
341
+ elsif encoding
342
+ encoding.is_a?(String) ? Encoding.find(encoding) : encoding
343
+ elsif entry_name.end_with?(".xml", ".rels") || entry.name.end_with?(".xml", ".rels")
344
+ Encoding::UTF_8
345
+ end
346
+
347
+ stream = EntryStreamIO.new(
348
+ f,
349
+ entry.data_offset,
350
+ entry.compressed_size,
351
+ entry.method,
352
+ max_uncompressed_size: @max_uncompressed_size,
353
+ encoding: resolved_encoding
354
+ )
355
+ begin
356
+ stream.each_chunk(chunk_size, &block)
357
+ ensure
358
+ stream.close
359
+ end
360
+ end
361
+ else
362
+ stream = open_entry_io(entry_name, encoding: encoding)
363
+ begin
364
+ stream.each_chunk(chunk_size, &block)
365
+ ensure
366
+ stream.close
367
+ end
331
368
  end
332
369
  end
333
370