write_xlsx 1.11.0 → 1.11.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -1
  3. data/Changes +12 -0
  4. data/examples/shape_all.rb +1 -1
  5. data/lib/write_xlsx/chart/area.rb +1 -0
  6. data/lib/write_xlsx/chart/axis.rb +1 -0
  7. data/lib/write_xlsx/chart/bar.rb +1 -0
  8. data/lib/write_xlsx/chart/caption.rb +1 -0
  9. data/lib/write_xlsx/chart/column.rb +1 -0
  10. data/lib/write_xlsx/chart/doughnut.rb +1 -0
  11. data/lib/write_xlsx/chart/legend.rb +1 -0
  12. data/lib/write_xlsx/chart/line.rb +1 -0
  13. data/lib/write_xlsx/chart/pie.rb +15 -2
  14. data/lib/write_xlsx/chart/radar.rb +1 -0
  15. data/lib/write_xlsx/chart/scatter.rb +1 -0
  16. data/lib/write_xlsx/chart/series.rb +56 -4
  17. data/lib/write_xlsx/chart/stock.rb +1 -0
  18. data/lib/write_xlsx/chart.rb +107 -23
  19. data/lib/write_xlsx/chartsheet.rb +10 -1
  20. data/lib/write_xlsx/col_name.rb +7 -3
  21. data/lib/write_xlsx/colors.rb +20 -19
  22. data/lib/write_xlsx/format.rb +10 -8
  23. data/lib/write_xlsx/package/app.rb +9 -5
  24. data/lib/write_xlsx/package/comments.rb +2 -1
  25. data/lib/write_xlsx/package/conditional_format.rb +6 -6
  26. data/lib/write_xlsx/package/packager.rb +2 -3
  27. data/lib/write_xlsx/package/styles.rb +11 -13
  28. data/lib/write_xlsx/package/table.rb +74 -20
  29. data/lib/write_xlsx/package/xml_writer_simple.rb +32 -44
  30. data/lib/write_xlsx/sheets.rb +6 -2
  31. data/lib/write_xlsx/sparkline.rb +2 -2
  32. data/lib/write_xlsx/utility.rb +14 -12
  33. data/lib/write_xlsx/version.rb +1 -1
  34. data/lib/write_xlsx/workbook.rb +2 -3
  35. data/lib/write_xlsx/worksheet/cell_data.rb +17 -18
  36. data/lib/write_xlsx/worksheet/hyperlink.rb +2 -2
  37. data/lib/write_xlsx/worksheet.rb +90 -39
  38. data/write_xlsx.gemspec +2 -0
  39. metadata +31 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 14a7593970ecc4db14f2accbdc1634033ac9042cdd7680a20d4400ea1eda741f
4
- data.tar.gz: 2ec671ba25dc571f612dc5b9d4a9c4ede2e147203d2e085313ea8b4a5f774377
3
+ metadata.gz: 9dae4b31e210af6cea2f7df87d92e29d48e8b36d7408cfc0c542b4aa0fe4ea22
4
+ data.tar.gz: 3c1be9afcd157d1c7a4aabf6f0688b049a80699133e6a3d31d17874bce453b5a
5
5
  SHA512:
6
- metadata.gz: 255b8f5d60623d6c9966ba1209773129d3312238df315a16564d8c950fa39ac738296a9c788d4cb707abad7e659e9eaef528749fa7f1de7f93a2152e0534fbb4
7
- data.tar.gz: c161bd9e8cfe47754f763a874ab83b183f76d7d290ecc53db1fa7a1ea1ec4433ee1d80efda0c139417321f02069db690fc113ab54104b5922b9c942210949e60
6
+ metadata.gz: 7975e43767efe81a4d32819a62ce805d88c51c879e7456f9ea653be43521501bf79612d61ea95ab065efcf5bf7c43fa7f4c2e657a0ab09e211310200237faceb
7
+ data.tar.gz: 03f711b7f01ba88e9e84676ce442737bf8c7cd14db67cd04bdd50aa30eddaad850133d476e11b7a0c0ed25f485740810d6724e0449f7343cc10345bc67ba9c5c
data/.rubocop.yml CHANGED
@@ -102,7 +102,7 @@ Style/FormatStringToken:
102
102
  EnforcedStyle: unannotated
103
103
 
104
104
  Style/HashSyntax:
105
- EnforceStyle: ruby19_no_mixed_keys
105
+ EnforcedStyle: ruby19_no_mixed_keys
106
106
  EnforcedShorthandSyntax: either
107
107
 
108
108
  Style/IfUnlessModifier:
data/Changes CHANGED
@@ -1,5 +1,17 @@
1
1
  Change history of write_xlsx rubygem.
2
2
 
3
+ 2023-12-26 v1.11.2
4
+ Fix issue where header images in chartsheets weren't displayed.
5
+ Add support for custom table total functions.
6
+ Add chart option to display N/A as empty cells.
7
+ Add support for leader lines to all chart types.
8
+ Fix issue where column formulas were overwritten by table data
9
+ add Worksheet#very_hidden method.
10
+ Add add trendline equation formatting for chart.
11
+
12
+ 2023-08-09 v1.11.1
13
+ Fixed issue #110. Redefining costant Struct::ColInfo
14
+
3
15
  2023-05-06 v1.11.0
4
16
  Added support for simulated worksheet `autofit()`.
5
17
 
@@ -218,7 +218,7 @@ shapes_list.each_line do |line|
218
218
  line = line.chomp
219
219
  next unless line =~ /^\w/ # Skip blank lines and comments.
220
220
 
221
- sheet, name = line.split(/\t/)
221
+ sheet, name = line.split("\t")
222
222
  if last_sheet != sheet
223
223
  worksheet = workbook.add_worksheet(sheet)
224
224
  row = 2
@@ -1,4 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
+ # frozen_string_literal: true
2
3
 
3
4
  ###############################################################################
4
5
  #
@@ -1,4 +1,5 @@
1
1
  # -*- encoding: utf-8 -*-
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'write_xlsx/package/xml_writer_simple'
4
5
  require 'write_xlsx/utility'
@@ -1,4 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
+ # frozen_string_literal: true
2
3
 
3
4
  ###############################################################################
4
5
  #
@@ -1,4 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
+ # frozen_string_literal: true
2
3
 
3
4
  module Writexlsx
4
5
  class Chart
@@ -1,4 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
+ # frozen_string_literal: true
2
3
 
3
4
  ###############################################################################
4
5
  #
@@ -1,4 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
+ # frozen_string_literal: true
2
3
 
3
4
  ###############################################################################
4
5
  #
@@ -1,4 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
+ # frozen_string_literal: true
2
3
 
3
4
  module Writexlsx
4
5
  class Chart
@@ -1,4 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
+ # frozen_string_literal: true
2
3
 
3
4
  ###############################################################################
4
5
  #
@@ -1,4 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
+ # frozen_string_literal: true
2
3
 
3
4
  ###############################################################################
4
5
  #
@@ -122,8 +123,7 @@ module Writexlsx
122
123
  # Write the <c:legend> element.
123
124
  #
124
125
  def write_legend
125
- position = @legend.position
126
- allowed = %w[right left top bottom]
126
+ allowed = %w[right left top bottom]
127
127
  delete_series = @legend.delete_series || []
128
128
 
129
129
  if @legend.position =~ /^overlay_/
@@ -206,6 +206,19 @@ module Writexlsx
206
206
  def write_first_slice_ang
207
207
  @writer.empty_tag('c:firstSliceAng', [['val', @rotation]])
208
208
  end
209
+
210
+ #
211
+ # Write the <c:showLeaderLines> element. This is for Pie/Doughnut charts.
212
+ # Other chart types only supported leader lines after Excel 2015 via an
213
+ # extension element.
214
+ #
215
+ def write_show_leader_lines
216
+ val = 1
217
+
218
+ attributes = [['val', val]]
219
+
220
+ @writer.empty_tag('c:showLeaderLines', attributes)
221
+ end
209
222
  end
210
223
  end
211
224
  end
@@ -1,4 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
+ # frozen_string_literal: true
2
3
 
3
4
  ###############################################################################
4
5
  #
@@ -1,4 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
+ # frozen_string_literal: true
2
3
 
3
4
  ###############################################################################
4
5
  #
@@ -1,4 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
+ # frozen_string_literal: true
2
3
 
3
4
  module Writexlsx
4
5
  class Chart
@@ -58,10 +59,13 @@ module Writexlsx
58
59
  class Trendline < Chartline
59
60
  attr_reader :name, :forward, :backward, :order, :period
60
61
  attr_reader :intercept, :display_equation, :display_r_squared
62
+ attr_reader :label
61
63
 
62
64
  def initialize(params)
63
65
  super(params)
64
66
 
67
+ @label = trendline_label_properties(params[:label])
68
+
65
69
  @name = params[:name]
66
70
  @forward = params[:forward]
67
71
  @backward = params[:backward]
@@ -75,6 +79,51 @@ module Writexlsx
75
79
 
76
80
  private
77
81
 
82
+ #
83
+ # Convert user defined trendline label properties to the structure required
84
+ # internally.
85
+ #
86
+ def trendline_label_properties(_label)
87
+ return unless _label || _label.is_a?(Hash)
88
+
89
+ # Copy the user supplied properties.
90
+ label = {}
91
+
92
+ # Set the font properties for the label.
93
+ label[:font] = convert_font_args(_label[:font]) if ptrue?(_label[:font])
94
+
95
+ # Set the line properties for the label.
96
+ line = line_properties(_label[:line])
97
+
98
+ # Allow 'border' as a synonym for 'line'.
99
+ line = line_properties(_label[:border]) if ptrue?(_label[:border])
100
+
101
+ # Set the fill properties for the label.
102
+ fill = fill_properties(_label[:fill])
103
+
104
+ # Set the pattern properties for the label.
105
+ pattern = pattern_properties(_label[:pattern])
106
+
107
+ # Set the gradient fill properties for the label.
108
+ gradient = gradient_properties(_label[:gradient])
109
+
110
+ # Pattern fill overrides solid fill.
111
+ fill = nil if ptrue?(pattern)
112
+
113
+ # Gradient fill overrides solid and pattern fills.
114
+ if ptrue?(gradient)
115
+ pattern = nil
116
+ fill = nil
117
+ end
118
+
119
+ label[:line] = line
120
+ label[:fill] = fill
121
+ label[:pattern] = pattern
122
+ label[:gradient] = gradient
123
+
124
+ label
125
+ end
126
+
78
127
  def types
79
128
  {
80
129
  exponential: 'exp',
@@ -182,6 +231,7 @@ module Writexlsx
182
231
  attr_reader :values, :categories, :name, :name_formula, :name_id
183
232
  attr_reader :cat_data_id, :val_data_id, :fill, :pattern, :gradient
184
233
  attr_reader :trendline, :smooth, :labels, :invert_if_negative
234
+ attr_reader :inverted_color
185
235
  attr_reader :x2_axis, :y2_axis, :error_bars, :points
186
236
  attr_accessor :line, :marker
187
237
 
@@ -217,10 +267,12 @@ module Writexlsx
217
267
 
218
268
  @label_positions = chart.label_positions
219
269
  @label_position_default = chart.label_position_default
220
- @labels = labels_properties(params[:data_labels])
270
+ @labels = labels_properties(params[:data_labels])
271
+ @inverted_color = params[:invert_if_negative_color]
221
272
 
222
- %i[smooth invert_if_negative x2_axis y2_axis]
223
- .each { |key| instance_variable_set("@#{key}", params[key]) }
273
+ %i[
274
+ smooth invert_if_negative x2_axis y2_axis
275
+ ].each { |key| instance_variable_set("@#{key}", params[key]) }
224
276
  end
225
277
 
226
278
  def ==(other)
@@ -228,7 +280,7 @@ module Writexlsx
228
280
  categories values name name_formula name_id
229
281
  cat_data_id val_data_id
230
282
  line fill gradient marker trendline
231
- smooth labels invert_if_neg
283
+ smooth labels inverted_color
232
284
  x2_axis y2_axis error_bars points
233
285
  ]
234
286
  methods.each do |method|
@@ -1,4 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
+ # frozen_string_literal: true
2
3
 
3
4
  ###############################################################################
4
5
  #
@@ -568,6 +568,13 @@ module Writexlsx
568
568
  @is_secondary
569
569
  end
570
570
 
571
+ #
572
+ # Set the option for displaying #N/A as an empty cell in a chart.
573
+ #
574
+ def show_na_as_empty_cell
575
+ @show_na_as_empty = true
576
+ end
577
+
571
578
  private
572
579
 
573
580
  def axis_setup
@@ -598,6 +605,7 @@ module Writexlsx
598
605
  @cross_between = 'between'
599
606
  @date_category = false
600
607
  @show_blanks = 'gap'
608
+ @show_na_as_empty = false
601
609
  @show_hidden_data = false
602
610
  @show_crosses = true
603
611
  end
@@ -782,6 +790,9 @@ module Writexlsx
782
790
 
783
791
  # Write the c:dispBlanksAs element.
784
792
  write_disp_blanks_as
793
+
794
+ # Write the c:extLst element.
795
+ write_ext_lst_display_na if @show_na_as_empty
785
796
  end
786
797
  end
787
798
 
@@ -950,10 +961,62 @@ module Writexlsx
950
961
  write_val(series)
951
962
  # Write the c:smooth element.
952
963
  write_c_smooth(series.smooth) if ptrue?(@smooth_allowed)
964
+ # Write the c:extLst element.
965
+ write_ext_lst_inverted_fill(series.inverted_color) if series.inverted_color
953
966
  end
954
967
  @series_index += 1
955
968
  end
956
969
 
970
+ def write_ext_lst_inverted_fill(color)
971
+ uri = '{6F2FDCE9-48DA-4B69-8628-5D25D57E5C99}'
972
+ xmlns_c_14 =
973
+ 'http://schemas.microsoft.com/office/drawing/2007/8/2/chart'
974
+
975
+ attributes_1 = [
976
+ ['uri', uri],
977
+ ['xmlns:c14', xmlns_c_14]
978
+ ]
979
+
980
+ attributes_2 = [
981
+ ['xmlns:c14', xmlns_c_14]
982
+ ]
983
+
984
+ @writer.tag_elements('c:extLst') do
985
+ @writer.tag_elements('c:ext', attributes_1) do
986
+ @writer.tag_elements('c14:invertSolidFillFmt') do
987
+ @writer.tag_elements('c14:spPr', attributes_2) do
988
+ write_a_solid_fill(color: color)
989
+ end
990
+ end
991
+ end
992
+ end
993
+ end
994
+
995
+ #
996
+ # Write the <c:extLst> element for the display N/A as empty cell option.
997
+ #
998
+ def write_ext_lst_display_na
999
+ uri = '{56B9EC1D-385E-4148-901F-78D8002777C0}'
1000
+ xmlns_c_16 = 'http://schemas.microsoft.com/office/drawing/2017/03/chart'
1001
+
1002
+ attributes1 = [
1003
+ ['uri', uri],
1004
+ ['xmlns:c16r3', xmlns_c_16]
1005
+ ]
1006
+
1007
+ attributes2 = [
1008
+ ['val', 1]
1009
+ ]
1010
+
1011
+ @writer.tag_elements('c:extLst') do
1012
+ @writer.tag_elements('c:ext', attributes1) do
1013
+ @writer.tag_elements('c16r3:dataDisplayOptions16') do
1014
+ @writer.empty_tag('c16r3:dispNaAsBlank', attributes2)
1015
+ end
1016
+ end
1017
+ end
1018
+ end
1019
+
957
1020
  def write_ser_base(series)
958
1021
  # Write the c:idx element.
959
1022
  write_idx(@series_index)
@@ -2018,20 +2081,25 @@ module Writexlsx
2018
2081
  attributes << ['w', width]
2019
2082
  end
2020
2083
 
2021
- @writer.tag_elements('a:ln', attributes) do
2022
- # Write the line fill.
2023
- if ptrue?(line[:none])
2024
- # Write the a:noFill element.
2025
- write_a_no_fill
2026
- elsif ptrue?(line[:color])
2027
- # Write the a:solidFill element.
2028
- write_a_solid_fill(line)
2029
- end
2030
- # Write the line/dash type.
2031
- if line[:dash_type]
2032
- # Write the a:prstDash element.
2033
- write_a_prst_dash(line[:dash_type])
2084
+ if ptrue?(line[:none]) || ptrue?(line[:color]) || line[:dash_type]
2085
+ @writer.tag_elements('a:ln', attributes) do
2086
+ # Write the line fill.
2087
+ if ptrue?(line[:none])
2088
+ # Write the a:noFill element.
2089
+ write_a_no_fill
2090
+ elsif ptrue?(line[:color])
2091
+ # Write the a:solidFill element.
2092
+ write_a_solid_fill(line)
2093
+ end
2094
+
2095
+ # Write the line/dash type.
2096
+ if line[:dash_type]
2097
+ # Write the a:prstDash element.
2098
+ write_a_prst_dash(line[:dash_type])
2099
+ end
2034
2100
  end
2101
+ else
2102
+ @writer.empty_tag('a:ln', attributes)
2035
2103
  end
2036
2104
  end
2037
2105
 
@@ -2091,7 +2159,7 @@ module Writexlsx
2091
2159
  # Write the c:dispEq element.
2092
2160
  write_disp_eq
2093
2161
  # Write the c:trendlineLbl element.
2094
- write_trendline_lbl
2162
+ write_trendline_lbl(trendline)
2095
2163
  end
2096
2164
  end
2097
2165
  end
@@ -2168,12 +2236,18 @@ module Writexlsx
2168
2236
  #
2169
2237
  # Write the <c:trendlineLbl> element.
2170
2238
  #
2171
- def write_trendline_lbl
2239
+ def write_trendline_lbl(trendline)
2172
2240
  @writer.tag_elements('c:trendlineLbl') do
2173
2241
  # Write the c:layout element.
2174
2242
  write_layout
2175
2243
  # Write the c:numFmt element.
2176
2244
  write_trendline_num_fmt
2245
+ # Write the c:spPr element for the label formatting.
2246
+ write_sp_pr(trendline.label)
2247
+ # Write the data label font elements.
2248
+ if trendline.label && ptrue?(trendline.label[:font])
2249
+ write_axis_font(trendline.label[:font])
2250
+ end
2177
2251
  end
2178
2252
  end
2179
2253
 
@@ -2513,11 +2587,25 @@ module Writexlsx
2513
2587
  @writer.data_element('c:separator', data)
2514
2588
  end
2515
2589
 
2516
- #
2517
- # Write the <c:showLeaderLines> element.
2518
- #
2590
+ # Write the <c:showLeaderLines> element. This is different for Pie/Doughnut
2591
+ # charts. Other chart types only supported leader lines after Excel 2015 via
2592
+ # an extension element.
2519
2593
  def write_show_leader_lines
2520
- @writer.empty_tag('c:showLeaderLines', [['val', 1]])
2594
+ uri = '{CE6537A1-D6FC-4f65-9D91-7224C49458BB}'
2595
+ xmlns_c_15 = 'http://schemas.microsoft.com/office/drawing/2012/chart'
2596
+
2597
+ attributes1 = [
2598
+ ['uri', uri],
2599
+ ['xmlns:c15', xmlns_c_15]
2600
+ ]
2601
+
2602
+ attributes2 = [['val', 1]]
2603
+
2604
+ @writer.tag_elements('c:extLst') do
2605
+ @writer.tag_elements('c:ext', attributes1) do
2606
+ @writer.empty_tag('c15:showLeaderLines', attributes2)
2607
+ end
2608
+ end
2521
2609
  end
2522
2610
 
2523
2611
  #
@@ -2831,8 +2919,6 @@ module Writexlsx
2831
2919
  # Write the <a:fillToRect> element.
2832
2920
  #
2833
2921
  def write_a_fill_to_rect(type)
2834
- attributes = []
2835
-
2836
2922
  attributes = if type == 'shape'
2837
2923
  [
2838
2924
  ['l', 50000],
@@ -2854,8 +2940,6 @@ module Writexlsx
2854
2940
  # Write the <a:tileRect> element.
2855
2941
  #
2856
2942
  def write_a_tile_rect(type)
2857
- attributes = []
2858
-
2859
2943
  attributes = if type == 'shape'
2860
2944
  []
2861
2945
  else
@@ -54,6 +54,8 @@ module Writexlsx
54
54
  write_header_footer
55
55
  # Write the drawing element.
56
56
  write_drawings
57
+ # Write the legaacyDrawingHF element.
58
+ write_legacy_drawing_hf
57
59
  # Close the worksheet tag.
58
60
  end
59
61
  end
@@ -145,6 +147,10 @@ module Writexlsx
145
147
  @chart.show_blanks_as(*args)
146
148
  end
147
149
 
150
+ def show_na_as_empty_cell
151
+ @chart.show_na_as_empty_cell(*args)
152
+ end
153
+
148
154
  def show_hidden_data(*args)
149
155
  @chart.show_hidden_data(*args)
150
156
  end
@@ -185,7 +191,10 @@ module Writexlsx
185
191
  end
186
192
 
187
193
  def external_links
188
- [@external_drawing_links]
194
+ [
195
+ @external_drawing_links,
196
+ @external_vml_links
197
+ ]
189
198
  end
190
199
 
191
200
  private
@@ -7,12 +7,16 @@ class ColName
7
7
  include Singleton
8
8
 
9
9
  def initialize
10
- @col_str_table = {}
10
+ @col_str_table = []
11
+ @row_str_table = []
11
12
  end
12
13
 
13
14
  def col_str(col)
14
- @col_str_table[col] = col_str_build(col) unless @col_str_table[col]
15
- @col_str_table[col]
15
+ @col_str_table[col] ||= col_str_build(col)
16
+ end
17
+
18
+ def row_str(row)
19
+ @row_str_table[row] ||= row.to_s
16
20
  end
17
21
 
18
22
  private
@@ -4,25 +4,26 @@
4
4
  module Writexlsx
5
5
  class Colors
6
6
  COLORS = {
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
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
  ###############################################################################
@@ -324,7 +324,7 @@ module Writexlsx
324
324
  return colors[color_code.downcase.to_sym] if colors[color_code.downcase.to_sym]
325
325
 
326
326
  # or the default color if string is unrecognised,
327
- return 0x00 if color_code =~ /\D/
327
+ 0x00 if color_code =~ /\D/
328
328
  else
329
329
  # or an index < 8 mapped into the correct range,
330
330
  return color_code + 8 if color_code < 8
@@ -584,14 +584,16 @@ module Writexlsx
584
584
  if theme == -1
585
585
  # Ignore for excel2003_style
586
586
  elsif ptrue?(theme)
587
- write_color(writer, 'theme', theme)
587
+ write_color('theme', theme, writer)
588
588
  elsif ptrue?(@color_indexed)
589
- write_color(writer, 'indexed', @color_indexed)
589
+ write_color('indexed', @color_indexed, writer)
590
590
  elsif ptrue?(@color)
591
591
  color = worksheet.palette_color(@color)
592
- write_color(writer, 'rgb', color)
592
+ if color != 'Automatic'
593
+ write_color('rgb', color, writer)
594
+ end
593
595
  elsif !ptrue?(dxf_format)
594
- write_color(writer, 'theme', 1)
596
+ write_color('theme', 1, writer)
595
597
  end
596
598
 
597
599
  unless ptrue?(dxf_format)
@@ -607,12 +609,12 @@ module Writexlsx
607
609
  writer.empty_tag('sz', [['val', size]])
608
610
 
609
611
  if ptrue?(theme)
610
- write_color(writer, 'theme', theme)
612
+ write_color('theme', theme, writer)
611
613
  elsif ptrue?(@color)
612
614
  color = worksheet.palette_color(@color)
613
- write_color(writer, 'rgb', color)
615
+ write_color('rgb', color, writer)
614
616
  else
615
- write_color(writer, 'theme', 1)
617
+ write_color('theme', 1, writer)
616
618
  end
617
619
 
618
620
  writer.empty_tag('rFont', [['val', @font]])
@@ -46,7 +46,9 @@ module Writexlsx
46
46
  add_heading_pair(
47
47
  [
48
48
  'Worksheets',
49
- @workbook.worksheets.reject { |s| s.is_chartsheet? }.count
49
+ @workbook.worksheets.reject do |s|
50
+ s.is_chartsheet? || s.very_hidden?
51
+ end.count
50
52
  ]
51
53
  )
52
54
  end
@@ -57,14 +59,16 @@ module Writexlsx
57
59
 
58
60
  def add_worksheet_part_names
59
61
  @workbook.worksheets
60
- .reject { |sheet| sheet.is_chartsheet? }
61
- .each { |sheet| add_part_name(sheet.name) }
62
+ .reject { |sheet| sheet.is_chartsheet? || sheet.very_hidden? }
63
+ .each do |sheet|
64
+ add_part_name(sheet.name)
65
+ end
62
66
  end
63
67
 
64
68
  def add_chartsheet_part_names
65
69
  @workbook.worksheets
66
- .select { |sheet| sheet.is_chartsheet? }
67
- .each { |sheet| add_part_name(sheet.name) }
70
+ .select { |sheet| sheet.is_chartsheet? }
71
+ .each { |sheet| add_part_name(sheet.name) }
68
72
  end
69
73
 
70
74
  def add_part_name(part_name)
@@ -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
- result = sprintf("%02x%02x%02x", *rgb)
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