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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +157 -1
- data/README.md +81 -21
- data/lib/ruby_lsp/xlsxrb/completion_listener.rb +31 -61
- data/lib/xlsxrb/chart_builder.rb +619 -98
- data/lib/xlsxrb/dsl_helpers.rb +583 -15
- data/lib/xlsxrb/elements/cell.rb +265 -53
- data/lib/xlsxrb/elements/column.rb +95 -6
- data/lib/xlsxrb/elements/coordinate_access.rb +108 -10
- data/lib/xlsxrb/elements/image.rb +81 -15
- data/lib/xlsxrb/elements/metadata.rb +2733 -0
- data/lib/xlsxrb/elements/row.rb +130 -46
- data/lib/xlsxrb/elements/styles.rb +184 -76
- data/lib/xlsxrb/elements/types.rb +243 -7
- data/lib/xlsxrb/elements/workbook.rb +202 -65
- data/lib/xlsxrb/elements/worksheet.rb +728 -85
- data/lib/xlsxrb/elements.rb +1 -0
- data/lib/xlsxrb/ooxml/reader/listeners/core_listeners.rb +32 -3
- data/lib/xlsxrb/ooxml/reader/listeners/drawing_listeners.rb +194 -26
- data/lib/xlsxrb/ooxml/reader/listeners/feature_listeners.rb +372 -18
- data/lib/xlsxrb/ooxml/reader/listeners/style_listeners.rb +33 -14
- data/lib/xlsxrb/ooxml/reader.rb +92 -0
- data/lib/xlsxrb/ooxml/styles_parser.rb +29 -14
- data/lib/xlsxrb/ooxml/workbook_parser.rb +18 -3
- data/lib/xlsxrb/ooxml/workbook_writer.rb +351 -77
- data/lib/xlsxrb/ooxml/worksheet_parser.rb +18 -4
- data/lib/xlsxrb/ooxml/worksheet_writer.rb +349 -103
- data/lib/xlsxrb/ooxml/writer/drawing_xml.rb +584 -443
- data/lib/xlsxrb/ooxml/writer/features_xml.rb +52 -14
- data/lib/xlsxrb/ooxml/writer/styles_xml.rb +42 -18
- data/lib/xlsxrb/ooxml/writer.rb +288 -35
- data/lib/xlsxrb/ooxml/zip_generator.rb +2 -0
- data/lib/xlsxrb/ooxml/zip_reader.rb +47 -10
- data/lib/xlsxrb/ooxml/zip_writer.rb +15 -5
- data/lib/xlsxrb/stream_row.rb +97 -18
- data/lib/xlsxrb/stream_sheet.rb +827 -157
- data/lib/xlsxrb/stream_writer.rb +2766 -375
- data/lib/xlsxrb/style_builder.rb +821 -105
- data/lib/xlsxrb/utils.rb +82 -57
- data/lib/xlsxrb/version.rb +1 -1
- data/lib/xlsxrb/workbook_builder.rb +542 -62
- data/lib/xlsxrb/worksheet_builder.rb +2279 -209
- data/lib/xlsxrb.rb +1539 -344
- data/sig/generated/xlsxrb/chart_builder.rbs +336 -79
- data/sig/generated/xlsxrb/dsl_helpers.rbs +137 -4
- data/sig/generated/xlsxrb/elements/cell.rbs +104 -15
- data/sig/generated/xlsxrb/elements/column.rbs +62 -3
- data/sig/generated/xlsxrb/elements/coordinate_access.rbs +49 -7
- data/sig/generated/xlsxrb/elements/image.rbs +30 -8
- data/sig/generated/xlsxrb/elements/metadata.rbs +1587 -0
- data/sig/generated/xlsxrb/elements/row.rbs +61 -21
- data/sig/generated/xlsxrb/elements/styles.rbs +96 -58
- data/sig/generated/xlsxrb/elements/types.rbs +29 -0
- data/sig/generated/xlsxrb/elements/workbook.rbs +92 -44
- data/sig/generated/xlsxrb/elements/worksheet.rbs +259 -38
- data/sig/generated/xlsxrb/ooxml/reader/listeners/core_listeners.rbs +2 -0
- data/sig/generated/xlsxrb/ooxml/reader/listeners/drawing_listeners.rbs +74 -2
- data/sig/generated/xlsxrb/ooxml/reader/listeners/feature_listeners.rbs +97 -0
- data/sig/generated/xlsxrb/ooxml/reader/listeners/style_listeners.rbs +3 -0
- data/sig/generated/xlsxrb/ooxml/reader.rbs +20 -0
- data/sig/generated/xlsxrb/ooxml/styles_parser.rbs +3 -0
- data/sig/generated/xlsxrb/ooxml/workbook_parser.rbs +8 -0
- data/sig/generated/xlsxrb/ooxml/workbook_writer.rbs +8 -4
- data/sig/generated/xlsxrb/ooxml/worksheet_parser.rbs +1 -1
- data/sig/generated/xlsxrb/ooxml/worksheet_writer.rbs +12 -1
- data/sig/generated/xlsxrb/ooxml/writer/drawing_xml.rbs +16 -0
- data/sig/generated/xlsxrb/ooxml/writer.rbs +45 -8
- data/sig/generated/xlsxrb/ooxml/zip_generator.rbs +2 -0
- data/sig/generated/xlsxrb/ooxml/zip_reader.rbs +2 -2
- data/sig/generated/xlsxrb/ooxml/zip_writer.rbs +8 -2
- data/sig/generated/xlsxrb/stream_row.rbs +48 -14
- data/sig/generated/xlsxrb/stream_sheet.rbs +398 -89
- data/sig/generated/xlsxrb/stream_writer.rbs +1601 -219
- data/sig/generated/xlsxrb/style_builder.rbs +403 -75
- data/sig/generated/xlsxrb/utils.rbs +49 -13
- data/sig/generated/xlsxrb/workbook_builder.rbs +308 -26
- data/sig/generated/xlsxrb/worksheet_builder.rbs +1142 -96
- data/sig/generated/xlsxrb.rbs +321 -52
- metadata +3 -1
|
@@ -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
|
-
|
|
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
|
|
@@ -449,6 +452,12 @@ module Xlsxrb
|
|
|
449
452
|
@properties[:summary_right] = %w[1 true].include?(sr) unless sr.nil?
|
|
450
453
|
sos = attributes["showOutlineSymbols"]
|
|
451
454
|
@properties[:show_outline_symbols] = %w[1 true].include?(sos) unless sos.nil?
|
|
455
|
+
@properties[:outline_properties] = {
|
|
456
|
+
apply_styles: @properties[:apply_styles],
|
|
457
|
+
summary_below: @properties[:summary_below],
|
|
458
|
+
summary_right: @properties[:summary_right],
|
|
459
|
+
show_outline_symbols: @properties[:show_outline_symbols]
|
|
460
|
+
}.compact
|
|
452
461
|
end
|
|
453
462
|
when "pageSetUpPr"
|
|
454
463
|
if @inside_sheet_pr
|
|
@@ -776,13 +785,22 @@ module Xlsxrb
|
|
|
776
785
|
drh = attributes["defaultRowHeight"]
|
|
777
786
|
@properties[:default_row_height] = drh.to_f if drh
|
|
778
787
|
dcw = attributes["defaultColWidth"]
|
|
779
|
-
|
|
788
|
+
if dcw
|
|
789
|
+
@properties[:default_column_width] = dcw.to_f
|
|
790
|
+
@properties[:default_col_width] = dcw.to_f
|
|
791
|
+
end
|
|
780
792
|
bcw = attributes["baseColWidth"]
|
|
781
|
-
|
|
793
|
+
if bcw
|
|
794
|
+
@properties[:base_column_width] = bcw.to_i
|
|
795
|
+
@properties[:base_col_width] = bcw.to_i
|
|
796
|
+
end
|
|
782
797
|
olr = attributes["outlineLevelRow"]
|
|
783
798
|
@properties[:outline_level_row] = olr.to_i if olr
|
|
784
799
|
olc = attributes["outlineLevelCol"]
|
|
785
|
-
|
|
800
|
+
if olc
|
|
801
|
+
@properties[:outline_level_column] = olc.to_i
|
|
802
|
+
@properties[:outline_level_col] = olc.to_i
|
|
803
|
+
end
|
|
786
804
|
ch = attributes["customHeight"]
|
|
787
805
|
@properties[:custom_height] = true if %w[1 true].include?(ch)
|
|
788
806
|
zh = attributes["zeroHeight"]
|
|
@@ -869,18 +887,22 @@ module Xlsxrb
|
|
|
869
887
|
frozen = attributes["state"] == "frozen"
|
|
870
888
|
tlc = attributes["topLeftCell"]
|
|
871
889
|
ap = attributes["activePane"]
|
|
890
|
+
col_val = xs ? xs.to_i : 0
|
|
891
|
+
row_val = ys ? ys.to_i : 0
|
|
872
892
|
p = if frozen
|
|
873
893
|
{
|
|
874
|
-
row:
|
|
875
|
-
|
|
894
|
+
row: row_val,
|
|
895
|
+
column: col_val,
|
|
896
|
+
col: col_val,
|
|
876
897
|
state: :frozen
|
|
877
898
|
}
|
|
878
899
|
else
|
|
879
900
|
{
|
|
880
|
-
row:
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
901
|
+
row: row_val,
|
|
902
|
+
column: col_val,
|
|
903
|
+
col: col_val,
|
|
904
|
+
x_split: col_val,
|
|
905
|
+
y_split: row_val,
|
|
884
906
|
top_left_cell: tlc,
|
|
885
907
|
state: :split
|
|
886
908
|
}
|
|
@@ -1033,7 +1055,11 @@ module Xlsxrb
|
|
|
1033
1055
|
@current_rule[:pivot] = true if @current_pivot
|
|
1034
1056
|
@current_rule[:priority] = attributes["priority"].to_i if attributes["priority"]
|
|
1035
1057
|
@current_rule[:operator] = attributes["operator"] if attributes["operator"]
|
|
1036
|
-
|
|
1058
|
+
if attributes["dxfId"]
|
|
1059
|
+
did = attributes["dxfId"].to_i
|
|
1060
|
+
@current_rule[:dxf_id] = did
|
|
1061
|
+
@current_rule[:format_id] = did
|
|
1062
|
+
end
|
|
1037
1063
|
@current_rule[:stop_if_true] = true if attributes["stopIfTrue"] == "1"
|
|
1038
1064
|
@current_rule[:above_average] = false if attributes["aboveAverage"] == "0"
|
|
1039
1065
|
@current_rule[:equal_average] = true if attributes["equalAverage"] == "1"
|
|
@@ -1102,7 +1128,11 @@ module Xlsxrb
|
|
|
1102
1128
|
name = element_name(local_name, qname)
|
|
1103
1129
|
case name
|
|
1104
1130
|
when "formula"
|
|
1105
|
-
|
|
1131
|
+
if @current_rule
|
|
1132
|
+
val = @text_buffer.dup
|
|
1133
|
+
(@current_rule[:formulas] ||= []) << val
|
|
1134
|
+
@current_rule[:formula] = @current_rule[:formulas]
|
|
1135
|
+
end
|
|
1106
1136
|
@inside_formula = false
|
|
1107
1137
|
when "cfRule"
|
|
1108
1138
|
@rules << @current_rule if @current_rule
|
|
@@ -1148,7 +1178,7 @@ module Xlsxrb
|
|
|
1148
1178
|
class PrintPageListener
|
|
1149
1179
|
include REXML::SAX2Listener
|
|
1150
1180
|
|
|
1151
|
-
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
|
|
1152
1182
|
|
|
1153
1183
|
def initialize
|
|
1154
1184
|
@print_options = {}
|
|
@@ -1157,6 +1187,7 @@ module Xlsxrb
|
|
|
1157
1187
|
@header_footer = {}
|
|
1158
1188
|
@row_breaks = []
|
|
1159
1189
|
@col_breaks = []
|
|
1190
|
+
@column_breaks = @col_breaks
|
|
1160
1191
|
@inside_header_footer = false
|
|
1161
1192
|
@inside_row_breaks = false
|
|
1162
1193
|
@inside_col_breaks = false
|
|
@@ -1394,7 +1425,11 @@ module Xlsxrb
|
|
|
1394
1425
|
name = element_name(local_name, qname)
|
|
1395
1426
|
case name
|
|
1396
1427
|
when "calculatedColumnFormula"
|
|
1397
|
-
|
|
1428
|
+
if @current_column
|
|
1429
|
+
val = @text_buffer.dup
|
|
1430
|
+
@current_column[:calculated_column_formula] = val
|
|
1431
|
+
@current_column[:data_formula] = val
|
|
1432
|
+
end
|
|
1398
1433
|
@inside_calc_formula = false
|
|
1399
1434
|
when "totalsRowFormula"
|
|
1400
1435
|
@current_column[:totals_row_formula] = @text_buffer.dup if @current_column
|
|
@@ -1481,7 +1516,11 @@ module Xlsxrb
|
|
|
1481
1516
|
@pivot_table[:data_caption] = attributes["dataCaption"] if attributes["dataCaption"]
|
|
1482
1517
|
@pivot_table[:data_on_rows] = attributes["dataOnRows"] == "1" if attributes["dataOnRows"]
|
|
1483
1518
|
@pivot_table[:row_grand_totals] = attributes["rowGrandTotals"] != "0" if attributes["rowGrandTotals"]
|
|
1484
|
-
|
|
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
|
|
1485
1524
|
@pivot_table[:compact] = attributes["compact"] != "0" if attributes["compact"]
|
|
1486
1525
|
@pivot_table[:outline] = attributes["outline"] != "0" if attributes["outline"]
|
|
1487
1526
|
@pivot_table[:outline_data] = attributes["outlineData"] == "1" if attributes["outlineData"]
|
|
@@ -1534,7 +1573,11 @@ module Xlsxrb
|
|
|
1534
1573
|
when "location"
|
|
1535
1574
|
@pivot_table[:ref] = attributes["ref"] if @pivot_table
|
|
1536
1575
|
@pivot_table[:row_page_count] = attributes["rowPageCount"]&.to_i if attributes["rowPageCount"]
|
|
1537
|
-
|
|
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
|
|
1538
1581
|
when "pivotField"
|
|
1539
1582
|
@inside_pivot_field = true
|
|
1540
1583
|
@current_field = {}
|
|
@@ -1591,11 +1634,19 @@ module Xlsxrb
|
|
|
1591
1634
|
srh = attributes["showRowHeaders"]
|
|
1592
1635
|
psi[:show_row_headers] = srh == "1" unless srh.nil?
|
|
1593
1636
|
sch = attributes["showColHeaders"]
|
|
1594
|
-
|
|
1637
|
+
unless sch.nil?
|
|
1638
|
+
val = sch == "1"
|
|
1639
|
+
psi[:show_column_headers] = val
|
|
1640
|
+
psi[:show_col_headers] = val
|
|
1641
|
+
end
|
|
1595
1642
|
srs = attributes["showRowStripes"]
|
|
1596
1643
|
psi[:show_row_stripes] = srs == "1" unless srs.nil?
|
|
1597
1644
|
scs = attributes["showColStripes"]
|
|
1598
|
-
|
|
1645
|
+
unless scs.nil?
|
|
1646
|
+
val = scs == "1"
|
|
1647
|
+
psi[:show_column_stripes] = val
|
|
1648
|
+
psi[:show_col_stripes] = val
|
|
1649
|
+
end
|
|
1599
1650
|
slc = attributes["showLastColumn"]
|
|
1600
1651
|
psi[:show_last_column] = slc == "1" unless slc.nil?
|
|
1601
1652
|
@pivot_table[:pivot_table_style] = psi
|
|
@@ -1616,6 +1667,7 @@ module Xlsxrb
|
|
|
1616
1667
|
if @pivot_table
|
|
1617
1668
|
@pivot_table[:fields] = @fields
|
|
1618
1669
|
@pivot_table[:row_fields] = @row_fields
|
|
1670
|
+
@pivot_table[:column_fields] = @col_fields
|
|
1619
1671
|
@pivot_table[:col_fields] = @col_fields
|
|
1620
1672
|
@pivot_table[:data_fields] = @data_fields
|
|
1621
1673
|
end
|
|
@@ -1803,6 +1855,308 @@ module Xlsxrb
|
|
|
1803
1855
|
end
|
|
1804
1856
|
end
|
|
1805
1857
|
end
|
|
1858
|
+
|
|
1859
|
+
# SAX2 listener for parsing <personList> element in xl/persons/person.xml.
|
|
1860
|
+
class PersonListListener
|
|
1861
|
+
include REXML::SAX2Listener
|
|
1862
|
+
|
|
1863
|
+
attr_reader :persons
|
|
1864
|
+
|
|
1865
|
+
def initialize
|
|
1866
|
+
@persons = []
|
|
1867
|
+
end
|
|
1868
|
+
|
|
1869
|
+
def start_element(_uri, local_name, qname, attributes)
|
|
1870
|
+
name = element_name(local_name, qname)
|
|
1871
|
+
return unless name == "person"
|
|
1872
|
+
|
|
1873
|
+
@persons << {
|
|
1874
|
+
id: attributes["id"],
|
|
1875
|
+
display_name: attributes["displayName"],
|
|
1876
|
+
user_id: attributes["userId"],
|
|
1877
|
+
provider_id: attributes["providerId"]
|
|
1878
|
+
}.compact
|
|
1879
|
+
end
|
|
1880
|
+
|
|
1881
|
+
def end_element(_uri, _local_name, _qname); end
|
|
1882
|
+
|
|
1883
|
+
private
|
|
1884
|
+
|
|
1885
|
+
def element_name(local_name, qname)
|
|
1886
|
+
if local_name.nil? || local_name.empty?
|
|
1887
|
+
qname.to_s.split(":").last
|
|
1888
|
+
else
|
|
1889
|
+
local_name
|
|
1890
|
+
end
|
|
1891
|
+
end
|
|
1892
|
+
end
|
|
1893
|
+
|
|
1894
|
+
# SAX2 listener for parsing <ThreadedComments> element in xl/threadedComments/threadedComment{N}.xml.
|
|
1895
|
+
class ThreadedCommentsListener
|
|
1896
|
+
include REXML::SAX2Listener
|
|
1897
|
+
|
|
1898
|
+
attr_reader :threaded_comments
|
|
1899
|
+
|
|
1900
|
+
def initialize
|
|
1901
|
+
@threaded_comments = []
|
|
1902
|
+
@current_comment = nil
|
|
1903
|
+
@inside_text = false
|
|
1904
|
+
@text_buffer = +""
|
|
1905
|
+
end
|
|
1906
|
+
|
|
1907
|
+
def start_element(_uri, local_name, qname, attributes)
|
|
1908
|
+
name = element_name(local_name, qname)
|
|
1909
|
+
case name
|
|
1910
|
+
when "threadedComment"
|
|
1911
|
+
@current_comment = {
|
|
1912
|
+
ref: attributes["ref"],
|
|
1913
|
+
dt: attributes["dT"] || attributes["dt"],
|
|
1914
|
+
person_id: attributes["personId"],
|
|
1915
|
+
id: attributes["id"]
|
|
1916
|
+
}
|
|
1917
|
+
@current_comment[:parent_id] = attributes["parentId"] if attributes["parentId"]
|
|
1918
|
+
@current_comment[:done] = %w[1 true].include?(attributes["done"]) if attributes.key?("done")
|
|
1919
|
+
when "text"
|
|
1920
|
+
if @current_comment
|
|
1921
|
+
@inside_text = true
|
|
1922
|
+
@text_buffer = +""
|
|
1923
|
+
end
|
|
1924
|
+
end
|
|
1925
|
+
end
|
|
1926
|
+
|
|
1927
|
+
def characters(text)
|
|
1928
|
+
@text_buffer << text if @inside_text
|
|
1929
|
+
end
|
|
1930
|
+
|
|
1931
|
+
def end_element(_uri, local_name, qname)
|
|
1932
|
+
name = element_name(local_name, qname)
|
|
1933
|
+
case name
|
|
1934
|
+
when "text"
|
|
1935
|
+
if @current_comment && @inside_text
|
|
1936
|
+
@current_comment[:text] = @text_buffer.dup
|
|
1937
|
+
@inside_text = false
|
|
1938
|
+
end
|
|
1939
|
+
when "threadedComment"
|
|
1940
|
+
@threaded_comments << @current_comment if @current_comment
|
|
1941
|
+
@current_comment = nil
|
|
1942
|
+
end
|
|
1943
|
+
end
|
|
1944
|
+
|
|
1945
|
+
private
|
|
1946
|
+
|
|
1947
|
+
def element_name(local_name, qname)
|
|
1948
|
+
if local_name.nil? || local_name.empty?
|
|
1949
|
+
qname.to_s.split(":").last
|
|
1950
|
+
else
|
|
1951
|
+
local_name
|
|
1952
|
+
end
|
|
1953
|
+
end
|
|
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
|
|
1806
2160
|
end
|
|
1807
2161
|
end
|
|
1808
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
|
-
|
|
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
|
|
@@ -85,12 +89,12 @@ module Xlsxrb
|
|
|
85
89
|
}
|
|
86
90
|
%w[applyNumberFormat applyFont applyFill applyBorder applyAlignment applyProtection].each do |attr|
|
|
87
91
|
key = attr.gsub(/[A-Z]/) { |m| "_#{m.downcase}" }.to_sym
|
|
88
|
-
xf_entry[key] = attributes[attr]
|
|
92
|
+
xf_entry[key] = boolean_val(attributes[attr]) unless attributes[attr].nil?
|
|
89
93
|
end
|
|
90
94
|
if @inside_cell_xfs
|
|
91
95
|
xf_entry[:xf_id] = attributes["xfId"]&.to_i
|
|
92
|
-
xf_entry[:quote_prefix] = true if attributes["quotePrefix"]
|
|
93
|
-
xf_entry[:pivot_button] = true if attributes["pivotButton"]
|
|
96
|
+
xf_entry[:quote_prefix] = true if boolean_val(attributes["quotePrefix"])
|
|
97
|
+
xf_entry[:pivot_button] = true if boolean_val(attributes["pivotButton"])
|
|
94
98
|
@cell_xfs << xf_entry
|
|
95
99
|
@current_xf = xf_entry
|
|
96
100
|
elsif @inside_cell_style_xfs
|
|
@@ -103,15 +107,15 @@ module Xlsxrb
|
|
|
103
107
|
alignment = {}
|
|
104
108
|
alignment[:horizontal] = attributes["horizontal"] if attributes["horizontal"]
|
|
105
109
|
alignment[:vertical] = attributes["vertical"] if attributes["vertical"]
|
|
106
|
-
alignment[:wrap_text] = true if attributes["wrapText"]
|
|
110
|
+
alignment[:wrap_text] = true if boolean_val(attributes["wrapText"])
|
|
107
111
|
alignment[:text_rotation] = attributes["textRotation"].to_i if attributes["textRotation"]
|
|
108
112
|
alignment[:indent] = attributes["indent"].to_i if attributes["indent"]
|
|
109
113
|
ri = attributes["relativeIndent"]
|
|
110
114
|
alignment[:relative_indent] = ri.to_i if ri
|
|
111
|
-
alignment[:shrink_to_fit] = true if attributes["shrinkToFit"]
|
|
115
|
+
alignment[:shrink_to_fit] = true if boolean_val(attributes["shrinkToFit"])
|
|
112
116
|
ro = attributes["readingOrder"]
|
|
113
117
|
alignment[:reading_order] = ro.to_i if ro
|
|
114
|
-
alignment[:justify_last_line] = true if attributes["justifyLastLine"]
|
|
118
|
+
alignment[:justify_last_line] = true if boolean_val(attributes["justifyLastLine"])
|
|
115
119
|
unless alignment.empty?
|
|
116
120
|
if @inside_dxfs && @current_dxf
|
|
117
121
|
@current_dxf[:alignment] = alignment
|
|
@@ -121,8 +125,8 @@ module Xlsxrb
|
|
|
121
125
|
end
|
|
122
126
|
when "protection"
|
|
123
127
|
protection = {}
|
|
124
|
-
protection[:locked] = attributes["locked"]
|
|
125
|
-
protection[:hidden] = attributes["hidden"]
|
|
128
|
+
protection[:locked] = !%w[0 false].include?(attributes["locked"]&.downcase) if attributes.key?("locked")
|
|
129
|
+
protection[:hidden] = boolean_val(attributes["hidden"]) if attributes.key?("hidden")
|
|
126
130
|
unless protection.empty?
|
|
127
131
|
if @inside_dxfs && @current_dxf
|
|
128
132
|
@current_dxf[:protection] = protection
|
|
@@ -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
|
-
|
|
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
|
-
|
|
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 = {}
|
|
@@ -194,10 +208,10 @@ module Xlsxrb
|
|
|
194
208
|
when "border"
|
|
195
209
|
if @inside_borders || @inside_dxfs
|
|
196
210
|
@current_border = {}
|
|
197
|
-
@current_border[:diagonal_up] = true if attributes["diagonalUp"]
|
|
198
|
-
@current_border[:diagonal_down] = true if attributes["diagonalDown"]
|
|
211
|
+
@current_border[:diagonal_up] = true if boolean_val(attributes["diagonalUp"])
|
|
212
|
+
@current_border[:diagonal_down] = true if boolean_val(attributes["diagonalDown"])
|
|
199
213
|
ol = attributes["outline"]
|
|
200
|
-
@current_border[:outline] =
|
|
214
|
+
@current_border[:outline] = boolean_val(ol) unless ol.nil?
|
|
201
215
|
end
|
|
202
216
|
when "left", "right", "top", "bottom", "diagonal", "vertical", "horizontal", "start", "end"
|
|
203
217
|
if @current_border
|
|
@@ -303,6 +317,11 @@ module Xlsxrb
|
|
|
303
317
|
|
|
304
318
|
private
|
|
305
319
|
|
|
320
|
+
#: (untyped val) -> bool
|
|
321
|
+
def boolean_val(val)
|
|
322
|
+
val == "1" || (val&.casecmp?("true") || false)
|
|
323
|
+
end
|
|
324
|
+
|
|
306
325
|
def truthy_val?(attributes)
|
|
307
326
|
val = attributes["val"]
|
|
308
327
|
val.nil? || (val != "0" && val.downcase != "false")
|