write_xlsx 1.10.2 → 1.11.1
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/.rubocop.yml +10 -1
- data/Changes +18 -0
- data/examples/autofit.rb +37 -0
- data/examples/chart_radar.rb +3 -9
- data/lib/write_xlsx/chart/area.rb +1 -0
- data/lib/write_xlsx/chart/axis.rb +1 -0
- data/lib/write_xlsx/chart/bar.rb +1 -0
- data/lib/write_xlsx/chart/caption.rb +1 -0
- data/lib/write_xlsx/chart/column.rb +1 -0
- data/lib/write_xlsx/chart/doughnut.rb +1 -0
- data/lib/write_xlsx/chart/legend.rb +1 -0
- data/lib/write_xlsx/chart/line.rb +1 -0
- data/lib/write_xlsx/chart/pie.rb +1 -0
- data/lib/write_xlsx/chart/radar.rb +1 -0
- data/lib/write_xlsx/chart/scatter.rb +1 -0
- data/lib/write_xlsx/chart/series.rb +8 -4
- data/lib/write_xlsx/chart/stock.rb +1 -0
- data/lib/write_xlsx/chart.rb +45 -14
- data/lib/write_xlsx/colors.rb +20 -19
- data/lib/write_xlsx/format.rb +13 -9
- data/lib/write_xlsx/package/comments.rb +2 -1
- data/lib/write_xlsx/package/conditional_format.rb +4 -4
- data/lib/write_xlsx/package/shared_strings.rb +5 -3
- data/lib/write_xlsx/package/styles.rb +27 -30
- data/lib/write_xlsx/package/table.rb +9 -0
- data/lib/write_xlsx/utility.rb +40 -7
- data/lib/write_xlsx/version.rb +1 -1
- data/lib/write_xlsx/workbook.rb +20 -11
- data/lib/write_xlsx/worksheet/cell_data.rb +11 -4
- data/lib/write_xlsx/worksheet.rb +264 -81
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cabafeb058f3742956ec06251cab5ecf67d9b76cd5db3ec659e2e4184d2c1483
|
4
|
+
data.tar.gz: 95a68e0390bff44e03dc8577b31162c1d1c2cb80d77f3943947e1114327afb01
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 70a98e3ffc2be69574805f72a63678b2023cc3aef9a1c1a97c5f8a13de80de29c641c573d8c8c9bd7d33da088827a15fb6feb3b4c7591b50ffb26cb321591b49
|
7
|
+
data.tar.gz: 1d387aa195a7a35f0b664e4ff155ca71de765ad6ae886df66debc9063d1fea8c4c905ab10a7aef735d69813b79faa1d6e7ded96e70ce23a75df56e5f172b1648
|
data/.rubocop.yml
CHANGED
@@ -8,6 +8,9 @@ AllCops:
|
|
8
8
|
TargetRubyVersion: 2.6
|
9
9
|
NewCops: enable
|
10
10
|
|
11
|
+
Gemspec/DevelopmentDependencies:
|
12
|
+
Enabled: false
|
13
|
+
|
11
14
|
Gemspec/RequiredRubyVersion:
|
12
15
|
Enabled: false
|
13
16
|
|
@@ -33,6 +36,9 @@ Layout/HeredocIndentation:
|
|
33
36
|
Layout/LineLength:
|
34
37
|
Max: 7000
|
35
38
|
|
39
|
+
Layout/MultilineMethodCallIndentation:
|
40
|
+
Enabled: false
|
41
|
+
|
36
42
|
Lint/DuplicateBranch:
|
37
43
|
IgnoreLiteralBranches: true
|
38
44
|
Exclude:
|
@@ -60,6 +66,9 @@ Metrics/CyclomaticComplexity:
|
|
60
66
|
Metrics/MethodLength:
|
61
67
|
Max: 400
|
62
68
|
|
69
|
+
Metrics/ModuleLength:
|
70
|
+
Max: 1000
|
71
|
+
|
63
72
|
Metrics/ParameterLists:
|
64
73
|
Max: 12
|
65
74
|
MaxOptionalParameters: 6
|
@@ -93,7 +102,7 @@ Style/FormatStringToken:
|
|
93
102
|
EnforcedStyle: unannotated
|
94
103
|
|
95
104
|
Style/HashSyntax:
|
96
|
-
|
105
|
+
EnforcedStyle: ruby19_no_mixed_keys
|
97
106
|
EnforcedShorthandSyntax: either
|
98
107
|
|
99
108
|
Style/IfUnlessModifier:
|
data/Changes
CHANGED
@@ -1,5 +1,23 @@
|
|
1
1
|
Change history of write_xlsx rubygem.
|
2
2
|
|
3
|
+
2023-08-09 v1.11.1
|
4
|
+
Fixed issue #110. Redefining costant Struct::ColInfo
|
5
|
+
|
6
|
+
2023-05-06 v1.11.0
|
7
|
+
Added support for simulated worksheet `autofit()`.
|
8
|
+
|
9
|
+
Refactored internal column property handling to allow column ranges
|
10
|
+
to be overridden (a common UX expectation).
|
11
|
+
|
12
|
+
Add `quote_prefix` format property.
|
13
|
+
|
14
|
+
Fix for duplicate number formats. Issue #283(excel-write-xlsx)
|
15
|
+
|
16
|
+
Add fix for worksheets with tables and background images.
|
17
|
+
|
18
|
+
Replace/fix the worksheet protection password algorithm
|
19
|
+
so that is works correctly for strings over 24 chars.
|
20
|
+
|
3
21
|
2023-02-16 v1.10.2
|
4
22
|
Fixed issue #104. Worksheet#write Ruby 3.2 removed Object#=~
|
5
23
|
making it impossible to write Date objects
|
data/examples/autofit.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
|
4
|
+
#
|
5
|
+
# An example of using simulated autofit to automatically adjust the width of
|
6
|
+
# worksheet columns based on the data in the cells.
|
7
|
+
#
|
8
|
+
# Copyright 2000-2023, John McNamara, jmcnamara@cpan.org
|
9
|
+
#
|
10
|
+
# SPDX-License-Identifier: Artistic-1.0-Perl OR GPL-1.0-or-later
|
11
|
+
#
|
12
|
+
# convert to Ruby by Hideo NAKAMURA, nakamura.hideo@gmail.com
|
13
|
+
#
|
14
|
+
require 'write_xlsx'
|
15
|
+
|
16
|
+
workbook = WriteXLSX.new('autofit.xlsx')
|
17
|
+
worksheet = workbook.add_worksheet
|
18
|
+
|
19
|
+
# Write some worksheet data to demonstrate autofitting.
|
20
|
+
worksheet.write(0, 0, "Foo")
|
21
|
+
worksheet.write(1, 0, "Food")
|
22
|
+
worksheet.write(2, 0, "Foody")
|
23
|
+
worksheet.write(3, 0, "Froody")
|
24
|
+
|
25
|
+
worksheet.write(0, 1, 12345)
|
26
|
+
worksheet.write(1, 1, 12345678)
|
27
|
+
worksheet.write(2, 1, 12345)
|
28
|
+
|
29
|
+
worksheet.write(0, 2, "Some longer text")
|
30
|
+
|
31
|
+
worksheet.write(0, 3, 'http://www.google.com')
|
32
|
+
worksheet.write(1, 3, 'https://github.com')
|
33
|
+
|
34
|
+
# Autofit the worksheet
|
35
|
+
worksheet.autofit
|
36
|
+
|
37
|
+
workbook.close
|
data/examples/chart_radar.rb
CHANGED
@@ -44,10 +44,8 @@ chart1.add_series(
|
|
44
44
|
values: ['Sheet1', 1, 6, 2, 2]
|
45
45
|
)
|
46
46
|
|
47
|
-
# Add a chart title
|
47
|
+
# Add a chart title.
|
48
48
|
chart1.set_title(name: 'Results of sample analysis')
|
49
|
-
chart1.set_x_axis(name: 'Test number')
|
50
|
-
chart1.set_y_axis(name: 'Sample length (mm)')
|
51
49
|
|
52
50
|
# Set an Excel chart style. Blue colors with white outline and shadow.
|
53
51
|
chart1.set_style(11)
|
@@ -81,10 +79,8 @@ chart2.add_series(
|
|
81
79
|
values: ['Sheet1', 1, 6, 2, 2]
|
82
80
|
)
|
83
81
|
|
84
|
-
# Add a chart title
|
82
|
+
# Add a chart title.
|
85
83
|
chart2.set_title(name: 'Stacked Chart')
|
86
|
-
chart2.set_x_axis(name: 'Test number')
|
87
|
-
chart2.set_y_axis(name: 'Sample length (mm)')
|
88
84
|
|
89
85
|
# Set an Excel chart style. Blue colors with white outline and shadow.
|
90
86
|
chart2.set_style(12)
|
@@ -118,10 +114,8 @@ chart3.add_series(
|
|
118
114
|
values: ['Sheet1', 1, 6, 2, 2]
|
119
115
|
)
|
120
116
|
|
121
|
-
# Add a chart title
|
117
|
+
# Add a chart title.
|
122
118
|
chart3.set_title(name: 'Percent Stacked Chart')
|
123
|
-
chart3.set_x_axis(name: 'Test number')
|
124
|
-
chart3.set_y_axis(name: 'Sample length (mm)')
|
125
119
|
|
126
120
|
# Set an Excel chart style. Blue colors with white outline and shadow.
|
127
121
|
chart3.set_style(13)
|
data/lib/write_xlsx/chart/bar.rb
CHANGED
data/lib/write_xlsx/chart/pie.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
module Writexlsx
|
4
5
|
class Chart
|
@@ -182,6 +183,7 @@ module Writexlsx
|
|
182
183
|
attr_reader :values, :categories, :name, :name_formula, :name_id
|
183
184
|
attr_reader :cat_data_id, :val_data_id, :fill, :pattern, :gradient
|
184
185
|
attr_reader :trendline, :smooth, :labels, :invert_if_negative
|
186
|
+
attr_reader :inverted_color
|
185
187
|
attr_reader :x2_axis, :y2_axis, :error_bars, :points
|
186
188
|
attr_accessor :line, :marker
|
187
189
|
|
@@ -217,10 +219,12 @@ module Writexlsx
|
|
217
219
|
|
218
220
|
@label_positions = chart.label_positions
|
219
221
|
@label_position_default = chart.label_position_default
|
220
|
-
@labels
|
222
|
+
@labels = labels_properties(params[:data_labels])
|
223
|
+
@inverted_color = params[:invert_if_negative_color]
|
221
224
|
|
222
|
-
%i[
|
223
|
-
|
225
|
+
%i[
|
226
|
+
smooth invert_if_negative x2_axis y2_axis
|
227
|
+
].each { |key| instance_variable_set("@#{key}", params[key]) }
|
224
228
|
end
|
225
229
|
|
226
230
|
def ==(other)
|
@@ -228,7 +232,7 @@ module Writexlsx
|
|
228
232
|
categories values name name_formula name_id
|
229
233
|
cat_data_id val_data_id
|
230
234
|
line fill gradient marker trendline
|
231
|
-
smooth labels
|
235
|
+
smooth labels inverted_color
|
232
236
|
x2_axis y2_axis error_bars points
|
233
237
|
]
|
234
238
|
methods.each do |method|
|
data/lib/write_xlsx/chart.rb
CHANGED
@@ -371,7 +371,7 @@ module Writexlsx
|
|
371
371
|
# Set on of the 42 built-in Excel chart styles. The default style is 2.
|
372
372
|
#
|
373
373
|
def set_style(style_id = 2)
|
374
|
-
style_id = 2 if style_id <
|
374
|
+
style_id = 2 if style_id < 1 || style_id > 48
|
375
375
|
@style_id = style_id
|
376
376
|
end
|
377
377
|
|
@@ -950,10 +950,36 @@ module Writexlsx
|
|
950
950
|
write_val(series)
|
951
951
|
# Write the c:smooth element.
|
952
952
|
write_c_smooth(series.smooth) if ptrue?(@smooth_allowed)
|
953
|
+
write_ext_lst(series.inverted_color) if series.inverted_color
|
953
954
|
end
|
954
955
|
@series_index += 1
|
955
956
|
end
|
956
957
|
|
958
|
+
def write_ext_lst(color)
|
959
|
+
uri = '{6F2FDCE9-48DA-4B69-8628-5D25D57E5C99}'
|
960
|
+
xmlns_c_14 =
|
961
|
+
'http://schemas.microsoft.com/office/drawing/2007/8/2/chart'
|
962
|
+
|
963
|
+
attributes_1 = [
|
964
|
+
['uri', uri],
|
965
|
+
['xmlns:c14', xmlns_c_14]
|
966
|
+
]
|
967
|
+
|
968
|
+
attributes_2 = [
|
969
|
+
['xmlns:c14', xmlns_c_14]
|
970
|
+
]
|
971
|
+
|
972
|
+
@writer.tag_elements('c:extLst') do
|
973
|
+
@writer.tag_elements('c:ext', attributes_1) do
|
974
|
+
@writer.tag_elements('c14:invertSolidFillFmt') do
|
975
|
+
@writer.tag_elements('c14:spPr', attributes_2) do
|
976
|
+
write_a_solid_fill(color: color)
|
977
|
+
end
|
978
|
+
end
|
979
|
+
end
|
980
|
+
end
|
981
|
+
end
|
982
|
+
|
957
983
|
def write_ser_base(series)
|
958
984
|
# Write the c:idx element.
|
959
985
|
write_idx(@series_index)
|
@@ -2018,20 +2044,25 @@ module Writexlsx
|
|
2018
2044
|
attributes << ['w', width]
|
2019
2045
|
end
|
2020
2046
|
|
2021
|
-
|
2022
|
-
|
2023
|
-
|
2024
|
-
|
2025
|
-
|
2026
|
-
|
2027
|
-
|
2028
|
-
|
2029
|
-
|
2030
|
-
|
2031
|
-
|
2032
|
-
# Write the
|
2033
|
-
|
2047
|
+
if ptrue?(line[:none]) || ptrue?(line[:color]) || line[:dash_type]
|
2048
|
+
@writer.tag_elements('a:ln', attributes) do
|
2049
|
+
# Write the line fill.
|
2050
|
+
if ptrue?(line[:none])
|
2051
|
+
# Write the a:noFill element.
|
2052
|
+
write_a_no_fill
|
2053
|
+
elsif ptrue?(line[:color])
|
2054
|
+
# Write the a:solidFill element.
|
2055
|
+
write_a_solid_fill(line)
|
2056
|
+
end
|
2057
|
+
|
2058
|
+
# Write the line/dash type.
|
2059
|
+
if line[:dash_type]
|
2060
|
+
# Write the a:prstDash element.
|
2061
|
+
write_a_prst_dash(line[:dash_type])
|
2062
|
+
end
|
2034
2063
|
end
|
2064
|
+
else
|
2065
|
+
@writer.empty_tag('a:ln', attributes)
|
2035
2066
|
end
|
2036
2067
|
end
|
2037
2068
|
|
data/lib/write_xlsx/colors.rb
CHANGED
@@ -4,25 +4,26 @@
|
|
4
4
|
module Writexlsx
|
5
5
|
class Colors
|
6
6
|
COLORS = {
|
7
|
-
aqua:
|
8
|
-
cyan:
|
9
|
-
black:
|
10
|
-
blue:
|
11
|
-
brown:
|
12
|
-
magenta:
|
13
|
-
fuchsia:
|
14
|
-
gray:
|
15
|
-
grey:
|
16
|
-
green:
|
17
|
-
lime:
|
18
|
-
navy:
|
19
|
-
orange:
|
20
|
-
pink:
|
21
|
-
purple:
|
22
|
-
red:
|
23
|
-
silver:
|
24
|
-
white:
|
25
|
-
yellow:
|
7
|
+
aqua: 0x0F,
|
8
|
+
cyan: 0x0F,
|
9
|
+
black: 0x08,
|
10
|
+
blue: 0x0C,
|
11
|
+
brown: 0x10,
|
12
|
+
magenta: 0x0E,
|
13
|
+
fuchsia: 0x0E,
|
14
|
+
gray: 0x17,
|
15
|
+
grey: 0x17,
|
16
|
+
green: 0x11,
|
17
|
+
lime: 0x0B,
|
18
|
+
navy: 0x12,
|
19
|
+
orange: 0x35,
|
20
|
+
pink: 0x21,
|
21
|
+
purple: 0x14,
|
22
|
+
red: 0x0A,
|
23
|
+
silver: 0x16,
|
24
|
+
white: 0x09,
|
25
|
+
yellow: 0x0D,
|
26
|
+
automatic: 0x40
|
26
27
|
} # :nodoc:
|
27
28
|
|
28
29
|
###############################################################################
|
data/lib/write_xlsx/format.rb
CHANGED
@@ -12,7 +12,7 @@ module Writexlsx
|
|
12
12
|
attr_reader :diag_type, :diag_color, :font_only, :color_indexed # :nodoc:
|
13
13
|
attr_reader :left, :left_color, :right, :right_color, :top, :top_color, :bottom, :bottom_color # :nodoc:
|
14
14
|
attr_reader :font_scheme # :nodoc:
|
15
|
-
attr_accessor :num_format_index, :border_index, :font_index # :nodoc:
|
15
|
+
attr_accessor :quote_prefix, :num_format_index, :border_index, :font_index # :nodoc:
|
16
16
|
attr_accessor :fill_index, :font_condense, :font_extend, :diag_border # :nodoc:
|
17
17
|
attr_accessor :bg_color, :fg_color, :pattern # :nodoc:
|
18
18
|
|
@@ -84,6 +84,7 @@ module Writexlsx
|
|
84
84
|
@just_distrib = 0
|
85
85
|
@color_indexed = 0
|
86
86
|
@font_only = 0
|
87
|
+
@quote_prefix = 0
|
87
88
|
|
88
89
|
set_format_properties(params) unless params.empty?
|
89
90
|
end
|
@@ -213,7 +214,7 @@ module Writexlsx
|
|
213
214
|
# Returns a unique hash key for the Format object.
|
214
215
|
#
|
215
216
|
def get_format_key
|
216
|
-
[get_font_key, get_border_key, get_fill_key, get_alignment_key, @num_format, @locked, @hidden].join(':')
|
217
|
+
[get_font_key, get_border_key, get_fill_key, get_alignment_key, @num_format, @locked, @hidden, @quote_prefix].join(':')
|
217
218
|
end
|
218
219
|
|
219
220
|
#
|
@@ -583,14 +584,16 @@ module Writexlsx
|
|
583
584
|
if theme == -1
|
584
585
|
# Ignore for excel2003_style
|
585
586
|
elsif ptrue?(theme)
|
586
|
-
write_color(
|
587
|
+
write_color('theme', theme, writer)
|
587
588
|
elsif ptrue?(@color_indexed)
|
588
|
-
write_color(
|
589
|
+
write_color('indexed', @color_indexed, writer)
|
589
590
|
elsif ptrue?(@color)
|
590
591
|
color = worksheet.palette_color(@color)
|
591
|
-
|
592
|
+
if color != 'Automatic'
|
593
|
+
write_color('rgb', color, writer)
|
594
|
+
end
|
592
595
|
elsif !ptrue?(dxf_format)
|
593
|
-
write_color(
|
596
|
+
write_color('theme', 1, writer)
|
594
597
|
end
|
595
598
|
|
596
599
|
unless ptrue?(dxf_format)
|
@@ -606,12 +609,12 @@ module Writexlsx
|
|
606
609
|
writer.empty_tag('sz', [['val', size]])
|
607
610
|
|
608
611
|
if ptrue?(theme)
|
609
|
-
write_color(
|
612
|
+
write_color('theme', theme, writer)
|
610
613
|
elsif ptrue?(@color)
|
611
614
|
color = worksheet.palette_color(@color)
|
612
|
-
write_color(
|
615
|
+
write_color('rgb', color, writer)
|
613
616
|
else
|
614
|
-
write_color(
|
617
|
+
write_color('theme', 1, writer)
|
615
618
|
end
|
616
619
|
|
617
620
|
writer.empty_tag('rFont', [['val', @font]])
|
@@ -642,6 +645,7 @@ module Writexlsx
|
|
642
645
|
['borderId', border_index],
|
643
646
|
['xfId', xf_id]
|
644
647
|
]
|
648
|
+
attributes << ['quotePrefix', 1] if ptrue?(quote_prefix)
|
645
649
|
attributes << ['applyNumberFormat', 1] if num_format_index > 0
|
646
650
|
# Add applyFont attribute if XF format uses a font element.
|
647
651
|
attributes << ['applyFont', 1] if font_index > 0 && !ptrue?(@hyperlink)
|
@@ -57,7 +57,8 @@ module Writexlsx
|
|
57
57
|
# Minor modification to allow comparison testing. Change RGB colors
|
58
58
|
# from long format, ffcc00 to short format fc0 used by VML.
|
59
59
|
def rgb_color(rgb)
|
60
|
-
|
60
|
+
r, g, b = rgb
|
61
|
+
result = sprintf("%02x%02x%02x", r, g, b)
|
61
62
|
result = "#{::Regexp.last_match(1)}#{::Regexp.last_match(2)}#{::Regexp.last_match(3)}" if result =~ /^([0-9a-f])\1([0-9a-f])\2([0-9a-f])\3$/
|
62
63
|
result
|
63
64
|
end
|
@@ -818,9 +818,9 @@ module Writexlsx
|
|
818
818
|
write_cfvo(min_type, min_value)
|
819
819
|
write_cfvo(mid_type, mid_value) if mid_type
|
820
820
|
write_cfvo(max_type, max_value)
|
821
|
-
write_color(
|
822
|
-
write_color(
|
823
|
-
write_color(
|
821
|
+
write_color('rgb', min_color)
|
822
|
+
write_color('rgb', mid_color) if mid_color
|
823
|
+
write_color('rgb', max_color)
|
824
824
|
end
|
825
825
|
end
|
826
826
|
end
|
@@ -844,7 +844,7 @@ module Writexlsx
|
|
844
844
|
write_cfvo(min_type, min_value)
|
845
845
|
write_cfvo(max_type, max_value)
|
846
846
|
|
847
|
-
write_color(
|
847
|
+
write_color('rgb', bar_color)
|
848
848
|
end
|
849
849
|
end
|
850
850
|
|
@@ -11,11 +11,14 @@ module Writexlsx
|
|
11
11
|
|
12
12
|
PRESERVE_SPACE_ATTRIBUTES = ['xml:space', 'preserve'].freeze
|
13
13
|
|
14
|
+
attr_reader :strings
|
15
|
+
|
14
16
|
def initialize
|
15
17
|
@writer = Package::XMLWriterSimple.new
|
16
18
|
@strings = [] # string table
|
17
19
|
@strings_index = {} # string table index
|
18
20
|
@count = 0 # count
|
21
|
+
@str_unique = 0
|
19
22
|
end
|
20
23
|
|
21
24
|
def index(string, params = {})
|
@@ -25,10 +28,9 @@ module Writexlsx
|
|
25
28
|
|
26
29
|
def add(string)
|
27
30
|
unless @strings_index[string]
|
28
|
-
# Only first time the string will be append to list
|
29
|
-
# next time we only check and not #dup it
|
30
31
|
str = string.frozen? ? string : string.freeze
|
31
32
|
@strings << str
|
33
|
+
@str_unique += 1
|
32
34
|
@strings_index[str] = @strings.size - 1
|
33
35
|
end
|
34
36
|
@count += 1
|
@@ -128,7 +130,7 @@ module Writexlsx
|
|
128
130
|
end
|
129
131
|
|
130
132
|
def unique_count
|
131
|
-
@
|
133
|
+
@str_unique
|
132
134
|
end
|
133
135
|
end
|
134
136
|
end
|
@@ -14,7 +14,7 @@ module Writexlsx
|
|
14
14
|
@xf_formats = nil
|
15
15
|
@palette = []
|
16
16
|
@font_count = 0
|
17
|
-
@
|
17
|
+
@num_formats = []
|
18
18
|
@border_count = 0
|
19
19
|
@fill_count = 0
|
20
20
|
@custom_colors = []
|
@@ -38,18 +38,18 @@ module Writexlsx
|
|
38
38
|
# Pass in the Format objects and other properties used to set the styles.
|
39
39
|
#
|
40
40
|
def set_style_properties(
|
41
|
-
xf_formats, palette, font_count,
|
41
|
+
xf_formats, palette, font_count, num_formats, border_count,
|
42
42
|
fill_count, custom_colors, dxf_formats, has_comments
|
43
43
|
)
|
44
|
-
@xf_formats
|
45
|
-
@palette
|
46
|
-
@font_count
|
47
|
-
@
|
48
|
-
@border_count
|
49
|
-
@fill_count
|
50
|
-
@custom_colors
|
51
|
-
@dxf_formats
|
52
|
-
@has_comments
|
44
|
+
@xf_formats = xf_formats
|
45
|
+
@palette = palette
|
46
|
+
@font_count = font_count
|
47
|
+
@num_formats = num_formats
|
48
|
+
@border_count = border_count
|
49
|
+
@fill_count = fill_count
|
50
|
+
@custom_colors = custom_colors
|
51
|
+
@dxf_formats = dxf_formats
|
52
|
+
@has_comments = has_comments
|
53
53
|
end
|
54
54
|
|
55
55
|
#
|
@@ -59,6 +59,8 @@ module Writexlsx
|
|
59
59
|
def palette_color(index)
|
60
60
|
if index.to_s =~ /^#([0-9A-F]{6})$/i
|
61
61
|
"FF#{::Regexp.last_match(1).upcase}"
|
62
|
+
elsif index == 0x40
|
63
|
+
"Automatic"
|
62
64
|
else
|
63
65
|
"FF#{super(index)}"
|
64
66
|
end
|
@@ -77,7 +79,7 @@ module Writexlsx
|
|
77
79
|
# Write the <numFmts> element.
|
78
80
|
#
|
79
81
|
def write_num_fmts
|
80
|
-
count = @
|
82
|
+
count = @num_formats.size
|
81
83
|
|
82
84
|
return if count == 0
|
83
85
|
|
@@ -85,11 +87,10 @@ module Writexlsx
|
|
85
87
|
|
86
88
|
@writer.tag_elements('numFmts', attributes) do
|
87
89
|
# Write the numFmts elements.
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
write_num_fmt(format.num_format_index, format.num_format)
|
90
|
+
index = 164
|
91
|
+
@num_formats.each do |num_format|
|
92
|
+
write_num_fmt(index, num_format)
|
93
|
+
index += 1
|
93
94
|
end
|
94
95
|
end
|
95
96
|
end
|
@@ -187,15 +188,6 @@ module Writexlsx
|
|
187
188
|
end
|
188
189
|
end
|
189
190
|
|
190
|
-
#
|
191
|
-
# Write the <color> element.
|
192
|
-
#
|
193
|
-
def write_color(name, value)
|
194
|
-
attributes = [[name, value]]
|
195
|
-
|
196
|
-
@writer.empty_tag('color', attributes)
|
197
|
-
end
|
198
|
-
|
199
191
|
#
|
200
192
|
# Write the <fills> element.
|
201
193
|
#
|
@@ -285,10 +277,14 @@ module Writexlsx
|
|
285
277
|
def write_pattern_fill(format, dxf_format)
|
286
278
|
bg_color, fg_color = bg_and_fg_color(format, dxf_format)
|
287
279
|
|
288
|
-
|
280
|
+
if fg_color && fg_color != 0 && fg_color != 0x40 # 'Automatic'
|
281
|
+
@writer.empty_tag('fgColor', [['rgb', palette_color(fg_color)]])
|
282
|
+
end
|
289
283
|
|
290
284
|
if bg_color && bg_color != 0
|
291
|
-
|
285
|
+
if bg_color != 0x40 # 'Automatic'
|
286
|
+
@writer.empty_tag('bgColor', [['rgb', palette_color(bg_color)]])
|
287
|
+
end
|
292
288
|
elsif !dxf_format && format.pattern <= 1
|
293
289
|
@writer.empty_tag('bgColor', [['indexed', 64]])
|
294
290
|
end
|
@@ -391,10 +387,11 @@ module Writexlsx
|
|
391
387
|
attributes = [[:style, BORDER_STYLES[style]]]
|
392
388
|
|
393
389
|
@writer.tag_elements(type, attributes) do
|
394
|
-
if color
|
390
|
+
if [0, 0x40].include?(color) # 'Automatic'
|
395
391
|
@writer.empty_tag('color', [['auto', 1]])
|
396
|
-
|
392
|
+
elsif color != 0 && color != 0x40 # 'Automatic'
|
397
393
|
color = palette_color(color)
|
394
|
+
|
398
395
|
@writer.empty_tag('color', [['rgb', color]])
|
399
396
|
end
|
400
397
|
end
|