xlsxrb 0.2.2 → 0.2.3
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 +43 -0
- data/lib/xlsxrb/elements/cell.rb +1 -1
- data/lib/xlsxrb/elements/workbook.rb +115 -4
- data/lib/xlsxrb/number_formatter.rb +5 -5
- data/lib/xlsxrb/ooxml/cfb.rb +61 -25
- data/lib/xlsxrb/ooxml/crypto/agile.rb +41 -12
- data/lib/xlsxrb/ooxml/reader/listeners/core_listeners.rb +4 -0
- data/lib/xlsxrb/ooxml/reader/listeners/feature_listeners.rb +2 -0
- data/lib/xlsxrb/ooxml/shared_strings_parser.rb +4 -2
- data/lib/xlsxrb/ooxml/utils.rb +4 -3
- data/lib/xlsxrb/ooxml/workbook_parser.rb +88 -40
- data/lib/xlsxrb/ooxml/workbook_writer.rb +48 -24
- data/lib/xlsxrb/ooxml/worksheet_parser.rb +186 -78
- data/lib/xlsxrb/ooxml/worksheet_writer.rb +81 -18
- data/lib/xlsxrb/ooxml/writer/drawing_xml.rb +1511 -1458
- data/lib/xlsxrb/ooxml/writer/features_xml.rb +558 -525
- data/lib/xlsxrb/ooxml/writer/styles_xml.rb +272 -280
- data/lib/xlsxrb/ooxml/writer.rb +1017 -941
- data/lib/xlsxrb/ooxml/xml_builder.rb +48 -16
- data/lib/xlsxrb/ooxml/xml_parser.rb +37 -2
- data/lib/xlsxrb/ooxml/zip_generator.rb +10 -10
- data/lib/xlsxrb/ooxml/zip_reader.rb +19 -6
- data/lib/xlsxrb/ooxml/zip_writer.rb +15 -7
- data/lib/xlsxrb/stream_row.rb +8 -5
- data/lib/xlsxrb/stream_sheet.rb +3 -0
- data/lib/xlsxrb/stream_writer.rb +48 -18
- data/lib/xlsxrb/style_builder.rb +9 -4
- data/lib/xlsxrb/version.rb +1 -1
- data/lib/xlsxrb/workbook_builder.rb +14 -8
- data/lib/xlsxrb/worksheet_builder.rb +10 -4
- data/lib/xlsxrb.rb +415 -418
- data/sig/generated/xlsxrb/elements/workbook.rbs +23 -1
- data/sig/generated/xlsxrb/ooxml/reader/listeners/core_listeners.rbs +2 -0
- data/sig/generated/xlsxrb/ooxml/workbook_parser.rbs +21 -1
- data/sig/generated/xlsxrb/ooxml/worksheet_parser.rbs +20 -2
- data/sig/generated/xlsxrb/ooxml/writer/drawing_xml.rbs +162 -47
- data/sig/generated/xlsxrb/ooxml/writer/features_xml.rbs +20 -24
- data/sig/generated/xlsxrb/ooxml/writer/styles_xml.rbs +20 -20
- data/sig/generated/xlsxrb/ooxml/writer.rbs +61 -10
- data/sig/generated/xlsxrb/ooxml/xml_builder.rbs +19 -1
- data/sig/generated/xlsxrb/ooxml/xml_parser.rbs +21 -0
- data/sig/generated/xlsxrb/ooxml/zip_writer.rbs +5 -0
- data/sig/generated/xlsxrb/stream_row.rbs +4 -3
- data/sig/generated/xlsxrb/style_builder.rbs +5 -5
- data/sig/generated/xlsxrb.rbs +41 -20
- metadata +1 -1
|
@@ -10,59 +10,60 @@ module Xlsxrb
|
|
|
10
10
|
# : (untyped pivot_table, untyped cache_id) -> untyped
|
|
11
11
|
def generate_pivot_table_xml(pivot_table, cache_id)
|
|
12
12
|
data_caption = pivot_table[:data_caption] || (pivot_table[:data_fields].first ? pivot_table[:data_fields].first[:name] : "Values")
|
|
13
|
-
pt_attrs = %( xmlns="#{SSML_NS}" name="#{xml_escape(pivot_table[:name])}" cacheId="#{xml_escape(cache_id)}" dataCaption="#{xml_escape(data_caption)}")
|
|
14
|
-
pt_attrs << %( grandTotalCaption="#{xml_escape(pivot_table[:grand_total_caption])}") if pivot_table[:grand_total_caption]
|
|
15
|
-
pt_attrs << %( errorCaption="#{xml_escape(pivot_table[:error_caption])}") if pivot_table[:error_caption]
|
|
16
|
-
pt_attrs << ' showError="1"' if pivot_table[:show_error]
|
|
17
|
-
pt_attrs << %( missingCaption="#{xml_escape(pivot_table[:missing_caption])}") if pivot_table[:missing_caption]
|
|
18
|
-
pt_attrs << ' showMissing="0"' if pivot_table[:show_missing] == false
|
|
19
|
-
pt_attrs << %( tag="#{xml_escape(pivot_table[:tag])}") if pivot_table[:tag]
|
|
20
|
-
pt_attrs << %( dataOnRows="1") if pivot_table[:data_on_rows]
|
|
21
|
-
pt_attrs << %( dataOnRows="0") unless pivot_table[:data_on_rows]
|
|
22
|
-
pt_attrs << %( rowGrandTotals="0") if pivot_table[:row_grand_totals] == false
|
|
23
|
-
pt_attrs << %( colGrandTotals="0") if pivot_table[:col_grand_totals] == false
|
|
24
|
-
pt_attrs << %( compact="0") if pivot_table[:compact] == false
|
|
25
|
-
pt_attrs << %( outline="0") if pivot_table[:outline] == false
|
|
26
|
-
pt_attrs << %( outlineData="1") if pivot_table[:outline_data]
|
|
27
|
-
pt_attrs << %( compactData="0") if pivot_table[:compact_data] == false
|
|
28
|
-
pt_attrs << %( showHeaders="0") if pivot_table[:show_headers] == false
|
|
29
|
-
pt_attrs << %( showMultipleLabel="0") if pivot_table[:show_multiple_label] == false
|
|
30
|
-
pt_attrs << %( showDataDropDown="0") if pivot_table[:show_data_drop_down] == false
|
|
31
|
-
pt_attrs << %( indent="#{xml_escape(pivot_table[:indent])}") if pivot_table[:indent]
|
|
32
|
-
pt_attrs << ' published="1"' if pivot_table[:published]
|
|
33
|
-
pt_attrs << ' editData="1"' if pivot_table[:edit_data]
|
|
34
|
-
pt_attrs << ' disableFieldList="1"' if pivot_table[:disable_field_list]
|
|
35
|
-
pt_attrs << ' visualTotals="0"' if pivot_table[:visual_totals] == false
|
|
36
|
-
pt_attrs << ' printDrill="1"' if pivot_table[:print_drill]
|
|
37
|
-
pt_attrs << %( createdVersion="#{xml_escape(pivot_table[:created_version])}") if pivot_table[:created_version]
|
|
38
|
-
pt_attrs << %( updatedVersion="#{xml_escape(pivot_table[:updated_version])}") if pivot_table[:updated_version]
|
|
39
|
-
pt_attrs << %( minRefreshableVersion="#{xml_escape(pivot_table[:min_refreshable_version])}") if pivot_table[:min_refreshable_version]
|
|
40
13
|
anf = pivot_table.fetch(:apply_number_formats, false)
|
|
41
14
|
abf = pivot_table.fetch(:apply_border_formats, false)
|
|
42
15
|
aff = pivot_table.fetch(:apply_font_formats, false)
|
|
43
16
|
apf = pivot_table.fetch(:apply_pattern_formats, false)
|
|
44
17
|
aaf = pivot_table.fetch(:apply_alignment_formats, false)
|
|
45
18
|
awf = pivot_table.fetch(:apply_width_height_formats, true)
|
|
46
|
-
|
|
47
|
-
pt_attrs
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
19
|
+
|
|
20
|
+
pt_attrs = {
|
|
21
|
+
xmlns: SSML_NS,
|
|
22
|
+
name: pivot_table[:name] || "",
|
|
23
|
+
cacheId: cache_id || "",
|
|
24
|
+
dataCaption: data_caption || "",
|
|
25
|
+
grandTotalCaption: pivot_table[:grand_total_caption],
|
|
26
|
+
errorCaption: pivot_table[:error_caption],
|
|
27
|
+
showError: pivot_table[:show_error] ? 1 : nil,
|
|
28
|
+
missingCaption: pivot_table[:missing_caption],
|
|
29
|
+
showMissing: pivot_table[:show_missing] == false ? 0 : nil,
|
|
30
|
+
tag: pivot_table[:tag],
|
|
31
|
+
dataOnRows: pivot_table[:data_on_rows] ? 1 : 0,
|
|
32
|
+
rowGrandTotals: pivot_table[:row_grand_totals] == false ? 0 : nil,
|
|
33
|
+
colGrandTotals: pivot_table[:col_grand_totals] == false ? 0 : nil,
|
|
34
|
+
compact: pivot_table[:compact] == false ? 0 : nil,
|
|
35
|
+
outline: pivot_table[:outline] == false ? 0 : nil,
|
|
36
|
+
outlineData: pivot_table[:outline_data] ? 1 : nil,
|
|
37
|
+
compactData: pivot_table[:compact_data] == false ? 0 : nil,
|
|
38
|
+
showHeaders: pivot_table[:show_headers] == false ? 0 : nil,
|
|
39
|
+
showMultipleLabel: pivot_table[:show_multiple_label] == false ? 0 : nil,
|
|
40
|
+
showDataDropDown: pivot_table[:show_data_drop_down] == false ? 0 : nil,
|
|
41
|
+
indent: pivot_table[:indent],
|
|
42
|
+
published: pivot_table[:published] ? 1 : nil,
|
|
43
|
+
editData: pivot_table[:edit_data] ? 1 : nil,
|
|
44
|
+
disableFieldList: pivot_table[:disable_field_list] ? 1 : nil,
|
|
45
|
+
visualTotals: pivot_table[:visual_totals] == false ? 0 : nil,
|
|
46
|
+
printDrill: pivot_table[:print_drill] ? 1 : nil,
|
|
47
|
+
createdVersion: pivot_table[:created_version],
|
|
48
|
+
updatedVersion: pivot_table[:updated_version],
|
|
49
|
+
minRefreshableVersion: pivot_table[:min_refreshable_version],
|
|
50
|
+
applyNumberFormats: anf ? 1 : 0,
|
|
51
|
+
applyBorderFormats: abf ? 1 : 0,
|
|
52
|
+
applyFontFormats: aff ? 1 : 0,
|
|
53
|
+
applyPatternFormats: apf ? 1 : 0,
|
|
54
|
+
applyAlignmentFormats: aaf ? 1 : 0,
|
|
55
|
+
applyWidthHeightFormats: awf ? 1 : 0,
|
|
56
|
+
multipleFieldFilters: pivot_table[:multiple_field_filters] == false ? 0 : nil,
|
|
57
|
+
showDrill: pivot_table[:show_drill] == false ? 0 : nil,
|
|
58
|
+
showDataTips: pivot_table[:show_data_tips] == false ? 0 : nil,
|
|
59
|
+
enableDrill: pivot_table[:enable_drill] == false ? 0 : nil,
|
|
60
|
+
showMemberPropertyTips: pivot_table[:show_member_property_tips] == false ? 0 : nil,
|
|
61
|
+
itemPrintTitles: pivot_table[:item_print_titles] ? 1 : nil,
|
|
62
|
+
fieldPrintTitles: pivot_table[:field_print_titles] ? 1 : nil,
|
|
63
|
+
preserveFormatting: pivot_table[:preserve_formatting] == false ? 0 : nil,
|
|
64
|
+
pageOverThenDown: pivot_table[:page_over_then_down] ? 1 : nil,
|
|
65
|
+
pageWrap: pivot_table[:page_wrap]
|
|
66
|
+
}
|
|
66
67
|
|
|
67
68
|
# Compute field count from source range or explicit field_names.
|
|
68
69
|
field_count = if pivot_table[:field_names]
|
|
@@ -70,251 +71,272 @@ module Xlsxrb
|
|
|
70
71
|
else
|
|
71
72
|
(pivot_table[:row_fields].size + pivot_table[:col_fields].size + pivot_table[:data_fields].size).clamp(1, 100)
|
|
72
73
|
end
|
|
73
|
-
loc_attrs = %(<location ref="#{xml_escape(pivot_table[:dest_ref])}" firstHeaderRow="#{xml_escape(pivot_table[:first_header_row] || 1)}" ) +
|
|
74
|
-
%(firstDataRow="#{xml_escape(pivot_table[:first_data_row] || 1)}" firstDataCol="#{xml_escape(pivot_table[:first_data_col] || 1)}")
|
|
75
|
-
loc_attrs << %( rowPageCount="#{xml_escape(pivot_table[:row_page_count])}") if pivot_table[:row_page_count]
|
|
76
|
-
loc_attrs << %( colPageCount="#{xml_escape(pivot_table[:col_page_count])}") if pivot_table[:col_page_count]
|
|
77
|
-
loc_attrs << "/>"
|
|
78
|
-
parts << loc_attrs
|
|
79
|
-
parts << %(<pivotFields count="#{xml_escape(field_count)}">)
|
|
80
|
-
field_count.times do |fi|
|
|
81
|
-
attrs = +""
|
|
82
|
-
if pivot_table[:row_fields].include?(fi)
|
|
83
|
-
attrs << ' axis="axisRow"'
|
|
84
|
-
elsif pivot_table[:col_fields].include?(fi)
|
|
85
|
-
attrs << ' axis="axisCol"'
|
|
86
|
-
end
|
|
87
|
-
attrs << ' dataField="1"' if pivot_table[:data_fields].any? { |df| df[:fld] == fi }
|
|
88
|
-
fa = pivot_table[:field_attrs] && pivot_table[:field_attrs][fi]
|
|
89
|
-
attrs << %( compact="#{fa[:compact] ? "1" : "0"}") if fa && !fa[:compact].nil?
|
|
90
|
-
attrs << %( outline="#{fa[:outline] ? "1" : "0"}") if fa && !fa[:outline].nil?
|
|
91
|
-
attrs << %( subtotalTop="#{fa[:subtotal_top] ? "1" : "0"}") if fa && !fa[:subtotal_top].nil?
|
|
92
|
-
attrs << %( showAll="#{fa && fa[:show_all] == true ? "1" : "0"}")
|
|
93
|
-
attrs << %( numFmtId="#{xml_escape(fa[:num_fmt_id])}") if fa && fa[:num_fmt_id]
|
|
94
|
-
attrs << %( sortType="#{xml_escape(fa[:sort_type])}") if fa && fa[:sort_type]
|
|
95
|
-
attrs << ' defaultSubtotal="0"' if fa && fa[:default_subtotal] == false
|
|
96
|
-
attrs << ' insertBlankRow="1"' if fa && fa[:insert_blank_row]
|
|
97
|
-
attrs << ' insertPageBreak="1"' if fa && fa[:insert_page_break]
|
|
98
|
-
attrs << ' includeNewItemsInFilter="1"' if fa && fa[:include_new_items_in_filter]
|
|
99
|
-
|
|
100
|
-
field_items = pivot_table[:items] && pivot_table[:items][fi]
|
|
101
|
-
axis_field = pivot_table[:row_fields].include?(fi) || pivot_table[:col_fields].include?(fi)
|
|
102
|
-
# The default subtotal item goes with the default subtotal; a field with
|
|
103
|
-
# defaultSubtotal="0" must not list it.
|
|
104
|
-
default_subtotal = !(fa && fa[:default_subtotal] == false)
|
|
105
|
-
if field_items || (axis_field && default_subtotal)
|
|
106
|
-
# A row or column field needs an <items> list; without known items it holds only the
|
|
107
|
-
# default subtotal, which Excel fills in when it refreshes the cache on open.
|
|
108
|
-
field_items ||= []
|
|
109
|
-
parts << "<pivotField#{attrs}>"
|
|
110
|
-
parts << %(<items count="#{xml_escape(field_items.size + (default_subtotal ? 1 : 0))}">)
|
|
111
|
-
field_items.size.times { |ix| parts << %(<item x="#{xml_escape(ix)}"/>) }
|
|
112
|
-
parts << '<item t="default"/>' if default_subtotal
|
|
113
|
-
parts << "</items>"
|
|
114
|
-
parts << "</pivotField>"
|
|
115
|
-
else
|
|
116
|
-
parts << "<pivotField#{attrs}/>"
|
|
117
|
-
end
|
|
118
|
-
end
|
|
119
|
-
parts << "</pivotFields>"
|
|
120
74
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
75
|
+
XmlBuilder.build(declaration: :plain) do |xml|
|
|
76
|
+
xml.tag("pivotTableDefinition", pt_attrs) do
|
|
77
|
+
xml.empty_tag("location", {
|
|
78
|
+
ref: pivot_table[:dest_ref] || "",
|
|
79
|
+
firstHeaderRow: pivot_table[:first_header_row] || 1,
|
|
80
|
+
firstDataRow: pivot_table[:first_data_row] || 1,
|
|
81
|
+
firstDataCol: pivot_table[:first_data_col] || 1,
|
|
82
|
+
rowPageCount: pivot_table[:row_page_count],
|
|
83
|
+
colPageCount: pivot_table[:col_page_count]
|
|
84
|
+
})
|
|
85
|
+
xml.tag("pivotFields", { count: field_count }) do
|
|
86
|
+
field_count.times do |fi|
|
|
87
|
+
axis_val = if pivot_table[:row_fields].include?(fi)
|
|
88
|
+
"axisRow"
|
|
89
|
+
elsif pivot_table[:col_fields].include?(fi)
|
|
90
|
+
"axisCol"
|
|
91
|
+
end
|
|
92
|
+
fa = pivot_table[:field_attrs] && pivot_table[:field_attrs][fi]
|
|
93
|
+
pf_attrs = {
|
|
94
|
+
axis: axis_val,
|
|
95
|
+
dataField: pivot_table[:data_fields].any? { |df| df[:fld] == fi } ? 1 : nil,
|
|
96
|
+
compact: xml_bool_attr(fa&.[](:compact)),
|
|
97
|
+
outline: xml_bool_attr(fa&.[](:outline)),
|
|
98
|
+
subtotalTop: xml_bool_attr(fa&.[](:subtotal_top)),
|
|
99
|
+
showAll: fa && fa[:show_all] == true ? "1" : "0",
|
|
100
|
+
numFmtId: fa && fa[:num_fmt_id] ? fa[:num_fmt_id] : nil,
|
|
101
|
+
sortType: fa && fa[:sort_type] ? fa[:sort_type] : nil,
|
|
102
|
+
defaultSubtotal: fa && fa[:default_subtotal] == false ? 0 : nil,
|
|
103
|
+
insertBlankRow: fa && fa[:insert_blank_row] ? 1 : nil,
|
|
104
|
+
insertPageBreak: fa && fa[:insert_page_break] ? 1 : nil,
|
|
105
|
+
includeNewItemsInFilter: fa && fa[:include_new_items_in_filter] ? 1 : nil
|
|
106
|
+
}
|
|
107
|
+
field_items = pivot_table[:items] && pivot_table[:items][fi]
|
|
108
|
+
axis_field = pivot_table[:row_fields].include?(fi) || pivot_table[:col_fields].include?(fi)
|
|
109
|
+
# The default subtotal item goes with the default subtotal; a field with
|
|
110
|
+
# defaultSubtotal="0" must not list it.
|
|
111
|
+
default_subtotal = !(fa && fa[:default_subtotal] == false)
|
|
112
|
+
if field_items || (axis_field && default_subtotal)
|
|
113
|
+
# A row or column field needs an <items> list; without known items it holds only the
|
|
114
|
+
# default subtotal, which Excel fills in when it refreshes the cache on open.
|
|
115
|
+
field_items ||= []
|
|
116
|
+
xml.tag("pivotField", pf_attrs) do
|
|
117
|
+
xml.tag("items", { count: field_items.size + (default_subtotal ? 1 : 0) }) do
|
|
118
|
+
field_items.size.times { |ix| xml.empty_tag("item", { x: ix }) }
|
|
119
|
+
xml.empty_tag("item", { t: "default" }) if default_subtotal
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
else
|
|
123
|
+
xml.empty_tag("pivotField", pf_attrs)
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
end
|
|
126
127
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
128
|
+
unless pivot_table[:row_fields].empty?
|
|
129
|
+
xml.tag("rowFields", { count: pivot_table[:row_fields].size }) do
|
|
130
|
+
pivot_table[:row_fields].each { |f| xml.empty_tag("field", { x: f || "" }) }
|
|
131
|
+
end
|
|
132
|
+
end
|
|
132
133
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
df_attrs << %( baseField="#{xml_escape(df[:base_field])}") if df[:base_field]
|
|
139
|
-
df_attrs << %( baseItem="#{xml_escape(df[:base_item])}") if df[:base_item]
|
|
140
|
-
df_attrs << %( numFmtId="#{xml_escape(df[:num_fmt_id])}") if df[:num_fmt_id]
|
|
141
|
-
parts << "<dataField#{df_attrs}/>"
|
|
142
|
-
end
|
|
143
|
-
parts << "</dataFields>"
|
|
144
|
-
end
|
|
134
|
+
unless pivot_table[:col_fields].empty?
|
|
135
|
+
xml.tag("colFields", { count: pivot_table[:col_fields].size }) do
|
|
136
|
+
pivot_table[:col_fields].each { |f| xml.empty_tag("field", { x: f || "" }) }
|
|
137
|
+
end
|
|
138
|
+
end
|
|
145
139
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
140
|
+
unless pivot_table[:data_fields].empty?
|
|
141
|
+
xml.tag("dataFields", { count: pivot_table[:data_fields].size }) do
|
|
142
|
+
pivot_table[:data_fields].each do |df|
|
|
143
|
+
xml.empty_tag("dataField", {
|
|
144
|
+
name: df[:name] || "",
|
|
145
|
+
fld: df[:fld] || "",
|
|
146
|
+
subtotal: df[:subtotal] || "sum",
|
|
147
|
+
showDataAs: df[:show_data_as],
|
|
148
|
+
baseField: df[:base_field],
|
|
149
|
+
baseItem: df[:base_item],
|
|
150
|
+
numFmtId: df[:num_fmt_id]
|
|
151
|
+
})
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
end
|
|
157
155
|
|
|
158
|
-
|
|
159
|
-
|
|
156
|
+
if (psi = pivot_table[:pivot_table_style])
|
|
157
|
+
xml.empty_tag("pivotTableStyleInfo", {
|
|
158
|
+
name: psi[:name],
|
|
159
|
+
showRowHeaders: xml_bool_attr(psi[:show_row_headers]),
|
|
160
|
+
showColHeaders: xml_bool_attr(psi[:show_col_headers]),
|
|
161
|
+
showRowStripes: xml_bool_attr(psi[:show_row_stripes]),
|
|
162
|
+
showColStripes: xml_bool_attr(psi[:show_col_stripes]),
|
|
163
|
+
showLastColumn: xml_bool_attr(psi[:show_last_column])
|
|
164
|
+
})
|
|
165
|
+
end
|
|
166
|
+
end
|
|
167
|
+
end
|
|
160
168
|
end
|
|
161
169
|
|
|
162
170
|
# : (untyped pivot_table, untyped _cache_id) -> untyped
|
|
163
171
|
def generate_pivot_cache_definition_xml(pivot_table, _cache_id)
|
|
164
|
-
pcd_attrs =
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
172
|
+
pcd_attrs = {
|
|
173
|
+
xmlns: SSML_NS,
|
|
174
|
+
"xmlns:r": DOC_REL_NS,
|
|
175
|
+
"r:id": "rId1",
|
|
176
|
+
refreshOnLoad: 1,
|
|
177
|
+
saveData: pivot_table[:cache_save_data] == false ? 0 : nil,
|
|
178
|
+
enableRefresh: pivot_table[:cache_enable_refresh] == false ? 0 : nil,
|
|
179
|
+
refreshedBy: pivot_table[:cache_refreshed_by],
|
|
180
|
+
refreshedVersion: pivot_table[:cache_refreshed_version],
|
|
181
|
+
createdVersion: pivot_table[:cache_created_version],
|
|
182
|
+
recordCount: pivot_table[:cache_record_count],
|
|
183
|
+
optimizeMemory: pivot_table[:cache_optimize_memory] ? 1 : nil
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
XmlBuilder.build(declaration: :plain) do |xml|
|
|
187
|
+
xml.tag("pivotCacheDefinition", pcd_attrs) do
|
|
188
|
+
# Parse source ref: "Sheet1!A1:C4" => sheet name + range.
|
|
189
|
+
source = pivot_table[:source_ref]
|
|
190
|
+
ws_attrs = {}
|
|
191
|
+
if source&.include?("!")
|
|
192
|
+
sname, srange = source.split("!", 2)
|
|
193
|
+
ws_attrs[:ref] = srange
|
|
194
|
+
ws_attrs[:sheet] = sname.delete("'")
|
|
195
|
+
elsif !source.nil?
|
|
196
|
+
ws_attrs[:ref] = source
|
|
197
|
+
end
|
|
198
|
+
ws_attrs[:name] = pivot_table[:source_name] if pivot_table[:source_name]
|
|
199
|
+
xml.tag("cacheSource", { type: "worksheet" }) do
|
|
200
|
+
xml.empty_tag("worksheetSource", ws_attrs)
|
|
201
|
+
end
|
|
189
202
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
203
|
+
field_count = pivot_table[:field_names] ? pivot_table[:field_names].size : (pivot_table[:row_fields].size + pivot_table[:col_fields].size + pivot_table[:data_fields].size)
|
|
204
|
+
xml.tag("cacheFields", { count: field_count }) do
|
|
205
|
+
field_count.times do |fi|
|
|
206
|
+
fname = if pivot_table[:field_names] && pivot_table[:field_names][fi]
|
|
207
|
+
pivot_table[:field_names][fi]
|
|
208
|
+
else
|
|
209
|
+
df = pivot_table[:data_fields].find { |d| d[:fld] == fi }
|
|
210
|
+
df ? df[:name] : "Field#{fi + 1}"
|
|
211
|
+
end
|
|
212
|
+
fa = pivot_table[:field_attrs] && pivot_table[:field_attrs][fi]
|
|
213
|
+
cf_attrs = {
|
|
214
|
+
name: fname || "",
|
|
215
|
+
numFmtId: (fa && fa[:cache_num_fmt_id]) || 0,
|
|
216
|
+
caption: fa && fa[:cache_caption] ? fa[:cache_caption] : nil,
|
|
217
|
+
formula: fa && fa[:cache_formula] ? fa[:cache_formula] : nil
|
|
218
|
+
}
|
|
219
|
+
field_items = pivot_table[:items] && pivot_table[:items][fi]
|
|
220
|
+
xml.tag("cacheField", cf_attrs) do
|
|
221
|
+
if field_items
|
|
222
|
+
write_shared_items_xml(xml, field_items)
|
|
195
223
|
else
|
|
196
|
-
|
|
197
|
-
df ? df[:name] : "Field#{fi + 1}"
|
|
224
|
+
xml.empty_tag("sharedItems")
|
|
198
225
|
end
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
cf_attrs << %( caption="#{xml_escape(fa[:cache_caption])}") if fa && fa[:cache_caption]
|
|
203
|
-
cf_attrs << %( formula="#{xml_escape(fa[:cache_formula])}") if fa && fa[:cache_formula]
|
|
204
|
-
field_items = pivot_table[:items] && pivot_table[:items][fi]
|
|
205
|
-
if field_items
|
|
206
|
-
parts << "<cacheField#{cf_attrs}>"
|
|
207
|
-
parts << %(<sharedItems#{shared_items_attrs(field_items)} count="#{field_items.size}">)
|
|
208
|
-
field_items.each { |v| parts << shared_item_xml(v) }
|
|
209
|
-
parts << "</sharedItems>"
|
|
210
|
-
parts << "</cacheField>"
|
|
211
|
-
else
|
|
212
|
-
parts << "<cacheField#{cf_attrs}><sharedItems/></cacheField>"
|
|
226
|
+
end
|
|
227
|
+
end
|
|
228
|
+
end
|
|
213
229
|
end
|
|
214
230
|
end
|
|
215
|
-
parts << "</cacheFields>"
|
|
216
|
-
parts << "</pivotCacheDefinition>"
|
|
217
|
-
parts.join
|
|
218
231
|
end
|
|
219
232
|
|
|
220
|
-
#
|
|
221
|
-
# : (Array[untyped] values) ->
|
|
222
|
-
def
|
|
233
|
+
# Writes <sharedItems> and its typed children for a cache field.
|
|
234
|
+
# : (XmlBuilder xml, Array[untyped] values) -> void
|
|
235
|
+
def write_shared_items_xml(xml, values)
|
|
223
236
|
numbers = values.grep(Numeric)
|
|
224
237
|
strings = values.any? { |v| !v.nil? && !v.is_a?(Numeric) && v != true && v != false }
|
|
225
|
-
attrs =
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
238
|
+
attrs = {
|
|
239
|
+
containsSemiMixedTypes: strings || values.include?(nil) ? nil : 0,
|
|
240
|
+
containsString: strings ? nil : 0,
|
|
241
|
+
containsBlank: values.include?(nil) ? 1 : nil,
|
|
242
|
+
containsNumber: numbers.empty? ? nil : 1,
|
|
243
|
+
containsInteger: !numbers.empty? && numbers.all? { |n| n.is_a?(Integer) || n == n.to_i } ? 1 : nil,
|
|
244
|
+
minValue: numbers.empty? ? nil : numbers.min,
|
|
245
|
+
maxValue: numbers.empty? ? nil : numbers.max,
|
|
246
|
+
count: values.size
|
|
247
|
+
}
|
|
248
|
+
xml.tag("sharedItems", attrs) do
|
|
249
|
+
values.each do |value|
|
|
250
|
+
case value
|
|
251
|
+
when nil then xml.empty_tag("m")
|
|
252
|
+
when true, false then xml.empty_tag("b", { v: value ? 1 : 0 })
|
|
253
|
+
when Numeric then xml.empty_tag("n", { v: value })
|
|
254
|
+
else xml.empty_tag("s", { v: value.to_s })
|
|
255
|
+
end
|
|
256
|
+
end
|
|
244
257
|
end
|
|
245
258
|
end
|
|
246
259
|
|
|
247
260
|
# : (untyped pivot_table) -> untyped
|
|
248
261
|
def generate_pivot_cache_records_xml(pivot_table)
|
|
249
262
|
items = pivot_table[:items]
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
max_len.times do |ri|
|
|
254
|
-
parts << "<r>"
|
|
263
|
+
XmlBuilder.build(declaration: :plain) do |xml|
|
|
264
|
+
if items&.values&.any? { |v| v && !v.empty? }
|
|
265
|
+
max_len = items.values.map { |v| v ? v.size : 0 }.max
|
|
255
266
|
field_count = pivot_table[:field_names] ? pivot_table[:field_names].size : (pivot_table[:row_fields].size + pivot_table[:col_fields].size + pivot_table[:data_fields].size)
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
267
|
+
xml.tag("pivotCacheRecords", { xmlns: SSML_NS, count: max_len }) do
|
|
268
|
+
max_len.times do |ri|
|
|
269
|
+
xml.tag("r") do
|
|
270
|
+
field_count.times do |fi|
|
|
271
|
+
field_items = items[fi]
|
|
272
|
+
if field_items
|
|
273
|
+
xml.empty_tag("x", { v: ri < field_items.size ? ri : 0 })
|
|
274
|
+
else
|
|
275
|
+
xml.empty_tag("n", { v: 0 })
|
|
276
|
+
end
|
|
277
|
+
end
|
|
278
|
+
end
|
|
279
|
+
end
|
|
263
280
|
end
|
|
264
|
-
|
|
281
|
+
else
|
|
282
|
+
xml.empty_tag("pivotCacheRecords", { xmlns: SSML_NS, count: 0 })
|
|
265
283
|
end
|
|
266
|
-
parts << "</pivotCacheRecords>"
|
|
267
|
-
parts.join
|
|
268
|
-
else
|
|
269
|
-
[XML_HEADER, %(<pivotCacheRecords xmlns="#{SSML_NS}" count="0"/>)].join
|
|
270
284
|
end
|
|
271
285
|
end
|
|
272
286
|
|
|
273
287
|
# : (untyped cache_id) -> untyped
|
|
274
288
|
def generate_pivot_cache_rels(cache_id)
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
289
|
+
XmlBuilder.build(declaration: :plain) do |xml|
|
|
290
|
+
xml.tag("Relationships", { xmlns: REL_NS }) do
|
|
291
|
+
xml.empty_tag("Relationship", {
|
|
292
|
+
Id: "rId1",
|
|
293
|
+
Type: "#{DOC_REL_NS}/pivotCacheRecords",
|
|
294
|
+
Target: "pivotCacheRecords#{cache_id}.xml"
|
|
295
|
+
})
|
|
296
|
+
end
|
|
297
|
+
end
|
|
281
298
|
end
|
|
282
299
|
|
|
283
300
|
# : (untyped cache_id) -> untyped
|
|
284
301
|
def generate_pivot_table_rels(cache_id)
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
302
|
+
XmlBuilder.build(declaration: :plain) do |xml|
|
|
303
|
+
xml.tag("Relationships", { xmlns: REL_NS }) do
|
|
304
|
+
xml.empty_tag("Relationship", {
|
|
305
|
+
Id: "rId1",
|
|
306
|
+
Type: "#{DOC_REL_NS}/pivotCacheDefinition",
|
|
307
|
+
Target: "../pivotCache/pivotCacheDefinition#{cache_id}.xml"
|
|
308
|
+
})
|
|
309
|
+
end
|
|
310
|
+
end
|
|
291
311
|
end
|
|
292
312
|
|
|
293
313
|
# : (untyped ext_link) -> untyped
|
|
294
314
|
def generate_external_link_xml(ext_link)
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
315
|
+
XmlBuilder.build(declaration: :plain) do |xml|
|
|
316
|
+
xml.tag("externalLink", { xmlns: SSML_NS, "xmlns:r": DOC_REL_NS }) do
|
|
317
|
+
xml.tag("externalBook", { "r:id": "rId1" }) do
|
|
318
|
+
unless ext_link[:sheet_names].empty?
|
|
319
|
+
xml.tag("sheetNames") do
|
|
320
|
+
ext_link[:sheet_names].each { |sn| xml.empty_tag("sheetName", { val: sn || "" }) }
|
|
321
|
+
end
|
|
322
|
+
end
|
|
323
|
+
end
|
|
324
|
+
end
|
|
304
325
|
end
|
|
305
|
-
parts << "</externalBook>"
|
|
306
|
-
parts << "</externalLink>"
|
|
307
|
-
parts.join
|
|
308
326
|
end
|
|
309
327
|
|
|
310
328
|
# : (untyped ext_link) -> untyped
|
|
311
329
|
def generate_external_link_rels(ext_link)
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
330
|
+
XmlBuilder.build(declaration: :plain) do |xml|
|
|
331
|
+
xml.tag("Relationships", { xmlns: REL_NS }) do
|
|
332
|
+
xml.empty_tag("Relationship", {
|
|
333
|
+
Id: "rId1",
|
|
334
|
+
Type: "#{DOC_REL_NS}/externalLinkPath",
|
|
335
|
+
Target: ext_link[:target] || "",
|
|
336
|
+
TargetMode: "External"
|
|
337
|
+
})
|
|
338
|
+
end
|
|
339
|
+
end
|
|
318
340
|
end
|
|
319
341
|
|
|
320
342
|
# : (untyped ct_xml) -> untyped
|
|
@@ -327,149 +349,142 @@ module Xlsxrb
|
|
|
327
349
|
end
|
|
328
350
|
end
|
|
329
351
|
|
|
330
|
-
# : (untyped element, untyped opts) ->
|
|
331
|
-
def
|
|
332
|
-
return
|
|
352
|
+
# : (XmlBuilder xml, untyped element, untyped opts) -> void
|
|
353
|
+
def write_line_end_xml(xml, element, opts)
|
|
354
|
+
return unless opts
|
|
333
355
|
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
356
|
+
xml.empty_tag("a:#{element}", {
|
|
357
|
+
type: opts[:type],
|
|
358
|
+
w: opts[:w],
|
|
359
|
+
len: opts[:len]
|
|
360
|
+
})
|
|
339
361
|
end
|
|
340
362
|
|
|
341
|
-
# : (untyped
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
str = value.to_s
|
|
345
|
-
str = str.dup.force_encoding(Encoding::UTF_8) if str.encoding == Encoding::BINARY
|
|
346
|
-
xml_escape(XmlBuilder.encode_xstring(str))
|
|
347
|
-
end
|
|
348
|
-
|
|
349
|
-
def xml_escape(value)
|
|
350
|
-
value.to_s
|
|
351
|
-
.gsub(/[^\x09\x0A\x0D\x20-\uD7FF\uE000-\uFFFD\u{10000}-\u{10FFFF}]/, "")
|
|
352
|
-
.gsub("&", "&")
|
|
353
|
-
.gsub("<", "<")
|
|
354
|
-
.gsub(">", ">")
|
|
355
|
-
.gsub('"', """)
|
|
356
|
-
.gsub("'", "'")
|
|
357
|
-
end
|
|
358
|
-
|
|
359
|
-
# : (untyped rich_text) -> untyped
|
|
360
|
-
def rich_text_xml(rich_text)
|
|
361
|
-
rich_text.runs.map do |run|
|
|
363
|
+
# : (XmlBuilder xml, untyped rich_text) -> void
|
|
364
|
+
def write_rich_text_xml(xml, rich_text)
|
|
365
|
+
rich_text.runs.each do |run|
|
|
362
366
|
font = run.respond_to?(:font) ? run.font : run[:font]
|
|
363
367
|
text = run.respond_to?(:text) ? run.text : run[:text]
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
368
|
+
xml.tag("r") do
|
|
369
|
+
if font && !font.empty?
|
|
370
|
+
xml.tag("rPr") do
|
|
371
|
+
xml.empty_tag("b") if font[:bold]
|
|
372
|
+
xml.empty_tag("i") if font[:italic]
|
|
373
|
+
xml.empty_tag("strike") if font[:strike]
|
|
374
|
+
if font[:underline]
|
|
375
|
+
u_val = font[:underline]
|
|
376
|
+
if u_val == true || u_val.to_s == "single"
|
|
377
|
+
xml.empty_tag("u")
|
|
378
|
+
else
|
|
379
|
+
mapped_u = StyleBuilder::UNDERLINE_MAP[u_val.to_sym] || u_val
|
|
380
|
+
xml.empty_tag("u", { val: mapped_u })
|
|
381
|
+
end
|
|
382
|
+
end
|
|
383
|
+
va_val = font[:vert_align] || font[:vertical_align]
|
|
384
|
+
va_val ||= "superscript" if font[:superscript]
|
|
385
|
+
va_val ||= "subscript" if font[:subscript]
|
|
386
|
+
if va_val
|
|
387
|
+
mapped_va = StyleBuilder::VERT_ALIGN_MAP[va_val.to_sym] || va_val
|
|
388
|
+
xml.empty_tag("vertAlign", { val: mapped_va })
|
|
389
|
+
end
|
|
390
|
+
font_sz = font[:size] || font[:sz]
|
|
391
|
+
xml.empty_tag("sz", { val: font_sz }) if font_sz
|
|
392
|
+
write_color_xml(xml, font)
|
|
393
|
+
xml.empty_tag("rFont", { val: font[:name] }) if font[:name]
|
|
394
|
+
xml.empty_tag("family", { val: font[:family] }) if font[:family]
|
|
395
|
+
xml.empty_tag("scheme", { val: font[:scheme] }) if font[:scheme]
|
|
376
396
|
end
|
|
377
397
|
end
|
|
378
|
-
|
|
379
|
-
va_val ||= "superscript" if font[:superscript]
|
|
380
|
-
va_val ||= "subscript" if font[:subscript]
|
|
381
|
-
if va_val
|
|
382
|
-
mapped_va = StyleBuilder::VERT_ALIGN_MAP[va_val.to_sym] || va_val
|
|
383
|
-
rpr << %(<vertAlign val="#{xml_escape(mapped_va)}"/>)
|
|
384
|
-
end
|
|
385
|
-
font_sz = font[:size] || font[:sz]
|
|
386
|
-
rpr << %(<sz val="#{xml_escape(font_sz)}"/>) if font_sz
|
|
387
|
-
rpr << emit_color_xml(font)
|
|
388
|
-
rpr << %(<rFont val="#{xml_escape(font[:name])}"/>) if font[:name]
|
|
389
|
-
rpr << %(<family val="#{xml_escape(font[:family])}"/>) if font[:family]
|
|
390
|
-
rpr << %(<scheme val="#{xml_escape(font[:scheme])}"/>) if font[:scheme]
|
|
391
|
-
"<r><rPr>#{rpr}</rPr><t>#{xml_escape_text(text)}</t></r>"
|
|
392
|
-
else
|
|
393
|
-
"<r><t>#{xml_escape_text(text)}</t></r>"
|
|
398
|
+
xml.tag("t") { xml.xstring_text(text) }
|
|
394
399
|
end
|
|
395
|
-
end
|
|
400
|
+
end
|
|
396
401
|
end
|
|
397
402
|
|
|
398
|
-
# : (untyped cell_ref, untyped value, untyped style_idx, ?untyped? sst, ?ph: untyped?) ->
|
|
399
|
-
def
|
|
400
|
-
|
|
401
|
-
ph_attr = ph ? ' ph="1"' : ""
|
|
403
|
+
# : (XmlBuilder xml, untyped cell_ref, untyped value, untyped style_idx, ?untyped? sst, ?ph: untyped?) -> void
|
|
404
|
+
def write_cell_xml(xml, cell_ref, value, style_idx, sst = nil, ph: nil) # rubocop:disable Naming/MethodParameterName
|
|
405
|
+
ph_val = ph ? 1 : nil
|
|
402
406
|
case value
|
|
403
407
|
when Xlsxrb::Elements::CellError
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
f_attrs = +""
|
|
407
|
-
case value.type
|
|
408
|
-
when :shared
|
|
409
|
-
f_attrs << %( t="shared" si="#{xml_escape(value.shared_index)}")
|
|
410
|
-
f_attrs << %( ref="#{xml_escape(value.ref)}") if value.ref
|
|
411
|
-
when :array
|
|
412
|
-
f_attrs << %( t="array" ref="#{xml_escape(value.ref)}") if value.ref
|
|
413
|
-
when :data_table
|
|
414
|
-
f_attrs << ' t="dataTable"'
|
|
415
|
-
f_attrs << ' dt2D="1"' if value.dt2d
|
|
416
|
-
f_attrs << ' dtr="1"' if value.dtr
|
|
417
|
-
f_attrs << %( r1="#{xml_escape(value.r1)}") if value.r1
|
|
418
|
-
f_attrs << %( r2="#{xml_escape(value.r2)}") if value.r2
|
|
408
|
+
xml.tag("c", { r: cell_ref || "", t: "e", s: style_idx, ph: ph_val }) do
|
|
409
|
+
xml.text_tag("v", value.code)
|
|
419
410
|
end
|
|
420
|
-
|
|
421
|
-
f_attrs
|
|
422
|
-
|
|
423
|
-
|
|
411
|
+
when Xlsxrb::Elements::Formula
|
|
412
|
+
f_attrs = case value.type
|
|
413
|
+
when :shared
|
|
414
|
+
{ t: "shared", si: value.shared_index || "", ref: value.ref }
|
|
415
|
+
when :array
|
|
416
|
+
value.ref ? { t: "array", ref: value.ref } : {}
|
|
417
|
+
when :data_table
|
|
418
|
+
{
|
|
419
|
+
t: "dataTable",
|
|
420
|
+
dt2D: value.dt2d ? 1 : nil,
|
|
421
|
+
dtr: value.dtr ? 1 : nil,
|
|
422
|
+
r1: value.r1,
|
|
423
|
+
r2: value.r2
|
|
424
|
+
}
|
|
425
|
+
else
|
|
426
|
+
{}
|
|
427
|
+
end
|
|
428
|
+
f_attrs[:ca] = 1 if value.calculate_always?
|
|
429
|
+
f_attrs[:aca] = 1 if value.aca
|
|
430
|
+
f_attrs[:bx] = 1 if value.bx
|
|
431
|
+
t_val = nil
|
|
424
432
|
cached_val_str = value.cached_value.to_s
|
|
425
433
|
case value.cached_value
|
|
426
434
|
when String
|
|
427
|
-
|
|
435
|
+
t_val = "str"
|
|
428
436
|
when true
|
|
429
|
-
|
|
437
|
+
t_val = "b"
|
|
430
438
|
cached_val_str = "1"
|
|
431
439
|
when false
|
|
432
|
-
|
|
440
|
+
t_val = "b"
|
|
433
441
|
cached_val_str = "0"
|
|
434
442
|
end
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
parts
|
|
443
|
+
xml.tag("c", { r: cell_ref || "", t: t_val, s: style_idx, ph: ph_val }) do
|
|
444
|
+
if value.expression && !value.expression.empty?
|
|
445
|
+
xml.text_tag("f", value.expression, f_attrs)
|
|
446
|
+
else
|
|
447
|
+
xml.empty_tag("f", f_attrs)
|
|
448
|
+
end
|
|
449
|
+
xml.tag("v") { xml.xstring_text(cached_val_str) } unless value.cached_value.nil?
|
|
450
|
+
end
|
|
444
451
|
when Xlsxrb::Elements::RichText
|
|
445
452
|
if sst
|
|
446
453
|
rt_sst, = sst
|
|
447
|
-
|
|
448
|
-
|
|
454
|
+
xml.tag("c", { r: cell_ref || "", t: "s", s: style_idx, ph: ph_val }) do
|
|
455
|
+
xml.text_tag("v", rt_sst[value])
|
|
456
|
+
end
|
|
449
457
|
else
|
|
450
|
-
|
|
458
|
+
xml.tag("c", { r: cell_ref || "", t: "inlineStr", s: style_idx, ph: ph_val }) do
|
|
459
|
+
xml.tag("is") { write_rich_text_xml(xml, value) }
|
|
460
|
+
end
|
|
451
461
|
end
|
|
452
462
|
when true, false
|
|
453
|
-
|
|
463
|
+
xml.tag("c", { r: cell_ref || "", t: "b", s: style_idx, ph: ph_val }) do
|
|
464
|
+
xml.text_tag("v", value ? 1 : 0)
|
|
465
|
+
end
|
|
454
466
|
when Time
|
|
455
467
|
date1904 = @workbook_properties&.[](:date1904) ? true : false
|
|
456
468
|
serial = Xlsxrb::Ooxml::Utils.datetime_to_serial(value, date1904: date1904)
|
|
457
|
-
|
|
458
|
-
|
|
469
|
+
s_val = style_idx || resolve_style_index(datetime_num_fmt_id)
|
|
470
|
+
xml.tag("c", { r: cell_ref || "", s: s_val, ph: ph_val }) { xml.text_tag("v", serial) }
|
|
459
471
|
when Date
|
|
460
472
|
date1904 = @workbook_properties&.[](:date1904) ? true : false
|
|
461
473
|
serial = Xlsxrb::Ooxml::Utils.date_to_serial(value, date1904: date1904)
|
|
462
|
-
|
|
463
|
-
|
|
474
|
+
s_val = style_idx || resolve_style_index(date_num_fmt_id)
|
|
475
|
+
xml.tag("c", { r: cell_ref || "", s: s_val, ph: ph_val }) { xml.text_tag("v", serial) }
|
|
464
476
|
when Numeric
|
|
465
|
-
|
|
477
|
+
xml.tag("c", { r: cell_ref || "", s: style_idx, ph: ph_val }) { xml.text_tag("v", value) }
|
|
466
478
|
else
|
|
467
479
|
if sst
|
|
468
480
|
_, str_sst = sst
|
|
469
|
-
|
|
470
|
-
|
|
481
|
+
xml.tag("c", { r: cell_ref || "", t: "s", s: style_idx, ph: ph_val }) do
|
|
482
|
+
xml.text_tag("v", str_sst[value.to_s])
|
|
483
|
+
end
|
|
471
484
|
else
|
|
472
|
-
|
|
485
|
+
xml.tag("c", { r: cell_ref || "", t: "inlineStr", s: style_idx, ph: ph_val }) do
|
|
486
|
+
xml.tag("is") { xml.tag("t") { xml.xstring_text(value) } }
|
|
487
|
+
end
|
|
473
488
|
end
|
|
474
489
|
end
|
|
475
490
|
end
|
|
@@ -512,71 +527,76 @@ module Xlsxrb
|
|
|
512
527
|
@xf_index_map[num_fmt_id]
|
|
513
528
|
end
|
|
514
529
|
|
|
515
|
-
# : (untyped filter) ->
|
|
516
|
-
def
|
|
530
|
+
# : (XmlBuilder xml, untyped filter) -> void
|
|
531
|
+
def write_filter_xml(xml, filter)
|
|
517
532
|
case filter[:type]
|
|
518
533
|
when :filters
|
|
519
|
-
attrs =
|
|
520
|
-
|
|
534
|
+
attrs = {
|
|
535
|
+
blank: filter[:blank] ? 1 : nil,
|
|
536
|
+
calendarType: filter[:calendar_type]
|
|
537
|
+
}
|
|
521
538
|
has_values = filter[:values]&.any?
|
|
522
539
|
has_date_groups = filter[:date_group_items]&.any?
|
|
523
540
|
if has_values || has_date_groups
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
541
|
+
xml.tag("filters", attrs) do
|
|
542
|
+
filter[:values]&.each { |v| xml.empty_tag("filter", { val: v || "" }) }
|
|
543
|
+
filter[:date_group_items]&.each do |dg|
|
|
544
|
+
xml.empty_tag("dateGroupItem", {
|
|
545
|
+
dateTimeGrouping: dg[:date_time_grouping] || "",
|
|
546
|
+
year: dg[:year],
|
|
547
|
+
month: dg[:month],
|
|
548
|
+
day: dg[:day],
|
|
549
|
+
hour: dg[:hour],
|
|
550
|
+
minute: dg[:minute],
|
|
551
|
+
second: dg[:second]
|
|
552
|
+
})
|
|
553
|
+
end
|
|
535
554
|
end
|
|
536
|
-
parts << "</filters>"
|
|
537
|
-
parts.join
|
|
538
555
|
else
|
|
539
|
-
"
|
|
556
|
+
xml.empty_tag("filters", attrs)
|
|
540
557
|
end
|
|
541
558
|
when :custom
|
|
542
559
|
if filter[:filters]
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
560
|
+
xml.tag("customFilters", { and: filter[:and] ? 1 : nil }) do
|
|
561
|
+
filter[:filters].each do |cf|
|
|
562
|
+
xml.empty_tag("customFilter", { operator: cf[:operator] || "", val: cf[:val] || "" })
|
|
563
|
+
end
|
|
547
564
|
end
|
|
548
|
-
parts << "</customFilters>"
|
|
549
|
-
parts.join
|
|
550
565
|
else
|
|
551
|
-
|
|
566
|
+
xml.tag("customFilters") do
|
|
567
|
+
xml.empty_tag("customFilter", { operator: filter[:operator] || "", val: filter[:val] || "" })
|
|
568
|
+
end
|
|
552
569
|
end
|
|
553
570
|
when :dynamic
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
571
|
+
xml.empty_tag("dynamicFilter", {
|
|
572
|
+
type: filter[:dynamic_type] || "",
|
|
573
|
+
val: filter[:val],
|
|
574
|
+
valIso: filter[:val_iso],
|
|
575
|
+
maxVal: filter[:max_val],
|
|
576
|
+
maxValIso: filter[:max_val_iso]
|
|
577
|
+
})
|
|
560
578
|
when :top10
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
579
|
+
xml.empty_tag("top10", {
|
|
580
|
+
top: filter[:top] ? 1 : nil,
|
|
581
|
+
percent: filter[:percent] ? 1 : nil,
|
|
582
|
+
val: filter[:val] || "",
|
|
583
|
+
filterVal: filter[:filter_val]
|
|
584
|
+
})
|
|
565
585
|
when :color_filter
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
586
|
+
xml.empty_tag("colorFilter", {
|
|
587
|
+
dxfId: filter[:dxf_id] || "",
|
|
588
|
+
cellColor: filter[:cell_color] == false ? 0 : nil
|
|
589
|
+
})
|
|
569
590
|
when :icon_filter
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
""
|
|
591
|
+
xml.empty_tag("iconFilter", {
|
|
592
|
+
iconSet: filter[:icon_set] || "",
|
|
593
|
+
iconId: filter[:icon_id]
|
|
594
|
+
})
|
|
575
595
|
end
|
|
576
596
|
end
|
|
577
597
|
|
|
578
|
-
# : (
|
|
579
|
-
def
|
|
598
|
+
# : (XmlBuilder xml, untyped rule) -> void
|
|
599
|
+
def write_cf_rule(xml, rule)
|
|
580
600
|
type = rule[:type]
|
|
581
601
|
if type.is_a?(String) || type.is_a?(Symbol)
|
|
582
602
|
t_str = type.to_s
|
|
@@ -586,24 +606,26 @@ module Xlsxrb
|
|
|
586
606
|
type = snake if CF_TYPE_MAP.key?(snake)
|
|
587
607
|
end
|
|
588
608
|
rule_type = CF_TYPE_MAP[type] || type.to_s
|
|
589
|
-
rule_attrs = %(type="#{xml_escape(rule_type)}")
|
|
590
|
-
rule_attrs << %( priority="#{xml_escape(rule[:priority])}") if rule[:priority]
|
|
591
|
-
rule_attrs << %( operator="#{xml_escape(rule[:operator])}") if rule[:operator]
|
|
592
609
|
did = rule[:dxf_id] || rule[:format_id]
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
rule_attrs
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
610
|
+
tp_str = if rule[:time_period]
|
|
611
|
+
tp = rule[:time_period]
|
|
612
|
+
DslHelpers::CF_TIME_PERIODS[tp.to_sym] || tp.to_s
|
|
613
|
+
end
|
|
614
|
+
rule_attrs = {
|
|
615
|
+
type: rule_type,
|
|
616
|
+
priority: rule[:priority],
|
|
617
|
+
operator: rule[:operator],
|
|
618
|
+
dxfId: did,
|
|
619
|
+
stopIfTrue: rule[:stop_if_true] ? 1 : nil,
|
|
620
|
+
aboveAverage: rule[:above_average] == false ? 0 : nil,
|
|
621
|
+
equalAverage: rule[:equal_average] ? 1 : nil,
|
|
622
|
+
rank: rule[:rank],
|
|
623
|
+
percent: rule[:percent] ? 1 : nil,
|
|
624
|
+
bottom: rule[:bottom] ? 1 : nil,
|
|
625
|
+
text: rule[:text],
|
|
626
|
+
timePeriod: tp_str,
|
|
627
|
+
stdDev: rule[:std_dev]
|
|
628
|
+
}
|
|
607
629
|
|
|
608
630
|
case type
|
|
609
631
|
when :cell_is, :expression, :above_average, :top10, :duplicate_values, :unique_values,
|
|
@@ -611,71 +633,74 @@ module Xlsxrb
|
|
|
611
633
|
:contains_blanks, :not_contains_blanks, :contains_errors, :not_contains_errors, :time_period
|
|
612
634
|
formulas = rule[:formulas] || [rule[:formula]].compact
|
|
613
635
|
if formulas.empty?
|
|
614
|
-
|
|
636
|
+
xml.empty_tag("cfRule", rule_attrs)
|
|
615
637
|
else
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
638
|
+
xml.tag("cfRule", rule_attrs) do
|
|
639
|
+
formulas.each { |f| xml.text_tag("formula", f) }
|
|
640
|
+
end
|
|
619
641
|
end
|
|
620
642
|
when :color_scale
|
|
621
643
|
cs = rule[:color_scale]
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
644
|
+
xml.tag("cfRule", rule_attrs) do
|
|
645
|
+
xml.tag("colorScale") do
|
|
646
|
+
cs[:cfvo]&.each do |cfvo|
|
|
647
|
+
xml.empty_tag("cfvo", {
|
|
648
|
+
type: cfvo[:type] || "",
|
|
649
|
+
val: cfvo[:val],
|
|
650
|
+
gte: cfvo[:gte] == false ? 0 : nil
|
|
651
|
+
})
|
|
652
|
+
end
|
|
653
|
+
cs[:colors]&.each { |c| write_cf_color_xml(xml, c) }
|
|
654
|
+
end
|
|
629
655
|
end
|
|
630
|
-
cs[:colors]&.each { |c| parts << emit_cf_color_xml(c) }
|
|
631
|
-
parts << "</colorScale>"
|
|
632
|
-
parts << "</cfRule>"
|
|
633
656
|
when :data_bar
|
|
634
657
|
db = rule[:data_bar]
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
658
|
+
xml.tag("cfRule", rule_attrs) do
|
|
659
|
+
xml.tag("dataBar", {
|
|
660
|
+
minLength: db[:min_length],
|
|
661
|
+
maxLength: db[:max_length],
|
|
662
|
+
showValue: xml_bool_attr(db[:show_value])
|
|
663
|
+
}) do
|
|
664
|
+
db[:cfvo]&.each do |cfvo|
|
|
665
|
+
xml.empty_tag("cfvo", {
|
|
666
|
+
type: cfvo[:type] || "",
|
|
667
|
+
val: cfvo[:val],
|
|
668
|
+
gte: cfvo[:gte] == false ? 0 : nil
|
|
669
|
+
})
|
|
670
|
+
end
|
|
671
|
+
write_cf_color_xml(xml, db[:color]) if db[:color]
|
|
672
|
+
end
|
|
646
673
|
end
|
|
647
|
-
parts << emit_cf_color_xml(db[:color]) if db[:color]
|
|
648
|
-
parts << "</dataBar>"
|
|
649
|
-
parts << "</cfRule>"
|
|
650
674
|
when :icon_set
|
|
651
675
|
is = rule[:icon_set]
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
676
|
+
xml.tag("cfRule", rule_attrs) do
|
|
677
|
+
xml.tag("iconSet", {
|
|
678
|
+
iconSet: is[:icon_set],
|
|
679
|
+
reverse: xml_bool_attr(is[:reverse]),
|
|
680
|
+
percent: xml_bool_attr(is[:percent]),
|
|
681
|
+
showValue: xml_bool_attr(is[:show_value])
|
|
682
|
+
}) do
|
|
683
|
+
is[:cfvo]&.each do |cfvo|
|
|
684
|
+
xml.empty_tag("cfvo", {
|
|
685
|
+
type: cfvo[:type] || "",
|
|
686
|
+
val: cfvo[:val],
|
|
687
|
+
gte: cfvo[:gte] == false ? 0 : nil
|
|
688
|
+
})
|
|
689
|
+
end
|
|
690
|
+
end
|
|
664
691
|
end
|
|
665
|
-
parts << "</iconSet>"
|
|
666
|
-
parts << "</cfRule>"
|
|
667
692
|
else
|
|
668
|
-
|
|
693
|
+
xml.empty_tag("cfRule", rule_attrs)
|
|
669
694
|
end
|
|
670
695
|
end
|
|
671
696
|
|
|
672
697
|
# Emits a <color> element for CF rules, accepting either a plain RGB string or a hash.
|
|
673
|
-
# : (untyped color) ->
|
|
674
|
-
def
|
|
698
|
+
# : (XmlBuilder xml, untyped color) -> void
|
|
699
|
+
def write_cf_color_xml(xml, color)
|
|
675
700
|
if color.is_a?(Hash)
|
|
676
|
-
|
|
701
|
+
write_color_xml(xml, color)
|
|
677
702
|
else
|
|
678
|
-
|
|
703
|
+
xml.empty_tag("color", { rgb: color || "" })
|
|
679
704
|
end
|
|
680
705
|
end
|
|
681
706
|
|
|
@@ -714,63 +739,60 @@ module Xlsxrb
|
|
|
714
739
|
|
|
715
740
|
# : () -> untyped
|
|
716
741
|
def generate_core_properties_xml
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
742
|
+
XmlBuilder.build(declaration: :plain) do |xml|
|
|
743
|
+
xml.tag("cp:coreProperties", {
|
|
744
|
+
"xmlns:cp": CP_NS,
|
|
745
|
+
"xmlns:dc": DC_NS,
|
|
746
|
+
"xmlns:dcterms": DCTERMS_NS,
|
|
747
|
+
"xmlns:xsi": XSI_NS
|
|
748
|
+
}) do
|
|
749
|
+
xml.text_tag("dc:title", @core_properties[:title]) if @core_properties[:title]
|
|
750
|
+
xml.text_tag("dc:subject", @core_properties[:subject]) if @core_properties[:subject]
|
|
751
|
+
xml.text_tag("dc:creator", @core_properties[:creator]) if @core_properties[:creator]
|
|
752
|
+
xml.text_tag("cp:keywords", @core_properties[:keywords]) if @core_properties[:keywords]
|
|
753
|
+
xml.text_tag("dc:description", @core_properties[:description]) if @core_properties[:description]
|
|
754
|
+
xml.text_tag("cp:lastModifiedBy", @core_properties[:last_modified_by]) if @core_properties[:last_modified_by]
|
|
755
|
+
xml.text_tag("cp:revision", @core_properties[:revision]) if @core_properties[:revision]
|
|
756
|
+
xml.text_tag("dcterms:created", @core_properties[:created], { "xsi:type": "dcterms:W3CDTF" }) if @core_properties[:created]
|
|
757
|
+
xml.text_tag("dcterms:modified", @core_properties[:modified], { "xsi:type": "dcterms:W3CDTF" }) if @core_properties[:modified]
|
|
758
|
+
xml.text_tag("cp:category", @core_properties[:category]) if @core_properties[:category]
|
|
759
|
+
xml.text_tag("cp:contentStatus", @core_properties[:content_status]) if @core_properties[:content_status]
|
|
760
|
+
xml.text_tag("dc:language", @core_properties[:language]) if @core_properties[:language]
|
|
761
|
+
end
|
|
762
|
+
end
|
|
735
763
|
end
|
|
736
764
|
|
|
737
765
|
# : () -> untyped
|
|
738
766
|
def generate_app_properties_xml
|
|
739
|
-
parts = [
|
|
740
|
-
XML_HEADER,
|
|
741
|
-
%(<Properties xmlns="#{APP_NS}" xmlns:vt="#{VT_NS}">)
|
|
742
|
-
]
|
|
743
767
|
app_val = @app_properties[:app_name] || @app_properties[:application]
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
768
|
+
XmlBuilder.build(declaration: :plain) do |xml|
|
|
769
|
+
xml.tag("Properties", { xmlns: APP_NS, "xmlns:vt": VT_NS }) do
|
|
770
|
+
xml.text_tag("Application", app_val) if app_val
|
|
771
|
+
xml.text_tag("AppVersion", @app_properties[:app_version]) if @app_properties[:app_version]
|
|
772
|
+
if @app_properties[:heading_pairs] && @app_properties[:titles_of_parts]
|
|
773
|
+
hp = @app_properties[:heading_pairs]
|
|
774
|
+
tp = @app_properties[:titles_of_parts]
|
|
775
|
+
xml.tag("HeadingPairs") do
|
|
776
|
+
xml.tag("vt:vector", { size: hp.size * 2, baseType: "variant" }) do
|
|
777
|
+
hp.each do |label, count|
|
|
778
|
+
xml.tag("vt:variant") { xml.text_tag("vt:lpstr", label) }
|
|
779
|
+
xml.tag("vt:variant") { xml.text_tag("vt:i4", count) }
|
|
780
|
+
end
|
|
781
|
+
end
|
|
782
|
+
end
|
|
783
|
+
xml.tag("TitlesOfParts") do
|
|
784
|
+
xml.tag("vt:vector", { size: tp.size, baseType: "lpstr" }) do
|
|
785
|
+
tp.each { |t| xml.text_tag("vt:lpstr", t) }
|
|
786
|
+
end
|
|
787
|
+
end
|
|
788
|
+
end
|
|
754
789
|
end
|
|
755
|
-
parts << "</vt:vector>"
|
|
756
|
-
parts << "</HeadingPairs>"
|
|
757
|
-
parts << "<TitlesOfParts>"
|
|
758
|
-
parts << %(<vt:vector size="#{tp.size}" baseType="lpstr">)
|
|
759
|
-
tp.each { |t| parts << "<vt:lpstr>#{xml_escape(t)}</vt:lpstr>" }
|
|
760
|
-
parts << "</vt:vector>"
|
|
761
|
-
parts << "</TitlesOfParts>"
|
|
762
790
|
end
|
|
763
|
-
parts << "</Properties>"
|
|
764
|
-
parts.join
|
|
765
791
|
end
|
|
766
792
|
|
|
767
793
|
# : () -> untyped
|
|
768
794
|
def generate_custom_properties_xml
|
|
769
795
|
custom_ns = "http://schemas.openxmlformats.org/officeDocument/2006/custom-properties"
|
|
770
|
-
parts = [
|
|
771
|
-
XML_HEADER,
|
|
772
|
-
%(<Properties xmlns="#{xml_escape(custom_ns)}" xmlns:vt="#{VT_NS}">)
|
|
773
|
-
]
|
|
774
796
|
list = if @custom_properties.is_a?(Hash)
|
|
775
797
|
@custom_properties.map do |name, val|
|
|
776
798
|
if val.is_a?(Elements::CustomProperty) || (val.respond_to?(:name) && val.respond_to?(:value))
|
|
@@ -790,26 +812,37 @@ module Xlsxrb
|
|
|
790
812
|
end
|
|
791
813
|
end
|
|
792
814
|
end
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
815
|
+
|
|
816
|
+
XmlBuilder.build(declaration: :plain) do |xml|
|
|
817
|
+
xml.tag("Properties", { xmlns: custom_ns, "xmlns:vt": VT_NS }) do
|
|
818
|
+
list.each_with_index do |prop, idx|
|
|
819
|
+
fmtid = "{D5CDD505-2E9C-101B-9397-08002B2CF9AE}"
|
|
820
|
+
xml.tag("property", { fmtid: fmtid, pid: idx + 2, name: prop[:name] || "" }) do
|
|
821
|
+
case prop[:type]
|
|
822
|
+
when :number, :int, :i4
|
|
823
|
+
xml.text_tag("vt:i4", prop[:value])
|
|
824
|
+
when :float, :r8
|
|
825
|
+
xml.text_tag("vt:r8", prop[:value])
|
|
826
|
+
when :bool, :boolean
|
|
827
|
+
xml.text_tag("vt:bool", prop[:value] ? "true" : "false")
|
|
828
|
+
when :date, :filetime
|
|
829
|
+
xml.text_tag("vt:filetime", prop[:value])
|
|
830
|
+
else
|
|
831
|
+
xml.text_tag("vt:lpwstr", prop[:value])
|
|
832
|
+
end
|
|
833
|
+
end
|
|
834
|
+
end
|
|
835
|
+
end
|
|
810
836
|
end
|
|
811
|
-
|
|
812
|
-
|
|
837
|
+
end
|
|
838
|
+
|
|
839
|
+
private
|
|
840
|
+
|
|
841
|
+
# : (untyped val) -> (nil | ::Integer)
|
|
842
|
+
def xml_bool_attr(val)
|
|
843
|
+
return nil if val.nil?
|
|
844
|
+
|
|
845
|
+
val ? 1 : 0
|
|
813
846
|
end
|
|
814
847
|
end
|
|
815
848
|
end
|