xlsxrb 0.1.17 → 0.2.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +256 -1
- data/README.md +111 -28
- data/lib/ruby_lsp/xlsxrb/completion_listener.rb +439 -139
- data/lib/xlsxrb/chart_builder.rb +540 -193
- data/lib/xlsxrb/dsl_helpers.rb +178 -73
- data/lib/xlsxrb/elements/cell.rb +197 -130
- data/lib/xlsxrb/elements/column.rb +88 -7
- data/lib/xlsxrb/elements/coordinate_access.rb +86 -59
- data/lib/xlsxrb/elements/image.rb +18 -19
- data/lib/xlsxrb/elements/metadata.rb +2379 -0
- data/lib/xlsxrb/elements/row.rb +84 -118
- data/lib/xlsxrb/elements/styles.rb +140 -90
- data/lib/xlsxrb/elements/types.rb +164 -22
- data/lib/xlsxrb/elements/workbook.rb +122 -140
- data/lib/xlsxrb/elements/worksheet.rb +451 -226
- data/lib/xlsxrb/elements.rb +1 -0
- data/lib/xlsxrb/ooxml/reader/listeners/core_listeners.rb +16 -5
- data/lib/xlsxrb/ooxml/reader/listeners/drawing_listeners.rb +14 -9
- data/lib/xlsxrb/ooxml/reader/listeners/feature_listeners.rb +296 -34
- data/lib/xlsxrb/ooxml/reader/listeners/style_listeners.rb +17 -3
- data/lib/xlsxrb/ooxml/reader.rb +52 -50
- data/lib/xlsxrb/ooxml/styles_parser.rb +36 -5
- data/lib/xlsxrb/ooxml/utils.rb +2 -2
- data/lib/xlsxrb/ooxml/workbook_parser.rb +0 -1
- data/lib/xlsxrb/ooxml/workbook_writer.rb +242 -109
- data/lib/xlsxrb/ooxml/worksheet_parser.rb +63 -31
- data/lib/xlsxrb/ooxml/worksheet_writer.rb +119 -56
- data/lib/xlsxrb/ooxml/writer/drawing_xml.rb +33 -13
- data/lib/xlsxrb/ooxml/writer/features_xml.rb +75 -15
- data/lib/xlsxrb/ooxml/writer/styles_xml.rb +18 -8
- data/lib/xlsxrb/ooxml/writer.rb +124 -44
- data/lib/xlsxrb/ooxml/xml_parser.rb +78 -5
- data/lib/xlsxrb/ooxml/zip_generator.rb +2 -0
- data/lib/xlsxrb/ooxml/zip_reader.rb +112 -25
- data/lib/xlsxrb/ooxml/zip_writer.rb +119 -30
- data/lib/xlsxrb/stream_row.rb +56 -81
- data/lib/xlsxrb/stream_sheet.rb +542 -273
- data/lib/xlsxrb/stream_writer.rb +1536 -870
- data/lib/xlsxrb/style_builder.rb +667 -221
- data/lib/xlsxrb/version.rb +1 -1
- data/lib/xlsxrb/workbook_builder.rb +406 -143
- data/lib/xlsxrb/worksheet_builder.rb +1009 -900
- data/lib/xlsxrb.rb +1179 -1056
- data/sig/generated/xlsxrb/chart_builder.rbs +385 -159
- data/sig/generated/xlsxrb/dsl_helpers.rbs +81 -15
- data/sig/generated/xlsxrb/elements/cell.rbs +78 -70
- data/sig/generated/xlsxrb/elements/column.rbs +55 -3
- data/sig/generated/xlsxrb/elements/coordinate_access.rbs +35 -29
- data/sig/generated/xlsxrb/elements/image.rbs +7 -11
- data/sig/generated/xlsxrb/elements/metadata.rbs +1574 -0
- data/sig/generated/xlsxrb/elements/row.rbs +39 -42
- data/sig/generated/xlsxrb/elements/styles.rbs +66 -66
- data/sig/generated/xlsxrb/elements/types.rbs +27 -0
- data/sig/generated/xlsxrb/elements/workbook.rbs +46 -99
- data/sig/generated/xlsxrb/elements/worksheet.rbs +121 -96
- data/sig/generated/xlsxrb/ooxml/reader/listeners/feature_listeners.rbs +61 -4
- data/sig/generated/xlsxrb/ooxml/reader.rbs +2 -2
- data/sig/generated/xlsxrb/ooxml/styles_parser.rbs +1 -1
- data/sig/generated/xlsxrb/ooxml/utils.rbs +3 -3
- data/sig/generated/xlsxrb/ooxml/workbook_writer.rbs +13 -1
- data/sig/generated/xlsxrb/ooxml/worksheet_parser.rbs +16 -0
- data/sig/generated/xlsxrb/ooxml/worksheet_writer.rbs +6 -4
- data/sig/generated/xlsxrb/ooxml/writer/features_xml.rbs +7 -0
- data/sig/generated/xlsxrb/ooxml/writer.rbs +22 -13
- data/sig/generated/xlsxrb/ooxml/xml_parser.rbs +70 -0
- data/sig/generated/xlsxrb/ooxml/zip_generator.rbs +2 -0
- data/sig/generated/xlsxrb/ooxml/zip_reader.rbs +24 -9
- data/sig/generated/xlsxrb/ooxml/zip_writer.rbs +26 -1
- data/sig/generated/xlsxrb/stream_row.rbs +32 -33
- data/sig/generated/xlsxrb/stream_sheet.rbs +233 -181
- data/sig/generated/xlsxrb/stream_writer.rbs +961 -667
- data/sig/generated/xlsxrb/style_builder.rbs +402 -128
- data/sig/generated/xlsxrb/workbook_builder.rbs +223 -71
- data/sig/generated/xlsxrb/worksheet_builder.rbs +579 -453
- data/sig/generated/xlsxrb.rbs +205 -144
- data/sig/rexml.rbs +8 -0
- metadata +5 -5
- data/lib/xlsxrb/utils.rb +0 -291
- data/sig/generated/xlsxrb/utils.rbs +0 -184
data/lib/xlsxrb/ooxml/writer.rb
CHANGED
|
@@ -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
|
|
@@ -561,9 +563,13 @@ module Xlsxrb
|
|
|
561
563
|
name = opts[:name]
|
|
562
564
|
end
|
|
563
565
|
|
|
564
|
-
font = @fonts[0] ? @fonts[0].dup : { name: "Calibri", sz: 11 }
|
|
566
|
+
font = @fonts[0] ? @fonts[0].dup : { name: "Calibri", sz: 11, size: 11 }
|
|
565
567
|
font[:name] = (name || opts[:name]).to_s if name || opts[:name]
|
|
566
|
-
|
|
568
|
+
sz_val = size || opts[:size] || opts[:sz]
|
|
569
|
+
if sz_val
|
|
570
|
+
font[:sz] = sz_val
|
|
571
|
+
font[:size] = sz_val
|
|
572
|
+
end
|
|
567
573
|
font[:family] = opts[:family] if opts.key?(:family)
|
|
568
574
|
font[:charset] = opts[:charset] if opts.key?(:charset)
|
|
569
575
|
font[:scheme] = opts[:scheme].to_s if opts.key?(:scheme)
|
|
@@ -575,7 +581,6 @@ module Xlsxrb
|
|
|
575
581
|
|
|
576
582
|
@fonts[0] = font
|
|
577
583
|
end
|
|
578
|
-
alias set_default_font default_font
|
|
579
584
|
|
|
580
585
|
# Sets the indexed colors palette (array of ARGB hex strings, e.g. ["FF000000", "FFFFFFFF"]).
|
|
581
586
|
# rubocop:disable Naming/AccessorMethodName
|
|
@@ -739,13 +744,14 @@ module Xlsxrb
|
|
|
739
744
|
(@sheet_views[sheet_name] || {}).dup
|
|
740
745
|
end
|
|
741
746
|
|
|
742
|
-
# Sets a freeze pane. row: rows to freeze from top,
|
|
743
|
-
# : (?row: ::Integer, ?col: ::Integer
|
|
744
|
-
def set_freeze_pane(row: 0, col:
|
|
747
|
+
# Sets a freeze pane. row: rows to freeze from top, column: columns to freeze from left.
|
|
748
|
+
# : (?row: ::Integer, ?col: ::Integer?, ?column: ::Integer?, ?sheet: untyped?) -> untyped
|
|
749
|
+
def set_freeze_pane(row: 0, col: nil, column: nil, sheet: nil)
|
|
745
750
|
sheet_name = sheet || @sheet_order.first
|
|
746
751
|
raise ArgumentError, "unknown sheet: #{sheet_name}" unless @freeze_panes.key?(sheet_name)
|
|
747
752
|
|
|
748
|
-
|
|
753
|
+
col_val = column || col || 0
|
|
754
|
+
@freeze_panes[sheet_name] = { row: row, column: col_val, state: :frozen }
|
|
749
755
|
end
|
|
750
756
|
|
|
751
757
|
# Sets a split pane (non-frozen). x_split/y_split are in 1/20th of a point (twips).
|
|
@@ -925,9 +931,15 @@ module Xlsxrb
|
|
|
925
931
|
|
|
926
932
|
normalized_list = DslHelpers.normalize_conditional_format(sqref, **opts, &)
|
|
927
933
|
normalized_list.each do |rule|
|
|
928
|
-
if (rule[:dxf] || rule[:font_color] || rule[:fill_color] || rule[:bold] || rule[:italic]) && rule[:format_id].nil?
|
|
934
|
+
if (rule[:dxf] || rule[:font_color] || rule[:fill_color] || rule[:bold] || rule[:italic]) && (rule[:dxf_id] || rule[:format_id]).nil?
|
|
929
935
|
dxf = rule.delete(:dxf) || DslHelpers.extract_dxf_from_rule!(rule)
|
|
930
|
-
|
|
936
|
+
did = @dxfs.index(dxf) || add_dxf(**dxf) if dxf
|
|
937
|
+
rule[:dxf_id] = did
|
|
938
|
+
rule[:format_id] = did
|
|
939
|
+
elsif rule[:dxf_id] && rule[:format_id].nil?
|
|
940
|
+
rule[:format_id] = rule[:dxf_id]
|
|
941
|
+
elsif rule[:format_id] && rule[:dxf_id].nil?
|
|
942
|
+
rule[:dxf_id] = rule[:format_id]
|
|
931
943
|
end
|
|
932
944
|
@conditional_formats[sheet_name] << rule
|
|
933
945
|
end
|
|
@@ -1662,8 +1674,8 @@ module Xlsxrb
|
|
|
1662
1674
|
end
|
|
1663
1675
|
|
|
1664
1676
|
# Adds a comment on a cell.
|
|
1665
|
-
# : (untyped cell_address, untyped text, ?author: ::String, ?sheet: untyped?, ?guid: untyped?, ?shape_id: untyped?) -> untyped
|
|
1666
|
-
def add_comment(cell_address, text, author: "Author", sheet: nil, guid: nil, shape_id: nil)
|
|
1677
|
+
# : (untyped cell_address, untyped text, ?author: ::String, ?sheet: untyped?, ?guid: untyped?, ?shape_id: untyped?, ?visible: bool, ?anchor: Array[Integer]?) -> untyped
|
|
1678
|
+
def add_comment(cell_address, text, author: "Author", sheet: nil, guid: nil, shape_id: nil, visible: false, anchor: nil)
|
|
1667
1679
|
validate_cell_address!(cell_address)
|
|
1668
1680
|
sheet_name = sheet || @sheet_order.first
|
|
1669
1681
|
raise ArgumentError, "unknown sheet: #{sheet_name}" unless @comments_data.key?(sheet_name)
|
|
@@ -1671,6 +1683,8 @@ module Xlsxrb
|
|
|
1671
1683
|
entry = { ref: cell_address, text: text, author: author }
|
|
1672
1684
|
entry[:guid] = guid if guid
|
|
1673
1685
|
entry[:shape_id] = shape_id if shape_id
|
|
1686
|
+
entry[:visible] = true if visible
|
|
1687
|
+
entry[:anchor] = anchor if anchor
|
|
1674
1688
|
@comments_data[sheet_name] << entry
|
|
1675
1689
|
end
|
|
1676
1690
|
|
|
@@ -1757,22 +1771,27 @@ module Xlsxrb
|
|
|
1757
1771
|
alias person_list persons
|
|
1758
1772
|
|
|
1759
1773
|
# Adds a pivot table to the given sheet.
|
|
1760
|
-
# source_ref: data source range (e.g. "Sheet1!A1:C4").
|
|
1761
|
-
# row_fields: array of 0-based field indices for row axis.
|
|
1762
|
-
# data_fields: array of { fld:, name:, subtotal: } hashes
|
|
1763
|
-
#
|
|
1774
|
+
# source_ref: data source range (e.g. "Sheet1!A1:C4"), or nil with source_name: for a table source.
|
|
1775
|
+
# row_fields: array of 0-based field indices, or field names listed in field_names, for row axis.
|
|
1776
|
+
# data_fields: array of { fld:, name:, subtotal: } hashes ({ field: } takes a field name or index
|
|
1777
|
+
# in place of fld:), or field names.
|
|
1778
|
+
# col_fields: array of 0-based field indices, or field names, for column axis.
|
|
1764
1779
|
# field_names: array of field name strings (for cache definition).
|
|
1765
1780
|
# items: hash mapping field index to array of item values.
|
|
1766
|
-
# : (untyped source_ref, row_fields: untyped, data_fields: untyped, ?col_fields: untyped, ?dest_ref:
|
|
1767
|
-
def add_pivot_table(source_ref, row_fields:, data_fields:, col_fields:
|
|
1781
|
+
# : (untyped source_ref, row_fields: untyped, data_fields: untyped, ?col_fields: untyped, ?column_fields: untyped, ?dest_ref: untyped, ?destination: untyped, ?name: untyped?, ?field_names: untyped?, ?items: untyped?, ?sheet: untyped?, **untyped opts) -> untyped
|
|
1782
|
+
def add_pivot_table(source_ref, row_fields:, data_fields:, col_fields: nil, column_fields: nil, dest_ref: nil, destination: nil, name: nil, field_names: nil, items: nil, sheet: nil, **opts)
|
|
1768
1783
|
sheet_name = sheet || @sheet_order.first
|
|
1769
1784
|
raise ArgumentError, "unknown sheet: #{sheet_name}" unless @pivot_tables_data.key?(sheet_name)
|
|
1770
1785
|
|
|
1771
1786
|
pt_name = name || "PivotTable#{@pivot_tables_data.values.flatten.size + 1}"
|
|
1787
|
+
row_fields = row_fields.map { |f| resolve_pivot_field(f, field_names) }
|
|
1788
|
+
c_fields = (column_fields || col_fields || []).map { |f| resolve_pivot_field(f, field_names) }
|
|
1789
|
+
data_fields = data_fields.map { |df| resolve_pivot_data_field(df, field_names) }
|
|
1790
|
+
target_dest = destination || dest_ref || "E1"
|
|
1772
1791
|
@pivot_tables_data[sheet_name] << {
|
|
1773
1792
|
name: pt_name, source_ref: source_ref,
|
|
1774
|
-
row_fields: row_fields, col_fields:
|
|
1775
|
-
data_fields: data_fields, dest_ref:
|
|
1793
|
+
row_fields: row_fields, col_fields: c_fields, column_fields: c_fields,
|
|
1794
|
+
data_fields: data_fields, dest_ref: target_dest, destination: target_dest,
|
|
1776
1795
|
field_names: field_names, items: items,
|
|
1777
1796
|
data_caption: opts[:data_caption], data_on_rows: opts[:data_on_rows],
|
|
1778
1797
|
row_grand_totals: opts[:row_grand_totals], col_grand_totals: opts[:col_grand_totals],
|
|
@@ -1789,6 +1808,7 @@ module Xlsxrb
|
|
|
1789
1808
|
cache_created_version: opts[:cache_created_version], cache_record_count: opts[:cache_record_count],
|
|
1790
1809
|
cache_optimize_memory: opts[:cache_optimize_memory],
|
|
1791
1810
|
row_page_count: opts[:row_page_count], col_page_count: opts[:col_page_count],
|
|
1811
|
+
first_header_row: opts[:first_header_row], first_data_row: opts[:first_data_row], first_data_col: opts[:first_data_col],
|
|
1792
1812
|
field_attrs: opts[:field_attrs],
|
|
1793
1813
|
apply_number_formats: opts[:apply_number_formats],
|
|
1794
1814
|
apply_border_formats: opts[:apply_border_formats],
|
|
@@ -1817,6 +1837,35 @@ module Xlsxrb
|
|
|
1817
1837
|
}
|
|
1818
1838
|
end
|
|
1819
1839
|
|
|
1840
|
+
# Resolves a pivot table field given as a 0-based index or as a name in field_names.
|
|
1841
|
+
# : (untyped field, untyped field_names) -> Integer
|
|
1842
|
+
def resolve_pivot_field(field, field_names)
|
|
1843
|
+
return field if field.is_a?(Integer)
|
|
1844
|
+
raise ArgumentError, "pivot table field #{field.inspect} is a name; pass field_names: to resolve it" unless field_names
|
|
1845
|
+
|
|
1846
|
+
index = field_names.index(field.to_s)
|
|
1847
|
+
raise ArgumentError, "pivot table field #{field.inspect} is not in field_names #{field_names.inspect}" unless index
|
|
1848
|
+
|
|
1849
|
+
index
|
|
1850
|
+
end
|
|
1851
|
+
private :resolve_pivot_field
|
|
1852
|
+
|
|
1853
|
+
# Normalizes a pivot table data field to a Hash with an Integer fld.
|
|
1854
|
+
# : (untyped data_field, untyped field_names) -> Hash[Symbol, untyped]
|
|
1855
|
+
def resolve_pivot_data_field(data_field, field_names)
|
|
1856
|
+
data_field = { field: data_field } unless data_field.is_a?(Hash)
|
|
1857
|
+
return data_field if data_field[:fld].is_a?(Integer) && !data_field.key?(:field)
|
|
1858
|
+
|
|
1859
|
+
field = data_field.key?(:field) ? data_field[:field] : data_field[:fld]
|
|
1860
|
+
raise ArgumentError, "pivot table data field #{data_field.inspect} needs fld: or field:" if field.nil?
|
|
1861
|
+
|
|
1862
|
+
fld = resolve_pivot_field(field, field_names)
|
|
1863
|
+
subtotal = (data_field[:subtotal] || "sum").to_s
|
|
1864
|
+
caption = data_field[:name] || "#{subtotal[0].upcase}#{subtotal[1..]} of #{field_names ? field_names[fld] : "Field#{fld + 1}"}"
|
|
1865
|
+
data_field.except(:field).merge(fld: fld, name: caption, subtotal: subtotal)
|
|
1866
|
+
end
|
|
1867
|
+
private :resolve_pivot_data_field
|
|
1868
|
+
|
|
1820
1869
|
# Returns pivot table definitions for the first (or given) sheet.
|
|
1821
1870
|
# : (?sheet: untyped?) -> untyped
|
|
1822
1871
|
def pivot_tables(sheet: nil)
|
|
@@ -2294,7 +2343,8 @@ module Xlsxrb
|
|
|
2294
2343
|
attrs << %(windowHeight="#{@workbook_views[:window_height]}") if @workbook_views[:window_height]
|
|
2295
2344
|
attrs << %(tabRatio="#{@workbook_views[:tab_ratio]}") if @workbook_views[:tab_ratio]
|
|
2296
2345
|
attrs << %(firstSheet="#{@workbook_views[:first_sheet]}") if @workbook_views[:first_sheet]
|
|
2297
|
-
|
|
2346
|
+
at = @workbook_views[:active_sheet_index] || @workbook_views[:active_tab]
|
|
2347
|
+
attrs << %(activeTab="#{at}") if at
|
|
2298
2348
|
afdg = @workbook_views[:auto_filter_date_grouping]
|
|
2299
2349
|
attrs << %(autoFilterDateGrouping="#{afdg ? 1 : 0}") unless afdg.nil?
|
|
2300
2350
|
parts << "<bookViews>"
|
|
@@ -2534,8 +2584,11 @@ module Xlsxrb
|
|
|
2534
2584
|
outline_attrs << %(showOutlineSymbols="#{sos ? 1 : 0}") unless sos.nil?
|
|
2535
2585
|
sp_children << "<outlinePr #{outline_attrs.join(" ")}/>"
|
|
2536
2586
|
end
|
|
2587
|
+
psp = sheet_props[:page_setup_properties] || sheet_props[:page_setup_pr]
|
|
2537
2588
|
ftp = sheet_props[:fit_to_page]
|
|
2589
|
+
ftp = psp[:fit_to_page] if ftp.nil? && psp.is_a?(Hash)
|
|
2538
2590
|
apb = sheet_props[:auto_page_breaks]
|
|
2591
|
+
apb = psp[:auto_page_breaks] if apb.nil? && psp.is_a?(Hash)
|
|
2539
2592
|
unless ftp.nil? && apb.nil?
|
|
2540
2593
|
psp_attrs = []
|
|
2541
2594
|
psp_attrs << %(fitToPage="#{ftp ? 1 : 0}") unless ftp.nil?
|
|
@@ -2605,22 +2658,25 @@ module Xlsxrb
|
|
|
2605
2658
|
end
|
|
2606
2659
|
pane_attrs << %(activePane="#{active_pane}")
|
|
2607
2660
|
parts << "<pane #{pane_attrs.join(" ")}/>"
|
|
2608
|
-
elsif sheet_fp
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2661
|
+
elsif sheet_fp
|
|
2662
|
+
fp_col = sheet_fp[:column] || sheet_fp[:col] || 0
|
|
2663
|
+
if sheet_fp[:row].to_i.positive? || fp_col.to_i.positive?
|
|
2664
|
+
top_left = "#{index_to_column_letter(fp_col.to_i + 1)}#{sheet_fp[:row].to_i + 1}"
|
|
2665
|
+
pane_attrs = []
|
|
2666
|
+
pane_attrs << %(ySplit="#{sheet_fp[:row]}") if sheet_fp[:row].to_i.positive?
|
|
2667
|
+
pane_attrs << %(xSplit="#{fp_col}") if fp_col.to_i.positive?
|
|
2668
|
+
pane_attrs << %(topLeftCell="#{top_left}")
|
|
2669
|
+
active_pane = if sheet_fp[:row].to_i.positive? && fp_col.to_i.positive?
|
|
2670
|
+
"bottomRight"
|
|
2671
|
+
elsif sheet_fp[:row].to_i.positive?
|
|
2672
|
+
"bottomLeft"
|
|
2673
|
+
else
|
|
2674
|
+
"topRight"
|
|
2675
|
+
end
|
|
2676
|
+
pane_attrs << %(activePane="#{active_pane}")
|
|
2677
|
+
pane_attrs << 'state="frozen"'
|
|
2678
|
+
parts << "<pane #{pane_attrs.join(" ")}/>"
|
|
2679
|
+
end
|
|
2624
2680
|
end
|
|
2625
2681
|
|
|
2626
2682
|
if sheet_sel
|
|
@@ -2978,8 +3034,8 @@ module Xlsxrb
|
|
|
2978
3034
|
ps_attrs << %(cellComments="#{sheet_ps[:cell_comments]}") if sheet_ps[:cell_comments]
|
|
2979
3035
|
ps_attrs << %(firstPageNumber="#{sheet_ps[:first_page_number]}") if sheet_ps[:first_page_number] && sheet_ps[:first_page_number].to_i >= 0
|
|
2980
3036
|
ps_attrs << 'useFirstPageNumber="1"' if sheet_ps[:use_first_page_number]
|
|
2981
|
-
ps_attrs << %(horizontalDpi="#{sheet_ps[:horizontal_dpi]}") if sheet_ps[:horizontal_dpi]
|
|
2982
|
-
ps_attrs << %(verticalDpi="#{sheet_ps[:vertical_dpi]}") if sheet_ps[:vertical_dpi]
|
|
3037
|
+
ps_attrs << %(horizontalDpi="#{sheet_ps[:horizontal_dpi]}") if sheet_ps[:horizontal_dpi].to_i.positive?
|
|
3038
|
+
ps_attrs << %(verticalDpi="#{sheet_ps[:vertical_dpi]}") if sheet_ps[:vertical_dpi].to_i.positive?
|
|
2983
3039
|
ps_attrs << %(copies="#{sheet_ps[:copies]}") if sheet_ps[:copies]
|
|
2984
3040
|
ps_attrs << %(paperHeight="#{sheet_ps[:paper_height]}") if sheet_ps[:paper_height]
|
|
2985
3041
|
ps_attrs << %(paperWidth="#{sheet_ps[:paper_width]}") if sheet_ps[:paper_width]
|
|
@@ -3008,7 +3064,15 @@ module Xlsxrb
|
|
|
3008
3064
|
|
|
3009
3065
|
# Emit <rowBreaks> if defined.
|
|
3010
3066
|
unless sheet_rb.empty?
|
|
3011
|
-
manual_count = sheet_rb.count
|
|
3067
|
+
manual_count = sheet_rb.count do |r|
|
|
3068
|
+
if r.is_a?(Elements::PageBreak)
|
|
3069
|
+
r.manual?
|
|
3070
|
+
elsif r.is_a?(Hash)
|
|
3071
|
+
r[:man] != false
|
|
3072
|
+
else
|
|
3073
|
+
true
|
|
3074
|
+
end
|
|
3075
|
+
end
|
|
3012
3076
|
parts << %(<rowBreaks count="#{sheet_rb.size}" manualBreakCount="#{manual_count}">)
|
|
3013
3077
|
sheet_rb.each { |r| parts << emit_brk_xml(r, default_max: 16_383) }
|
|
3014
3078
|
parts << "</rowBreaks>"
|
|
@@ -3016,7 +3080,15 @@ module Xlsxrb
|
|
|
3016
3080
|
|
|
3017
3081
|
# Emit <colBreaks> if defined.
|
|
3018
3082
|
unless sheet_cb.empty?
|
|
3019
|
-
manual_count = sheet_cb.count
|
|
3083
|
+
manual_count = sheet_cb.count do |c|
|
|
3084
|
+
if c.is_a?(Elements::PageBreak)
|
|
3085
|
+
c.manual?
|
|
3086
|
+
elsif c.is_a?(Hash)
|
|
3087
|
+
c[:man] != false
|
|
3088
|
+
else
|
|
3089
|
+
true
|
|
3090
|
+
end
|
|
3091
|
+
end
|
|
3020
3092
|
parts << %(<colBreaks count="#{sheet_cb.size}" manualBreakCount="#{manual_count}">)
|
|
3021
3093
|
sheet_cb.each { |c| parts << emit_brk_xml(c, default_max: 1_048_575) }
|
|
3022
3094
|
parts << "</colBreaks>"
|
|
@@ -3144,11 +3216,18 @@ module Xlsxrb
|
|
|
3144
3216
|
parts << %(<autoFilter ref="#{tbl[:ref]}"/>) unless tbl[:auto_filter] == false
|
|
3145
3217
|
parts << %(<tableColumns count="#{tbl[:columns].size}">)
|
|
3146
3218
|
tbl[:columns].each_with_index do |col, i|
|
|
3147
|
-
|
|
3219
|
+
col = col.to_h if col.is_a?(Elements::MetadataRecord)
|
|
3220
|
+
col_name = if col.is_a?(Hash)
|
|
3221
|
+
col[:name]
|
|
3222
|
+
elsif col.is_a?(Elements::TableColumn)
|
|
3223
|
+
col.name
|
|
3224
|
+
else
|
|
3225
|
+
col
|
|
3226
|
+
end
|
|
3148
3227
|
col_attrs = %(id="#{i + 1}" name="#{xml_escape(col_name)}")
|
|
3149
|
-
if col.is_a?(Hash)
|
|
3228
|
+
if col.is_a?(Hash) || col.is_a?(Elements::TableColumn)
|
|
3150
3229
|
calc_formula = col[:calculated_column_formula] || col[:data_formula] || col[:formula]
|
|
3151
|
-
tot_formula = col[:totals_row_formula]
|
|
3230
|
+
tot_formula = col[:totals_row_formula]
|
|
3152
3231
|
trf = col[:totals_row_function] || ("custom" if tot_formula)
|
|
3153
3232
|
col_attrs << %( totalsRowFunction="#{trf}") if trf
|
|
3154
3233
|
col_attrs << %( totalsRowLabel="#{xml_escape(col[:totals_row_label])}") if col[:totals_row_label]
|
|
@@ -3169,7 +3248,8 @@ module Xlsxrb
|
|
|
3169
3248
|
end
|
|
3170
3249
|
end
|
|
3171
3250
|
parts << "</tableColumns>"
|
|
3172
|
-
raw_style = tbl[:style]
|
|
3251
|
+
raw_style = tbl[:style] || tbl[:style_info]
|
|
3252
|
+
raw_style = raw_style.to_h if raw_style.respond_to?(:to_h)
|
|
3173
3253
|
style = if raw_style.is_a?(Hash)
|
|
3174
3254
|
raw_style
|
|
3175
3255
|
elsif raw_style
|
|
@@ -17,15 +17,20 @@ begin
|
|
|
17
17
|
end
|
|
18
18
|
end
|
|
19
19
|
if defined?(REXML::Security)
|
|
20
|
+
# REXML keeps these limits in class variables, which non-main Ractors cannot read.
|
|
21
|
+
# Move them to module instance variables, carrying over the values the application
|
|
22
|
+
# has already set (e.g. 0 to disable entity expansion).
|
|
23
|
+
current_limit = REXML::Security.entity_expansion_limit
|
|
24
|
+
current_text_limit = REXML::Security.entity_expansion_text_limit
|
|
20
25
|
prev_verbose = $VERBOSE
|
|
21
26
|
$VERBOSE = nil
|
|
22
27
|
begin
|
|
23
28
|
REXML::Security.instance_eval do
|
|
24
|
-
@entity_expansion_limit =
|
|
25
|
-
@entity_expansion_text_limit =
|
|
29
|
+
@entity_expansion_limit = current_limit
|
|
30
|
+
@entity_expansion_text_limit = current_text_limit
|
|
26
31
|
|
|
27
32
|
def self.entity_expansion_limit
|
|
28
|
-
@entity_expansion_limit
|
|
33
|
+
@entity_expansion_limit
|
|
29
34
|
end
|
|
30
35
|
|
|
31
36
|
def self.entity_expansion_limit=(val)
|
|
@@ -33,7 +38,7 @@ begin
|
|
|
33
38
|
end
|
|
34
39
|
|
|
35
40
|
def self.entity_expansion_text_limit
|
|
36
|
-
@entity_expansion_text_limit
|
|
41
|
+
@entity_expansion_text_limit
|
|
37
42
|
end
|
|
38
43
|
|
|
39
44
|
def self.entity_expansion_text_limit=(val)
|
|
@@ -57,11 +62,79 @@ module Xlsxrb
|
|
|
57
62
|
module XmlParser
|
|
58
63
|
# Parses XML string using SAX2, calling the given listener.
|
|
59
64
|
def self.parse(xml_string, listener)
|
|
60
|
-
parser =
|
|
65
|
+
parser = sax2_parser(xml_string)
|
|
61
66
|
parser.listen(listener)
|
|
62
67
|
parser.parse
|
|
63
68
|
end
|
|
64
69
|
|
|
70
|
+
# Returns a SAX2 parser whose listeners receive attribute values with XML entities
|
|
71
|
+
# decoded. REXML's SAX2 parser decodes text but passes attribute values as written, so
|
|
72
|
+
# formatCode=""$"0" would otherwise arrive with the " references.
|
|
73
|
+
#: (String xml_string) -> REXML::Parsers::SAX2Parser
|
|
74
|
+
def self.sax2_parser(xml_string)
|
|
75
|
+
DecodingSAX2Parser.new(xml_string)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
# SAX2 parser that wraps each listener in an AttributeDecoder.
|
|
79
|
+
class DecodingSAX2Parser < REXML::Parsers::SAX2Parser
|
|
80
|
+
#: (*untyped args) ?{ (*untyped) -> untyped } -> untyped
|
|
81
|
+
def listen(*args, &)
|
|
82
|
+
return super if args.size != 1 || args.first.is_a?(Symbol) || args.first.is_a?(Array) || block_given?
|
|
83
|
+
|
|
84
|
+
super(AttributeDecoder.new(args.first))
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
# Forwards SAX2 events to a listener, decoding entity references in attribute values.
|
|
89
|
+
class AttributeDecoder
|
|
90
|
+
#: (untyped listener) -> void
|
|
91
|
+
def initialize(listener)
|
|
92
|
+
@listener = listener
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
# Plain methods rather than define_method blocks, which Ractors cannot share.
|
|
96
|
+
#: (*untyped args) -> untyped
|
|
97
|
+
def start_document(*args) = @listener.start_document(*args)
|
|
98
|
+
#: (*untyped args) -> untyped
|
|
99
|
+
def end_document(*args) = @listener.end_document(*args)
|
|
100
|
+
#: (*untyped args) -> untyped
|
|
101
|
+
def start_prefix_mapping(*args) = @listener.start_prefix_mapping(*args)
|
|
102
|
+
#: (*untyped args) -> untyped
|
|
103
|
+
def end_prefix_mapping(*args) = @listener.end_prefix_mapping(*args)
|
|
104
|
+
#: (*untyped args) -> untyped
|
|
105
|
+
def end_element(*args) = @listener.end_element(*args)
|
|
106
|
+
#: (*untyped args) -> untyped
|
|
107
|
+
def characters(*args) = @listener.characters(*args)
|
|
108
|
+
#: (*untyped args) -> untyped
|
|
109
|
+
def processing_instruction(*args) = @listener.processing_instruction(*args)
|
|
110
|
+
#: (*untyped args) -> untyped
|
|
111
|
+
def doctype(*args) = @listener.doctype(*args)
|
|
112
|
+
#: (*untyped args) -> untyped
|
|
113
|
+
def attlistdecl(*args) = @listener.attlistdecl(*args)
|
|
114
|
+
#: (*untyped args) -> untyped
|
|
115
|
+
def elementdecl(*args) = @listener.elementdecl(*args)
|
|
116
|
+
#: (*untyped args) -> untyped
|
|
117
|
+
def entitydecl(*args) = @listener.entitydecl(*args)
|
|
118
|
+
#: (*untyped args) -> untyped
|
|
119
|
+
def notationdecl(*args) = @listener.notationdecl(*args)
|
|
120
|
+
#: (*untyped args) -> untyped
|
|
121
|
+
def cdata(*args) = @listener.cdata(*args)
|
|
122
|
+
#: (*untyped args) -> untyped
|
|
123
|
+
def xmldecl(*args) = @listener.xmldecl(*args)
|
|
124
|
+
#: (*untyped args) -> untyped
|
|
125
|
+
def comment(*args) = @listener.comment(*args)
|
|
126
|
+
#: (*untyped args) -> untyped
|
|
127
|
+
def progress(*args) = @listener.progress(*args)
|
|
128
|
+
|
|
129
|
+
#: (String? uri, String local_name, String qname, Hash[String, String] attributes) -> untyped
|
|
130
|
+
def start_element(uri, local_name, qname, attributes)
|
|
131
|
+
if attributes.each_value.any? { |value| value.include?("&") }
|
|
132
|
+
attributes = attributes.transform_values { |value| value.include?("&") ? REXML::Text.unnormalize(value) : value }
|
|
133
|
+
end
|
|
134
|
+
@listener.start_element(uri, local_name, qname, attributes)
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
|
|
65
138
|
# Base listener with unmapped-data collection support.
|
|
66
139
|
class BaseListener
|
|
67
140
|
include REXML::SAX2Listener
|