write_xlsx 0.54.0 → 0.55.0

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.
@@ -1,5 +1,5 @@
1
1
  require 'write_xlsx/workbook'
2
2
 
3
3
  class WriteXLSX < Writexlsx::Workbook
4
- VERSION = "0.54.0"
4
+ VERSION = "0.55.0"
5
5
  end
@@ -35,6 +35,7 @@ module Writexlsx
35
35
  # insert_shape
36
36
  # data_validation
37
37
  # conditional_formatting
38
+ # add_sparkline
38
39
  # add_table
39
40
  # name
40
41
  # activate
@@ -362,6 +363,7 @@ def initialize(workbook, index, name) #:nodoc:
362
363
  @name = name
363
364
  @colinfo = []
364
365
  @cell_data_table = {}
366
+ @excel_version = 2007
365
367
 
366
368
  @print_style = PrintStyle.new
367
369
 
@@ -407,6 +409,7 @@ def initialize(workbook, index, name) #:nodoc:
407
409
  @charts = []
408
410
  @images = []
409
411
  @tables = []
412
+ @sparklines = []
410
413
  @shapes = []
411
414
  @shape_hash = {}
412
415
 
@@ -452,7 +455,7 @@ def assemble_xml_file #:nodoc:
452
455
  write_drawings
453
456
  write_legacy_drawing
454
457
  write_table_parts
455
- # write_ext_lst
458
+ write_ext_sparklines
456
459
  @writer.end_tag('worksheet')
457
460
  @writer.crlf
458
461
  @writer.close
@@ -3302,10 +3305,12 @@ def conditional_formatting(*args)
3302
3305
  param[:formula] = %Q!ISERROR(SEARCH("#{param[:value]}",#{start_cell}))!
3303
3306
  when 'beginsWith'
3304
3307
  param[:type] = 'beginsWith'
3305
- param[:formula] = %Q!LEFT(#{start_cell},1)="#{param[:value]}"!
3308
+ param[:formula] =
3309
+ %Q!LEFT(#{start_cell},#{param[:value].size})="#{param[:value]}"!
3306
3310
  when 'endsWith'
3307
3311
  param[:type] = 'endsWith'
3308
- param[:formula] = %Q!RIGHT(#{start_cell},1)="#{param[:value]}"!
3312
+ param[:formula] =
3313
+ %Q!RIGHT(#{start_cell},#{param[:value].size})="#{param[:value]}"!
3309
3314
  else
3310
3315
  raise "Invalid text criteria '#{param[:criteria]} in conditional_formatting()"
3311
3316
  end
@@ -3633,6 +3638,115 @@ def valid_table_parameter
3633
3638
  :total_row
3634
3639
  ]
3635
3640
  end
3641
+ private :valid_table_parameter
3642
+
3643
+ #
3644
+ # add_sparkline
3645
+ #
3646
+ def add_sparkline(param)
3647
+ sparkline = {}
3648
+
3649
+ # Check for valid input parameters.
3650
+ param.each_key do |k|
3651
+ unless valid_sparkline_parameter[k]
3652
+ raise "Unknown parameter '#{k}' in add_sparkline()"
3653
+ end
3654
+ end
3655
+ [:location, :range].each do |required_key|
3656
+ unless param[required_key]
3657
+ raise "Parameter '#{required_key}' is required in add_sparkline()"
3658
+ end
3659
+ end
3660
+
3661
+ # Handle the sparkline type.
3662
+ type = param[:type] || 'line'
3663
+ unless ['line', 'column', 'win_loss'].include?(type)
3664
+ raise "Parameter ':type' must be 'line', 'column' or 'win_loss' in add_sparkline()"
3665
+ end
3666
+ type = 'stacked' if type == 'win_loss'
3667
+ sparkline[:_type] = type
3668
+
3669
+ # We handle single location/range values or array refs of values.
3670
+ sparkline[:_locations] = [param[:location]].flatten
3671
+ sparkline[:_ranges] = [param[:range]].flatten
3672
+
3673
+ if sparkline[:_ranges].size != sparkline[:_locations].size
3674
+ raise "Must have the same number of location and range parameters in add_sparkline()"
3675
+ end
3676
+
3677
+ # Store the count.
3678
+ sparkline[:_count] = sparkline[:_locations].size
3679
+
3680
+ # Get the worksheet name for the range conversion below.
3681
+ sheetname = quote_sheetname(@name)
3682
+
3683
+ # Cleanup the input ranges.
3684
+ sparkline[:_ranges].collect! do |range|
3685
+ # Remove the absolute reference $ symbols.
3686
+ range = range.gsub(/\$/, '')
3687
+ # Convert a simiple range into a full Sheet1!A1:D1 range.
3688
+ range = "#{sheetname}!#{range}" unless range =~ /!/
3689
+ range
3690
+ end
3691
+
3692
+ # Cleanup the input locations.
3693
+ sparkline[:_locations].collect! { |location| location.gsub(/\$/, '') }
3694
+
3695
+ # Map options.
3696
+ sparkline[:_high] = param[:high_point]
3697
+ sparkline[:_low] = param[:low_point]
3698
+ sparkline[:_negative] = param[:negative_points]
3699
+ sparkline[:_first] = param[:first_point]
3700
+ sparkline[:_last] = param[:last_point]
3701
+ sparkline[:_markers] = param[:markers]
3702
+ sparkline[:_min] = param[:min]
3703
+ sparkline[:_max] = param[:max]
3704
+ sparkline[:_axis] = param[:axis]
3705
+ sparkline[:_reverse] = param[:reverse]
3706
+ sparkline[:_hidden] = param[:show_hidden]
3707
+ sparkline[:_weight] = param[:weight]
3708
+
3709
+ # Map empty cells options.
3710
+ empty = param[:empty_cells] || ''
3711
+ sparkline[:_empty] = case empty
3712
+ when 'zero'
3713
+ 0
3714
+ when 'connect'
3715
+ 'span'
3716
+ else
3717
+ 'gap'
3718
+ end
3719
+
3720
+ # Map the date axis range.
3721
+ date_range = param[:date_axis]
3722
+ if ptrue?(date_range) && !(date_range =~ /!/)
3723
+ date_range = "#{sheetname}!#{date_range}"
3724
+ end
3725
+ sparkline[:_date_axis] = date_range
3726
+
3727
+ # Set the sparkline styles.
3728
+ style_id = param[:style] || 0
3729
+ style = spark_styles[style_id]
3730
+
3731
+ sparkline[:_series_color] = style[:series]
3732
+ sparkline[:_negative_color] = style[:negative]
3733
+ sparkline[:_markers_color] = style[:markers]
3734
+ sparkline[:_first_color] = style[:first]
3735
+ sparkline[:_last_color] = style[:last]
3736
+ sparkline[:_high_color] = style[:high]
3737
+ sparkline[:_low_color] = style[:low]
3738
+
3739
+ # Override the style colours with user defined colors.
3740
+ set_spark_color(sparkline, param, :series_color)
3741
+ set_spark_color(sparkline, param, :negative_color)
3742
+ set_spark_color(sparkline, param, :markers_color)
3743
+ set_spark_color(sparkline, param, :first_color)
3744
+ set_spark_color(sparkline, param, :last_color)
3745
+ set_spark_color(sparkline, param, :high_color)
3746
+ set_spark_color(sparkline, param, :low_color)
3747
+
3748
+ @sparklines << sparkline
3749
+ end
3636
3750
 
3637
3751
  #
3638
3752
  # :call-seq:
@@ -5654,12 +5768,18 @@ def encode_password(password) #:nodoc:
5654
5768
  # Write the <worksheet> element. This is the root element of Worksheet.
5655
5769
  #
5656
5770
  def write_worksheet #:nodoc:
5657
- schema = 'http://schemas.openxmlformats.org/'
5658
- attributes = [
5659
- 'xmlns', schema + 'spreadsheetml/2006/main',
5660
- 'xmlns:r', schema + 'officeDocument/2006/relationships'
5661
- ]
5662
- @writer.start_tag('worksheet', attributes)
5771
+ schema = 'http://schemas.openxmlformats.org/'
5772
+ attributes = [
5773
+ 'xmlns', schema + 'spreadsheetml/2006/main',
5774
+ 'xmlns:r', schema + 'officeDocument/2006/relationships'
5775
+ ]
5776
+ if @excel_version == 2010
5777
+ attributes << 'xmlns:mc' << "#{schema}markup-compatibility/2006"
5778
+ attributes << 'xmlns:x14ac' <<
5779
+ 'http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac'
5780
+ attributes << 'mc:Ignorable' << 'x14ac'
5781
+ end
5782
+ @writer.start_tag('worksheet', attributes)
5663
5783
  end
5664
5784
 
5665
5785
  #
@@ -5798,6 +5918,9 @@ def write_sheet_format_pr #:nodoc:
5798
5918
  attributes = ['defaultRowHeight', default_row_height]
5799
5919
  attributes << 'outlineLevelRow' << @outline_row_level if @outline_row_level > 0
5800
5920
  attributes << 'outlineLevelCol' << @outline_col_level if @outline_col_level > 0
5921
+ if @excel_version == 2010
5922
+ attributes << 'x14ac:dyDescent' << '0.25'
5923
+ end
5801
5924
  @writer.empty_tag('sheetFormatPr', attributes)
5802
5925
  end
5803
5926
 
@@ -5966,6 +6089,9 @@ def write_row_element(r, spans = nil, height = 15, format = nil, hidden = false,
5966
6089
  (attributes << 'outlineLevel' << level) if ptrue?(level)
5967
6090
  (attributes << 'collapsed' << 1 ) if ptrue?(collapsed)
5968
6091
 
6092
+ if @excel_version == 2010
6093
+ attributes << 'x14ac:dyDescent' << '0.25'
6094
+ end
5969
6095
  if ptrue?(empty_row)
5970
6096
  @writer.empty_tag('row', attributes)
5971
6097
  else
@@ -6184,45 +6310,6 @@ def write_page_setup #:nodoc:
6184
6310
  @writer.empty_tag('pageSetup', attributes)
6185
6311
  end
6186
6312
 
6187
- #
6188
- # Write the <extLst> element.
6189
- #
6190
- def write_ext_lst #:nodoc:
6191
- @writer.tag_elements('extLst') { write_ext }
6192
- end
6193
-
6194
- #
6195
- # Write the <ext> element.
6196
- #
6197
- def write_ext #:nodoc:
6198
- xmlnsmx = 'http://schemas.microsoft.com/office/mac/excel/2008/main'
6199
- uri = 'http://schemas.microsoft.com/office/mac/excel/2008/main'
6200
-
6201
- attributes = [
6202
- 'xmlns:mx', xmlnsmx,
6203
- 'uri', uri
6204
- ]
6205
-
6206
- @writer.tag_elements('ext', attributes) { write_mx_plv }
6207
- end
6208
-
6209
- #
6210
- # Write the <mx:PLV> element.
6211
- #
6212
- def write_mx_plv #:nodoc:
6213
- mode = 1
6214
- one_page = 0
6215
- w_scale = 0
6216
-
6217
- attributes = [
6218
- 'Mode', mode,
6219
- 'OnePage', one_page,
6220
- 'WScale', w_scale
6221
- ]
6222
-
6223
- @writer.empty_tag('mx:PLV', attributes)
6224
- end
6225
-
6226
6313
  #
6227
6314
  # Write the <mergeCells> element.
6228
6315
  #
@@ -6726,6 +6813,631 @@ def write_table_part(id)
6726
6813
  @writer.empty_tag('tablePart', attributes)
6727
6814
  end
6728
6815
 
6816
+ def spark_styles # :nodoc:
6817
+ [
6818
+ { # 0
6819
+ :series => { :_theme => "4", :_tint => "-0.499984740745262" },
6820
+ :negative => { :_theme => "5" },
6821
+ :markers => { :_theme => "4", :_tint => "-0.499984740745262" },
6822
+ :first => { :_theme => "4", :_tint => "0.39997558519241921" },
6823
+ :last => { :_theme => "4", :_tint => "0.39997558519241921" },
6824
+ :high => { :_theme => "4" },
6825
+ :low => { :_theme => "4" }
6826
+ },
6827
+ { # 1
6828
+ :series => { :_theme => "4", :_tint => "-0.499984740745262" },
6829
+ :negative => { :_theme => "5" },
6830
+ :markers => { :_theme => "4", :_tint => "-0.499984740745262" },
6831
+ :first => { :_theme => "4", :_tint => "0.39997558519241921" },
6832
+ :last => { :_theme => "4", :_tint => "0.39997558519241921" },
6833
+ :high => { :_theme => "4" },
6834
+ :low => { :_theme => "4" }
6835
+ },
6836
+ { # 2
6837
+ :series => { :_theme => "5", :_tint => "-0.499984740745262" },
6838
+ :negative => { :_theme => "6" },
6839
+ :markers => { :_theme => "5", :_tint => "-0.499984740745262" },
6840
+ :first => { :_theme => "5", :_tint => "0.39997558519241921" },
6841
+ :last => { :_theme => "5", :_tint => "0.39997558519241921" },
6842
+ :high => { :_theme => "5" },
6843
+ :low => { :_theme => "5" }
6844
+ },
6845
+ { # 3
6846
+ :series => { :_theme => "6", :_tint => "-0.499984740745262" },
6847
+ :negative => { :_theme => "7" },
6848
+ :markers => { :_theme => "6", :_tint => "-0.499984740745262" },
6849
+ :first => { :_theme => "6", :_tint => "0.39997558519241921" },
6850
+ :last => { :_theme => "6", :_tint => "0.39997558519241921" },
6851
+ :high => { :_theme => "6" },
6852
+ :low => { :_theme => "6" }
6853
+ },
6854
+ { # 4
6855
+ :series => { :_theme => "7", :_tint => "-0.499984740745262" },
6856
+ :negative => { :_theme => "8" },
6857
+ :markers => { :_theme => "7", :_tint => "-0.499984740745262" },
6858
+ :first => { :_theme => "7", :_tint => "0.39997558519241921" },
6859
+ :last => { :_theme => "7", :_tint => "0.39997558519241921" },
6860
+ :high => { :_theme => "7" },
6861
+ :low => { :_theme => "7" }
6862
+ },
6863
+ { # 5
6864
+ :series => { :_theme => "8", :_tint => "-0.499984740745262" },
6865
+ :negative => { :_theme => "9" },
6866
+ :markers => { :_theme => "8", :_tint => "-0.499984740745262" },
6867
+ :first => { :_theme => "8", :_tint => "0.39997558519241921" },
6868
+ :last => { :_theme => "8", :_tint => "0.39997558519241921" },
6869
+ :high => { :_theme => "8" },
6870
+ :low => { :_theme => "8" }
6871
+ },
6872
+ { # 6
6873
+ :series => { :_theme => "9", :_tint => "-0.499984740745262" },
6874
+ :negative => { :_theme => "4" },
6875
+ :markers => { :_theme => "9", :_tint => "-0.499984740745262" },
6876
+ :first => { :_theme => "9", :_tint => "0.39997558519241921" },
6877
+ :last => { :_theme => "9", :_tint => "0.39997558519241921" },
6878
+ :high => { :_theme => "9" },
6879
+ :low => { :_theme => "9" }
6880
+ },
6881
+ { # 7
6882
+ :series => { :_theme => "4", :_tint => "-0.249977111117893" },
6883
+ :negative => { :_theme => "5" },
6884
+ :markers => { :_theme => "5", :_tint => "-0.249977111117893" },
6885
+ :first => { :_theme => "5", :_tint => "-0.249977111117893" },
6886
+ :last => { :_theme => "5", :_tint => "-0.249977111117893" },
6887
+ :high => { :_theme => "5", :_tint => "-0.249977111117893" },
6888
+ :low => { :_theme => "5", :_tint => "-0.249977111117893" }
6889
+ },
6890
+ { # 8
6891
+ :series => { :_theme => "5", :_tint => "-0.249977111117893" },
6892
+ :negative => { :_theme => "6" },
6893
+ :markers => { :_theme => "6", :_tint => "-0.249977111117893" },
6894
+ :first => { :_theme => "6", :_tint => "-0.249977111117893" },
6895
+ :last => { :_theme => "6", :_tint => "-0.249977111117893" },
6896
+ :high => { :_theme => "6", :_tint => "-0.249977111117893" },
6897
+ :low => { :_theme => "6", :_tint => "-0.249977111117893" }
6898
+ },
6899
+ { # 9
6900
+ :series => { :_theme => "6", :_tint => "-0.249977111117893" },
6901
+ :negative => { :_theme => "7" },
6902
+ :markers => { :_theme => "7", :_tint => "-0.249977111117893" },
6903
+ :first => { :_theme => "7", :_tint => "-0.249977111117893" },
6904
+ :last => { :_theme => "7", :_tint => "-0.249977111117893" },
6905
+ :high => { :_theme => "7", :_tint => "-0.249977111117893" },
6906
+ :low => { :_theme => "7", :_tint => "-0.249977111117893" }
6907
+ },
6908
+ { # 10
6909
+ :series => { :_theme => "7", :_tint => "-0.249977111117893" },
6910
+ :negative => { :_theme => "8" },
6911
+ :markers => { :_theme => "8", :_tint => "-0.249977111117893" },
6912
+ :first => { :_theme => "8", :_tint => "-0.249977111117893" },
6913
+ :last => { :_theme => "8", :_tint => "-0.249977111117893" },
6914
+ :high => { :_theme => "8", :_tint => "-0.249977111117893" },
6915
+ :low => { :_theme => "8", :_tint => "-0.249977111117893" }
6916
+ },
6917
+ { # 11
6918
+ :series => { :_theme => "8", :_tint => "-0.249977111117893" },
6919
+ :negative => { :_theme => "9" },
6920
+ :markers => { :_theme => "9", :_tint => "-0.249977111117893" },
6921
+ :first => { :_theme => "9", :_tint => "-0.249977111117893" },
6922
+ :last => { :_theme => "9", :_tint => "-0.249977111117893" },
6923
+ :high => { :_theme => "9", :_tint => "-0.249977111117893" },
6924
+ :low => { :_theme => "9", :_tint => "-0.249977111117893" }
6925
+ },
6926
+ { # 12
6927
+ :series => { :_theme => "9", :_tint => "-0.249977111117893" },
6928
+ :negative => { :_theme => "4" },
6929
+ :markers => { :_theme => "4", :_tint => "-0.249977111117893" },
6930
+ :first => { :_theme => "4", :_tint => "-0.249977111117893" },
6931
+ :last => { :_theme => "4", :_tint => "-0.249977111117893" },
6932
+ :high => { :_theme => "4", :_tint => "-0.249977111117893" },
6933
+ :low => { :_theme => "4", :_tint => "-0.249977111117893" }
6934
+ },
6935
+ { # 13
6936
+ :series => { :_theme => "4" },
6937
+ :negative => { :_theme => "5" },
6938
+ :markers => { :_theme => "4", :_tint => "-0.249977111117893" },
6939
+ :first => { :_theme => "4", :_tint => "-0.249977111117893" },
6940
+ :last => { :_theme => "4", :_tint => "-0.249977111117893" },
6941
+ :high => { :_theme => "4", :_tint => "-0.249977111117893" },
6942
+ :low => { :_theme => "4", :_tint => "-0.249977111117893" }
6943
+ },
6944
+ { # 14
6945
+ :series => { :_theme => "5" },
6946
+ :negative => { :_theme => "6" },
6947
+ :markers => { :_theme => "5", :_tint => "-0.249977111117893" },
6948
+ :first => { :_theme => "5", :_tint => "-0.249977111117893" },
6949
+ :last => { :_theme => "5", :_tint => "-0.249977111117893" },
6950
+ :high => { :_theme => "5", :_tint => "-0.249977111117893" },
6951
+ :low => { :_theme => "5", :_tint => "-0.249977111117893" }
6952
+ },
6953
+ { # 15
6954
+ :series => { :_theme => "6" },
6955
+ :negative => { :_theme => "7" },
6956
+ :markers => { :_theme => "6", :_tint => "-0.249977111117893" },
6957
+ :first => { :_theme => "6", :_tint => "-0.249977111117893" },
6958
+ :last => { :_theme => "6", :_tint => "-0.249977111117893" },
6959
+ :high => { :_theme => "6", :_tint => "-0.249977111117893" },
6960
+ :low => { :_theme => "6", :_tint => "-0.249977111117893" }
6961
+ },
6962
+ { # 16
6963
+ :series => { :_theme => "7" },
6964
+ :negative => { :_theme => "8" },
6965
+ :markers => { :_theme => "7", :_tint => "-0.249977111117893" },
6966
+ :first => { :_theme => "7", :_tint => "-0.249977111117893" },
6967
+ :last => { :_theme => "7", :_tint => "-0.249977111117893" },
6968
+ :high => { :_theme => "7", :_tint => "-0.249977111117893" },
6969
+ :low => { :_theme => "7", :_tint => "-0.249977111117893" }
6970
+ },
6971
+ { # 17
6972
+ :series => { :_theme => "8" },
6973
+ :negative => { :_theme => "9" },
6974
+ :markers => { :_theme => "8", :_tint => "-0.249977111117893" },
6975
+ :first => { :_theme => "8", :_tint => "-0.249977111117893" },
6976
+ :last => { :_theme => "8", :_tint => "-0.249977111117893" },
6977
+ :high => { :_theme => "8", :_tint => "-0.249977111117893" },
6978
+ :low => { :_theme => "8", :_tint => "-0.249977111117893" }
6979
+ },
6980
+ { # 18
6981
+ :series => { :_theme => "9" },
6982
+ :negative => { :_theme => "4" },
6983
+ :markers => { :_theme => "9", :_tint => "-0.249977111117893" },
6984
+ :first => { :_theme => "9", :_tint => "-0.249977111117893" },
6985
+ :last => { :_theme => "9", :_tint => "-0.249977111117893" },
6986
+ :high => { :_theme => "9", :_tint => "-0.249977111117893" },
6987
+ :low => { :_theme => "9", :_tint => "-0.249977111117893" }
6988
+ },
6989
+ { # 19
6990
+ :series => { :_theme => "4", :_tint => "0.39997558519241921" },
6991
+ :negative => { :_theme => "0", :_tint => "-0.499984740745262" },
6992
+ :markers => { :_theme => "4", :_tint => "0.79998168889431442" },
6993
+ :first => { :_theme => "4", :_tint => "-0.249977111117893" },
6994
+ :last => { :_theme => "4", :_tint => "-0.249977111117893" },
6995
+ :high => { :_theme => "4", :_tint => "-0.499984740745262" },
6996
+ :low => { :_theme => "4", :_tint => "-0.499984740745262" }
6997
+ },
6998
+ { # 20
6999
+ :series => { :_theme => "5", :_tint => "0.39997558519241921" },
7000
+ :negative => { :_theme => "0", :_tint => "-0.499984740745262" },
7001
+ :markers => { :_theme => "5", :_tint => "0.79998168889431442" },
7002
+ :first => { :_theme => "5", :_tint => "-0.249977111117893" },
7003
+ :last => { :_theme => "5", :_tint => "-0.249977111117893" },
7004
+ :high => { :_theme => "5", :_tint => "-0.499984740745262" },
7005
+ :low => { :_theme => "5", :_tint => "-0.499984740745262" }
7006
+ },
7007
+ { # 21
7008
+ :series => { :_theme => "6", :_tint => "0.39997558519241921" },
7009
+ :negative => { :_theme => "0", :_tint => "-0.499984740745262" },
7010
+ :markers => { :_theme => "6", :_tint => "0.79998168889431442" },
7011
+ :first => { :_theme => "6", :_tint => "-0.249977111117893" },
7012
+ :last => { :_theme => "6", :_tint => "-0.249977111117893" },
7013
+ :high => { :_theme => "6", :_tint => "-0.499984740745262" },
7014
+ :low => { :_theme => "6", :_tint => "-0.499984740745262" }
7015
+ },
7016
+ { # 22
7017
+ :series => { :_theme => "7", :_tint => "0.39997558519241921" },
7018
+ :negative => { :_theme => "0", :_tint => "-0.499984740745262" },
7019
+ :markers => { :_theme => "7", :_tint => "0.79998168889431442" },
7020
+ :first => { :_theme => "7", :_tint => "-0.249977111117893" },
7021
+ :last => { :_theme => "7", :_tint => "-0.249977111117893" },
7022
+ :high => { :_theme => "7", :_tint => "-0.499984740745262" },
7023
+ :low => { :_theme => "7", :_tint => "-0.499984740745262" }
7024
+ },
7025
+ { # 23
7026
+ :series => { :_theme => "8", :_tint => "0.39997558519241921" },
7027
+ :negative => { :_theme => "0", :_tint => "-0.499984740745262" },
7028
+ :markers => { :_theme => "8", :_tint => "0.79998168889431442" },
7029
+ :first => { :_theme => "8", :_tint => "-0.249977111117893" },
7030
+ :last => { :_theme => "8", :_tint => "-0.249977111117893" },
7031
+ :high => { :_theme => "8", :_tint => "-0.499984740745262" },
7032
+ :low => { :_theme => "8", :_tint => "-0.499984740745262" }
7033
+ },
7034
+ { # 24
7035
+ :series => { :_theme => "9", :_tint => "0.39997558519241921" },
7036
+ :negative => { :_theme => "0", :_tint => "-0.499984740745262" },
7037
+ :markers => { :_theme => "9", :_tint => "0.79998168889431442" },
7038
+ :first => { :_theme => "9", :_tint => "-0.249977111117893" },
7039
+ :last => { :_theme => "9", :_tint => "-0.249977111117893" },
7040
+ :high => { :_theme => "9", :_tint => "-0.499984740745262" },
7041
+ :low => { :_theme => "9", :_tint => "-0.499984740745262" }
7042
+ },
7043
+ { # 25
7044
+ :series => { :_theme => "1", :_tint => "0.499984740745262" },
7045
+ :negative => { :_theme => "1", :_tint => "0.249977111117893" },
7046
+ :markers => { :_theme => "1", :_tint => "0.249977111117893" },
7047
+ :first => { :_theme => "1", :_tint => "0.249977111117893" },
7048
+ :last => { :_theme => "1", :_tint => "0.249977111117893" },
7049
+ :high => { :_theme => "1", :_tint => "0.249977111117893" },
7050
+ :low => { :_theme => "1", :_tint => "0.249977111117893" }
7051
+ },
7052
+ { # 26
7053
+ :series => { :_theme => "1", :_tint => "0.34998626667073579" },
7054
+ :negative => { :_theme => "0", :_tint => "-0.249977111117893" },
7055
+ :markers => { :_theme => "0", :_tint => "-0.249977111117893" },
7056
+ :first => { :_theme => "0", :_tint => "-0.249977111117893" },
7057
+ :last => { :_theme => "0", :_tint => "-0.249977111117893" },
7058
+ :high => { :_theme => "0", :_tint => "-0.249977111117893" },
7059
+ :low => { :_theme => "0", :_tint => "-0.249977111117893" }
7060
+ },
7061
+ { # 27
7062
+ :series => { :_rgb => "FF323232" },
7063
+ :negative => { :_rgb => "FFD00000" },
7064
+ :markers => { :_rgb => "FFD00000" },
7065
+ :first => { :_rgb => "FFD00000" },
7066
+ :last => { :_rgb => "FFD00000" },
7067
+ :high => { :_rgb => "FFD00000" },
7068
+ :low => { :_rgb => "FFD00000" }
7069
+ },
7070
+ { # 28
7071
+ :series => { :_rgb => "FF000000" },
7072
+ :negative => { :_rgb => "FF0070C0" },
7073
+ :markers => { :_rgb => "FF0070C0" },
7074
+ :first => { :_rgb => "FF0070C0" },
7075
+ :last => { :_rgb => "FF0070C0" },
7076
+ :high => { :_rgb => "FF0070C0" },
7077
+ :low => { :_rgb => "FF0070C0" }
7078
+ },
7079
+ { # 29
7080
+ :series => { :_rgb => "FF376092" },
7081
+ :negative => { :_rgb => "FFD00000" },
7082
+ :markers => { :_rgb => "FFD00000" },
7083
+ :first => { :_rgb => "FFD00000" },
7084
+ :last => { :_rgb => "FFD00000" },
7085
+ :high => { :_rgb => "FFD00000" },
7086
+ :low => { :_rgb => "FFD00000" }
7087
+ },
7088
+ { # 30
7089
+ :series => { :_rgb => "FF0070C0" },
7090
+ :negative => { :_rgb => "FF000000" },
7091
+ :markers => { :_rgb => "FF000000" },
7092
+ :first => { :_rgb => "FF000000" },
7093
+ :last => { :_rgb => "FF000000" },
7094
+ :high => { :_rgb => "FF000000" },
7095
+ :low => { :_rgb => "FF000000" }
7096
+ },
7097
+ { # 31
7098
+ :series => { :_rgb => "FF5F5F5F" },
7099
+ :negative => { :_rgb => "FFFFB620" },
7100
+ :markers => { :_rgb => "FFD70077" },
7101
+ :first => { :_rgb => "FF5687C2" },
7102
+ :last => { :_rgb => "FF359CEB" },
7103
+ :high => { :_rgb => "FF56BE79" },
7104
+ :low => { :_rgb => "FFFF5055" }
7105
+ },
7106
+ { # 32
7107
+ :series => { :_rgb => "FF5687C2" },
7108
+ :negative => { :_rgb => "FFFFB620" },
7109
+ :markers => { :_rgb => "FFD70077" },
7110
+ :first => { :_rgb => "FF777777" },
7111
+ :last => { :_rgb => "FF359CEB" },
7112
+ :high => { :_rgb => "FF56BE79" },
7113
+ :low => { :_rgb => "FFFF5055" }
7114
+ },
7115
+ { # 33
7116
+ :series => { :_rgb => "FFC6EFCE" },
7117
+ :negative => { :_rgb => "FFFFC7CE" },
7118
+ :markers => { :_rgb => "FF8CADD6" },
7119
+ :first => { :_rgb => "FFFFDC47" },
7120
+ :last => { :_rgb => "FFFFEB9C" },
7121
+ :high => { :_rgb => "FF60D276" },
7122
+ :low => { :_rgb => "FFFF5367" }
7123
+ },
7124
+ { # 34
7125
+ :series => { :_rgb => "FF00B050" },
7126
+ :negative => { :_rgb => "FFFF0000" },
7127
+ :markers => { :_rgb => "FF0070C0" },
7128
+ :first => { :_rgb => "FFFFC000" },
7129
+ :last => { :_rgb => "FFFFC000" },
7130
+ :high => { :_rgb => "FF00B050" },
7131
+ :low => { :_rgb => "FFFF0000" }
7132
+ },
7133
+ { # 35
7134
+ :series => { :_theme => "3" },
7135
+ :negative => { :_theme => "9" },
7136
+ :markers => { :_theme => "8" },
7137
+ :first => { :_theme => "4" },
7138
+ :last => { :_theme => "5" },
7139
+ :high => { :_theme => "6" },
7140
+ :low => { :_theme => "7" }
7141
+ },
7142
+ { # 36
7143
+ :series => { :_theme => "1" },
7144
+ :negative => { :_theme => "9" },
7145
+ :markers => { :_theme => "8" },
7146
+ :first => { :_theme => "4" },
7147
+ :last => { :_theme => "5" },
7148
+ :high => { :_theme => "6" },
7149
+ :low => { :_theme => "7" }
7150
+ }
7151
+ ]
7152
+ end
7153
+
7154
+ def valid_sparkline_parameter # :nodoc:
7155
+ {
7156
+ :location => 1,
7157
+ :range => 1,
7158
+ :type => 1,
7159
+ :high_point => 1,
7160
+ :low_point => 1,
7161
+ :negative_points => 1,
7162
+ :first_point => 1,
7163
+ :last_point => 1,
7164
+ :markers => 1,
7165
+ :style => 1,
7166
+ :series_color => 1,
7167
+ :negative_color => 1,
7168
+ :markers_color => 1,
7169
+ :first_color => 1,
7170
+ :last_color => 1,
7171
+ :high_color => 1,
7172
+ :low_color => 1,
7173
+ :max => 1,
7174
+ :min => 1,
7175
+ :axis => 1,
7176
+ :reverse => 1,
7177
+ :empty_cells => 1,
7178
+ :show_hidden => 1,
7179
+ :date_axis => 1,
7180
+ :weight => 1
7181
+ }
7182
+ end
7183
+
7184
+ #
7185
+ #
7186
+ #
7187
+ def set_spark_color(sparkline, param, user_color) # :nodoc:
7188
+ spark_color = "_#{user_color}".to_sym
7189
+
7190
+ return unless ptrue?(param[user_color])
7191
+
7192
+ sparkline[spark_color] =
7193
+ { :_rgb => get_palette_color(param[user_color]) }
7194
+ end
7195
+ #
7196
+ # Write the <extLst> element and sparkline subelements.
7197
+ #
7198
+ def write_ext_sparklines # :nodoc:
7199
+ sparklines = @sparklines
7200
+
7201
+ # Return if worksheet doesn't contain any sparklines.
7202
+ return if sparklines.empty?
7203
+
7204
+ # Write the extLst element.
7205
+ @writer.start_tag('extLst')
7206
+
7207
+ # Write the ext element.
7208
+ write_ext
7209
+
7210
+ # Write the x14:sparklineGroups element.
7211
+ write_sparkline_groups
7212
+
7213
+ # Write the sparkline elements.
7214
+ sparklines.reverse.each do |sparkline|
7215
+ # Write the x14:sparklineGroup element.
7216
+ write_sparkline_group(sparkline)
7217
+
7218
+ # Write the x14:colorSeries element.
7219
+ write_color_series(sparkline[:_series_color])
7220
+
7221
+ # Write the x14:colorNegative element.
7222
+ write_color_negative(sparkline[:_negative_color])
7223
+
7224
+ # Write the x14:colorAxis element.
7225
+ write_color_axis
7226
+
7227
+ # Write the x14:colorMarkers element.
7228
+ write_color_markers(sparkline[:_markers_color])
7229
+
7230
+ # Write the x14:colorFirst element.
7231
+ write_color_first(sparkline[:_first_color])
7232
+
7233
+ # Write the x14:colorLast element.
7234
+ write_color_last(sparkline[:_last_color] )
7235
+
7236
+ # Write the x14:colorHigh element.
7237
+ write_color_high(sparkline[:_high_color])
7238
+
7239
+ # Write the x14:colorLow element.
7240
+ write_color_low(sparkline[:_low_color])
7241
+
7242
+ if sparkline[:_date_axis]
7243
+ @writer.data_element('xm:f', sparkline[:_date_axis])
7244
+ end
7245
+
7246
+ write_sparklines(sparkline)
7247
+
7248
+ @writer.end_tag('x14:sparklineGroup')
7249
+ end
7250
+
7251
+ @writer.end_tag('x14:sparklineGroups')
7252
+ @writer.end_tag('ext')
7253
+ @writer.end_tag('extLst')
7254
+ end
7255
+
7256
+ #
7257
+ # Write the <x14:sparklines> element and <x14:sparkline> subelements.
7258
+ #
7259
+ def write_sparklines(sparkline) # :nodoc:
7260
+ # Write the sparkline elements.
7261
+ @writer.tag_elements('x14:sparklines') do
7262
+
7263
+ (0 .. sparkline[:_count]-1).each do |i|
7264
+ range = sparkline[:_ranges][i]
7265
+ location = sparkline[:_locations][i]
7266
+
7267
+ @writer.tag_elements('x14:sparkline') do
7268
+ @writer.data_element('xm:f', range)
7269
+ @writer.data_element('xm:sqref', location)
7270
+ end
7271
+ end
7272
+ end
7273
+ end
7274
+
7275
+ #
7276
+ # Write the <ext> element.
7277
+ #
7278
+ def write_ext # :nodoc:
7279
+ schema = 'http://schemas.microsoft.com/office/'
7280
+ xmlns_x_14 = "#{schema}spreadsheetml/2009/9/main"
7281
+ uri = '{05C60535-1F16-4fd2-B633-F4F36F0B64E0}'
7282
+
7283
+ attributes = [
7284
+ 'xmlns:x14', xmlns_x_14,
7285
+ 'uri', uri
7286
+ ]
7287
+
7288
+ @writer.start_tag('ext', attributes)
7289
+ end
7290
+
7291
+ #
7292
+ # Write the <x14:sparklineGroups> element.
7293
+ #
7294
+ def write_sparkline_groups # :nodoc:
7295
+ xmlns_xm = 'http://schemas.microsoft.com/office/excel/2006/main'
7296
+
7297
+ attributes = ['xmlns:xm', xmlns_xm]
7298
+
7299
+ @writer.start_tag('x14:sparklineGroups', attributes)
7300
+ end
7301
+
7302
+ #
7303
+ # Write the <x14:sparklineGroup> element.
7304
+ #
7305
+ # Example for order.
7306
+ #
7307
+ # <x14:sparklineGroup
7308
+ # manualMax="0"
7309
+ # manualMin="0"
7310
+ # lineWeight="2.25"
7311
+ # type="column"
7312
+ # dateAxis="1"
7313
+ # displayEmptyCellsAs="span"
7314
+ # markers="1"
7315
+ # high="1"
7316
+ # low="1"
7317
+ # first="1"
7318
+ # last="1"
7319
+ # negative="1"
7320
+ # displayXAxis="1"
7321
+ # displayHidden="1"
7322
+ # minAxisType="custom"
7323
+ # maxAxisType="custom"
7324
+ # rightToLeft="1">
7325
+ #
7326
+ def write_sparkline_group(opts) # :nodoc:
7327
+ empty = opts[:_empty]
7328
+ user_max = 0
7329
+ user_min = 0
7330
+ a = []
7331
+
7332
+ if opts[:_max]
7333
+ if opts[:_max] == 'group'
7334
+ opts[:_cust_max] = 'group'
7335
+ else
7336
+ a << 'manualMax' << opts[:_max]
7337
+ opts[:_cust_max] = 'custom'
7338
+ end
7339
+ end
7340
+
7341
+ if opts[:_min]
7342
+ if opts[:_min] == 'group'
7343
+ opts[:_cust_min] = 'group'
7344
+ else
7345
+ a << 'manualMin' << opts[:_min]
7346
+ opts[:_cust_min] = 'custom'
7347
+ end
7348
+ end
7349
+
7350
+ # Ignore the default type attribute (line).
7351
+ a << 'type' << opts[:_type] if opts[:_type] != 'line'
7352
+
7353
+ a << 'lineWeight' << opts[:_weight] if opts[:_weight]
7354
+ a << 'dateAxis' << 1 if opts[:_date_axis]
7355
+ a << 'displayEmptyCellsAs' << empty if ptrue?(empty)
7356
+
7357
+ a << 'markers' << 1 if opts[:_markers]
7358
+ a << 'high' << 1 if opts[:_high]
7359
+ a << 'low' << 1 if opts[:_low]
7360
+ a << 'first' << 1 if opts[:_first]
7361
+ a << 'last' << 1 if opts[:_last]
7362
+ a << 'negative' << 1 if opts[:_negative]
7363
+ a << 'displayXAxis' << 1 if opts[:_axis]
7364
+ a << 'displayHidden' << 1 if opts[:_hidden]
7365
+ a << 'minAxisType' << opts[:_cust_min] if opts[:_cust_min]
7366
+ a << 'maxAxisType' << opts[:_cust_max] if opts[:_cust_max]
7367
+ a << 'rightToLeft' << 1 if opts[:_reverse]
7368
+
7369
+ @writer.start_tag('x14:sparklineGroup', a)
7370
+ end
7371
+
7372
+ #
7373
+ # Helper function for the sparkline color functions below.
7374
+ #
7375
+ def write_spark_color(element, color) # :nodoc:
7376
+ attr = []
7377
+
7378
+ attr << 'rgb' << color[:_rgb] if color[:_rgb]
7379
+ attr << 'theme' << color[:_theme] if color[:_theme]
7380
+ attr << 'tint' << color[:_tint] if color[:_tint]
7381
+
7382
+ @writer.empty_tag(element, attr)
7383
+ end
7384
+
7385
+ #
7386
+ # Write the <x14:colorSeries> element.
7387
+ #
7388
+ def write_color_series(param) # :nodoc:
7389
+ write_spark_color('x14:colorSeries', param)
7390
+ end
7391
+
7392
+ #
7393
+ # Write the <x14:colorNegative> element.
7394
+ #
7395
+ def write_color_negative(param) # :nodoc:
7396
+ write_spark_color('x14:colorNegative', param)
7397
+ end
7398
+
7399
+ #
7400
+ # Write the <x14:colorAxis> element.
7401
+ #
7402
+ def write_color_axis # :nodoc:
7403
+ write_spark_color('x14:colorAxis', { :_rgb => 'FF000000'} )
7404
+ end
7405
+
7406
+ #
7407
+ # Write the <x14:colorMarkers> element.
7408
+ #
7409
+ def write_color_markers(param) # :nodoc:
7410
+ write_spark_color('x14:colorMarkers', param)
7411
+ end
7412
+
7413
+ #
7414
+ # Write the <x14:colorFirst> element.
7415
+ #
7416
+ def write_color_first(param) # :nodoc:
7417
+ write_spark_color('x14:colorFirst', param)
7418
+ end
7419
+
7420
+ #
7421
+ # Write the <x14:colorLast> element.
7422
+ #
7423
+ def write_color_last(param) # :nodoc:
7424
+ write_spark_color('x14:colorLast', param)
7425
+ end
7426
+
7427
+ #
7428
+ # Write the <x14:colorHigh> element.
7429
+ #
7430
+ def write_color_high(param) # :nodoc:
7431
+ write_spark_color('x14:colorHigh', param)
7432
+ end
7433
+
7434
+ #
7435
+ # Write the <x14:colorLow> element.
7436
+ #
7437
+ def write_color_low(param) # :nodoc:
7438
+ write_spark_color('x14:colorLow', param)
7439
+ end
7440
+
6729
7441
  #
6730
7442
  # Write the <dataValidations> element.
6731
7443
  #