write_xlsx 1.11.0 → 1.11.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 14a7593970ecc4db14f2accbdc1634033ac9042cdd7680a20d4400ea1eda741f
4
- data.tar.gz: 2ec671ba25dc571f612dc5b9d4a9c4ede2e147203d2e085313ea8b4a5f774377
3
+ metadata.gz: cabafeb058f3742956ec06251cab5ecf67d9b76cd5db3ec659e2e4184d2c1483
4
+ data.tar.gz: 95a68e0390bff44e03dc8577b31162c1d1c2cb80d77f3943947e1114327afb01
5
5
  SHA512:
6
- metadata.gz: 255b8f5d60623d6c9966ba1209773129d3312238df315a16564d8c950fa39ac738296a9c788d4cb707abad7e659e9eaef528749fa7f1de7f93a2152e0534fbb4
7
- data.tar.gz: c161bd9e8cfe47754f763a874ab83b183f76d7d290ecc53db1fa7a1ea1ec4433ee1d80efda0c139417321f02069db690fc113ab54104b5922b9c942210949e60
6
+ metadata.gz: 70a98e3ffc2be69574805f72a63678b2023cc3aef9a1c1a97c5f8a13de80de29c641c573d8c8c9bd7d33da088827a15fb6feb3b4c7591b50ffb26cb321591b49
7
+ data.tar.gz: 1d387aa195a7a35f0b664e4ff155ca71de765ad6ae886df66debc9063d1fea8c4c905ab10a7aef735d69813b79faa1d6e7ded96e70ce23a75df56e5f172b1648
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,8 @@
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
+
3
6
  2023-05-06 v1.11.0
4
7
  Added support for simulated worksheet `autofit()`.
5
8
 
@@ -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
  #
@@ -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
@@ -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 = labels_properties(params[:data_labels])
222
+ @labels = labels_properties(params[:data_labels])
223
+ @inverted_color = params[:invert_if_negative_color]
221
224
 
222
- %i[smooth invert_if_negative x2_axis y2_axis]
223
- .each { |key| instance_variable_set("@#{key}", params[key]) }
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 invert_if_neg
235
+ smooth labels inverted_color
232
236
  x2_axis y2_axis error_bars points
233
237
  ]
234
238
  methods.each do |method|
@@ -1,4 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
+ # frozen_string_literal: true
2
3
 
3
4
  ###############################################################################
4
5
  #
@@ -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
- @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])
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
 
@@ -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
  ###############################################################################
@@ -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]])
@@ -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
@@ -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(@writer, 'rgb', min_color)
822
- write_color(@writer, 'rgb', mid_color) if mid_color
823
- write_color(@writer, 'rgb', max_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(@writer, 'rgb', bar_color)
847
+ write_color('rgb', bar_color)
848
848
  end
849
849
  end
850
850
 
@@ -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
@@ -186,15 +188,6 @@ module Writexlsx
186
188
  end
187
189
  end
188
190
 
189
- #
190
- # Write the <color> element.
191
- #
192
- def write_color(name, value)
193
- attributes = [[name, value]]
194
-
195
- @writer.empty_tag('color', attributes)
196
- end
197
-
198
191
  #
199
192
  # Write the <fills> element.
200
193
  #
@@ -284,10 +277,14 @@ module Writexlsx
284
277
  def write_pattern_fill(format, dxf_format)
285
278
  bg_color, fg_color = bg_and_fg_color(format, dxf_format)
286
279
 
287
- @writer.empty_tag('fgColor', [['rgb', palette_color(fg_color)]]) if fg_color && fg_color != 0
280
+ if fg_color && fg_color != 0 && fg_color != 0x40 # 'Automatic'
281
+ @writer.empty_tag('fgColor', [['rgb', palette_color(fg_color)]])
282
+ end
288
283
 
289
284
  if bg_color && bg_color != 0
290
- @writer.empty_tag('bgColor', [['rgb', palette_color(bg_color)]])
285
+ if bg_color != 0x40 # 'Automatic'
286
+ @writer.empty_tag('bgColor', [['rgb', palette_color(bg_color)]])
287
+ end
291
288
  elsif !dxf_format && format.pattern <= 1
292
289
  @writer.empty_tag('bgColor', [['indexed', 64]])
293
290
  end
@@ -390,10 +387,11 @@ module Writexlsx
390
387
  attributes = [[:style, BORDER_STYLES[style]]]
391
388
 
392
389
  @writer.tag_elements(type, attributes) do
393
- if color == 0
390
+ if [0, 0x40].include?(color) # 'Automatic'
394
391
  @writer.empty_tag('color', [['auto', 1]])
395
- else
392
+ elsif color != 0 && color != 0x40 # 'Automatic'
396
393
  color = palette_color(color)
394
+
397
395
  @writer.empty_tag('color', [['rgb', color]])
398
396
  end
399
397
  end
@@ -341,7 +341,7 @@ module Writexlsx
341
341
  #
342
342
  # Write the <color> element.
343
343
  #
344
- def write_color(writer, name, value) # :nodoc:
344
+ def write_color(name, value, writer = @writer) # :nodoc:
345
345
  attributes = [[name, value]]
346
346
 
347
347
  writer.empty_tag('color', attributes)
@@ -751,8 +751,8 @@ module Writexlsx
751
751
  # Adjust the colour index.
752
752
  idx = index - 8
753
753
 
754
- rgb = @palette[idx]
755
- sprintf("%02X%02X%02X", *rgb)
754
+ r, g, b = @palette[idx]
755
+ sprintf("%02X%02X%02X", r, g, b)
756
756
  end
757
757
 
758
758
  #
@@ -1,3 +1,3 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- WriteXLSX_VERSION = "1.11.0"
3
+ WriteXLSX_VERSION = "1.11.1"
@@ -988,7 +988,6 @@ module Writexlsx
988
988
  num_formats = []
989
989
  unique_num_formats = {}
990
990
  index = 164
991
- num_format_count = 0
992
991
 
993
992
  (@xf_formats + @dxf_formats).each do |format|
994
993
  num_format = format.num_format
@@ -1,6 +1,5 @@
1
1
  # -*- encoding: utf-8 -*-
2
-
3
- # frozen__literal: true
2
+ # frozen_string_literal: true
4
3
 
5
4
  module Writexlsx
6
5
  class Worksheet
@@ -23,6 +23,7 @@ module Writexlsx
23
23
 
24
24
  MAX_DIGIT_WIDTH = 7 # For Calabri 11. # :nodoc:
25
25
  PADDING = 5 # :nodoc:
26
+ COLINFO = Struct.new('ColInfo', :width, :format, :hidden, :level, :collapsed, :autofit)
26
27
 
27
28
  attr_reader :index # :nodoc:
28
29
  attr_reader :charts, :images, :tables, :shapes, :drawings # :nodoc:
@@ -357,8 +358,7 @@ module Writexlsx
357
358
  # Store the column data based on the first column. Padded for sorting.
358
359
  (firstcol..lastcol).each do |col|
359
360
  @col_info[col] =
360
- Struct.new('ColInfo', :width, :format, :hidden, :level, :collapsed, :autofit)
361
- .new(width, format, hidden, level, collapsed, autofit)
361
+ COLINFO.new(width, format, hidden, level, collapsed, autofit)
362
362
  end
363
363
 
364
364
  # Store the column change to allow optimisations.
@@ -497,8 +497,7 @@ module Writexlsx
497
497
  @col_info[col_num].autofit = 1
498
498
  else
499
499
  @col_info[col_num] =
500
- Struct.new('ColInfo', :width, :format, :hidden, :level, :collapsed, :autofit)
501
- .new(width, nil, 0, 0, 0, 1)
500
+ COLINFO.new(width, nil, 0, 0, 0, 1)
502
501
  end
503
502
  end
504
503
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: write_xlsx
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.11.0
4
+ version: 1.11.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hideo NAKAMURA
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-05-06 00:00:00.000000000 Z
11
+ date: 2023-08-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubyzip