write_xlsx 0.90.0 → 0.97.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.
- checksums.yaml +4 -4
- data/Changes +37 -0
- data/README.md +1 -1
- data/examples/a_simple.rb +1 -6
- data/examples/conditional_format.rb +73 -46
- data/examples/demo.rb +1 -7
- data/examples/hyperlink1.rb +4 -11
- data/lib/write_xlsx/chart.rb +81 -205
- data/lib/write_xlsx/chart/axis.rb +2 -2
- data/lib/write_xlsx/chart/caption.rb +3 -1
- data/lib/write_xlsx/chart/pie.rb +2 -0
- data/lib/write_xlsx/chart/series.rb +11 -7
- data/lib/write_xlsx/format.rb +15 -11
- data/lib/write_xlsx/package/conditional_format.rb +351 -38
- data/lib/write_xlsx/package/content_types.rb +10 -0
- data/lib/write_xlsx/package/custom.rb +125 -0
- data/lib/write_xlsx/package/packager.rb +26 -0
- data/lib/write_xlsx/package/styles.rb +53 -21
- data/lib/write_xlsx/package/table.rb +11 -4
- data/lib/write_xlsx/utility.rb +234 -34
- data/lib/write_xlsx/version.rb +1 -1
- data/lib/write_xlsx/workbook.rb +88 -1
- data/lib/write_xlsx/worksheet.rb +247 -23
- data/test/helper.rb +6 -1
- data/test/regression/_test_hyperlink31.rb +26 -0
- data/test/regression/images/zero_dpi.jpg +0 -0
- data/test/regression/test_chart_bar08.rb +3 -0
- data/test/regression/test_chart_bar11.rb +3 -0
- data/test/regression/test_chart_bar14.rb +3 -0
- data/test/regression/test_chart_chartarea05.rb +16 -17
- data/test/regression/test_chart_chartarea06.rb +49 -0
- data/test/regression/test_chart_data_labels25.rb +61 -0
- data/test/regression/test_chart_format26.rb +48 -0
- data/test/regression/test_chart_format27.rb +58 -0
- data/test/regression/test_chart_format28.rb +52 -0
- data/test/regression/test_chart_format29.rb +59 -0
- data/test/regression/test_chart_format30.rb +53 -0
- data/test/regression/test_chart_format31.rb +60 -0
- data/test/regression/test_chart_table03.rb +56 -0
- data/test/regression/test_cond_format14.rb +42 -0
- data/test/regression/test_cond_format15.rb +53 -0
- data/test/regression/test_cond_format16.rb +53 -0
- data/test/regression/test_cond_format17.rb +37 -0
- data/test/regression/test_cond_format18.rb +136 -0
- data/test/regression/test_date_1904_01.rb +1 -1
- data/test/regression/test_escapes04.rb +3 -0
- data/test/regression/test_escapes05.rb +3 -0
- data/test/regression/test_escapes07.rb +3 -0
- data/test/regression/test_escapes08.rb +3 -0
- data/test/regression/test_hyperlink01.rb +3 -0
- data/test/regression/test_hyperlink02.rb +3 -0
- data/test/regression/test_hyperlink03.rb +4 -0
- data/test/regression/test_hyperlink04.rb +3 -0
- data/test/regression/test_hyperlink05.rb +3 -0
- data/test/regression/test_hyperlink06.rb +3 -0
- data/test/regression/test_hyperlink07.rb +3 -0
- data/test/regression/test_hyperlink08.rb +3 -0
- data/test/regression/test_hyperlink09.rb +3 -0
- data/test/regression/test_hyperlink10.rb +3 -0
- data/test/regression/test_hyperlink11.rb +3 -0
- data/test/regression/test_hyperlink12.rb +3 -0
- data/test/regression/test_hyperlink13.rb +3 -0
- data/test/regression/test_hyperlink14.rb +3 -0
- data/test/regression/test_hyperlink15.rb +3 -0
- data/test/regression/test_hyperlink16.rb +3 -0
- data/test/regression/test_hyperlink17.rb +3 -0
- data/test/regression/test_hyperlink18.rb +3 -0
- data/test/regression/test_hyperlink20.rb +3 -0
- data/test/regression/test_hyperlink21.rb +3 -0
- data/test/regression/test_hyperlink22.rb +3 -0
- data/test/regression/test_hyperlink23.rb +3 -0
- data/test/regression/test_hyperlink24.rb +3 -0
- data/test/regression/test_hyperlink25.rb +3 -0
- data/test/regression/test_hyperlink26.rb +3 -0
- data/test/regression/test_hyperlink27.rb +3 -0
- data/test/regression/test_hyperlink28.rb +50 -0
- data/test/regression/test_hyperlink29.rb +27 -0
- data/test/regression/test_hyperlink30.rb +36 -0
- data/test/regression/test_image35.rb +26 -0
- data/test/regression/test_properties01.rb +1 -4
- data/test/regression/test_properties02.rb +1 -4
- data/test/regression/test_properties03.rb +26 -0
- data/test/regression/test_properties04.rb +61 -0
- data/test/regression/test_properties05.rb +30 -0
- data/test/regression/test_table03.rb +3 -0
- data/test/regression/test_table04.rb +3 -0
- data/test/regression/test_table05.rb +3 -0
- data/test/regression/test_table06.rb +3 -0
- data/test/regression/test_table20.rb +34 -0
- data/test/regression/test_table21.rb +36 -0
- data/test/regression/test_table22.rb +32 -0
- data/test/regression/xlsx_files/chart_chartarea05.xlsx +0 -0
- data/test/regression/xlsx_files/chart_chartarea06.xlsx +0 -0
- data/test/regression/xlsx_files/chart_data_labels25.xlsx +0 -0
- data/test/regression/xlsx_files/chart_format26.xlsx +0 -0
- data/test/regression/xlsx_files/chart_format27.xlsx +0 -0
- data/test/regression/xlsx_files/chart_format28.xlsx +0 -0
- data/test/regression/xlsx_files/chart_format29.xlsx +0 -0
- data/test/regression/xlsx_files/chart_format30.xlsx +0 -0
- data/test/regression/xlsx_files/chart_format31.xlsx +0 -0
- data/test/regression/xlsx_files/chart_table03.xlsx +0 -0
- data/test/regression/xlsx_files/cond_format14.xlsx +0 -0
- data/test/regression/xlsx_files/cond_format15.xlsx +0 -0
- data/test/regression/xlsx_files/cond_format16.xlsx +0 -0
- data/test/regression/xlsx_files/cond_format17.xlsx +0 -0
- data/test/regression/xlsx_files/cond_format18.xlsx +0 -0
- data/test/regression/xlsx_files/date_1904_01.xlsx +0 -0
- data/test/regression/xlsx_files/hyperlink28.xlsx +0 -0
- data/test/regression/xlsx_files/hyperlink29.xlsx +0 -0
- data/test/regression/xlsx_files/hyperlink30.xlsx +0 -0
- data/test/regression/xlsx_files/hyperlink31.xlsx +0 -0
- data/test/regression/xlsx_files/image35.xlsx +0 -0
- data/test/regression/xlsx_files/properties03.xlsx +0 -0
- data/test/regression/xlsx_files/properties04.xlsx +0 -0
- data/test/regression/xlsx_files/properties05.xlsx +0 -0
- data/test/regression/xlsx_files/table21.xlsx +0 -0
- data/test/regression/xlsx_files/table22.xlsx +0 -0
- data/test/workbook/test_write_workbook_view.rb +81 -0
- data/test/worksheet/test_cond_format_22.rb +266 -0
- data/test/worksheet/test_cond_format_23.rb +242 -0
- data/test/worksheet/test_cond_format_24.rb +303 -0
- data/test/worksheet/test_data_bar_01.rb +53 -0
- data/test/worksheet/test_data_bar_02.rb +79 -0
- data/test/worksheet/test_data_bar_03.rb +147 -0
- data/test/worksheet/test_data_bar_04.rb +145 -0
- data/test/worksheet/test_data_bar_05.rb +147 -0
- data/test/worksheet/test_data_bar_06.rb +145 -0
- data/test/worksheet/test_data_bar_07.rb +146 -0
- data/test/worksheet/test_data_bar_08.rb +54 -0
- data/test/worksheet/test_data_bar_09.rb +80 -0
- data/test/worksheet/test_data_bar_10.rb +165 -0
- data/test/worksheet/test_data_bar_11.rb +167 -0
- data/test/worksheet/test_data_bar_12.rb +104 -0
- data/test/worksheet/test_write_data_validation_02.rb +27 -0
- metadata +135 -2
data/lib/write_xlsx/version.rb
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
WriteXLSX_VERSION = "0.
|
|
1
|
+
WriteXLSX_VERSION = "0.97.0"
|
data/lib/write_xlsx/workbook.rb
CHANGED
|
@@ -44,11 +44,14 @@ class Workbook
|
|
|
44
44
|
attr_reader :worksheets, :charts, :drawings # :nodoc:
|
|
45
45
|
attr_reader :named_ranges # :nodoc:
|
|
46
46
|
attr_reader :doc_properties # :nodoc:
|
|
47
|
+
attr_reader :custom_properties # :nodoc:
|
|
47
48
|
attr_reader :image_types, :images # :nodoc:
|
|
48
49
|
attr_reader :shared_strings # :nodoc:
|
|
49
50
|
attr_reader :vba_project # :nodoc:
|
|
50
51
|
attr_reader :excel2003_style # :nodoc:
|
|
51
52
|
attr_reader :strings_to_urls # :nodoc:
|
|
53
|
+
attr_reader :default_url_format # :nodoc:
|
|
54
|
+
|
|
52
55
|
#
|
|
53
56
|
# A new Excel workbook is created using the +new+ constructor
|
|
54
57
|
# which accepts either a filename or an IO object as a parameter.
|
|
@@ -114,7 +117,7 @@ def initialize(file, *option_params)
|
|
|
114
117
|
@named_ranges = []
|
|
115
118
|
@custom_colors = []
|
|
116
119
|
@doc_properties = {}
|
|
117
|
-
@
|
|
120
|
+
@custom_properties = []
|
|
118
121
|
@optimization = options[:optimization] || 0
|
|
119
122
|
@x_window = 240
|
|
120
123
|
@y_window = 15
|
|
@@ -141,6 +144,10 @@ def initialize(file, *option_params)
|
|
|
141
144
|
else
|
|
142
145
|
add_format(default_formats.merge(:xf_index => 0))
|
|
143
146
|
end
|
|
147
|
+
|
|
148
|
+
# Add a default URL format.
|
|
149
|
+
@default_url_format = add_format(:hyperlink => 1)
|
|
150
|
+
|
|
144
151
|
set_color_palette
|
|
145
152
|
end
|
|
146
153
|
|
|
@@ -758,6 +765,25 @@ def define_name(name, formula)
|
|
|
758
765
|
@defined_names.push([ name, sheet_index, formula.sub(/^=/, '') ])
|
|
759
766
|
end
|
|
760
767
|
|
|
768
|
+
#
|
|
769
|
+
# Set the workbook size.
|
|
770
|
+
#
|
|
771
|
+
def set_size(width = nil, height = nil)
|
|
772
|
+
if ptrue?(width)
|
|
773
|
+
# Convert to twips at 96 dpi.
|
|
774
|
+
@window_width = width.to_i * 1440 / 96
|
|
775
|
+
else
|
|
776
|
+
@window_width = 16095
|
|
777
|
+
end
|
|
778
|
+
|
|
779
|
+
if ptrue?(height)
|
|
780
|
+
# Convert to twips at 96 dpi.
|
|
781
|
+
@window_height = height.to_i * 1440 / 96
|
|
782
|
+
else
|
|
783
|
+
@window_height = 9660
|
|
784
|
+
end
|
|
785
|
+
end
|
|
786
|
+
|
|
761
787
|
#
|
|
762
788
|
# The set_properties method can be used to set the document properties
|
|
763
789
|
# of the Excel file created by WriteXLSX. These properties are visible
|
|
@@ -819,6 +845,53 @@ def set_properties(params)
|
|
|
819
845
|
@doc_properties = params.dup
|
|
820
846
|
end
|
|
821
847
|
|
|
848
|
+
#
|
|
849
|
+
# Set a user defined custom document property.
|
|
850
|
+
#
|
|
851
|
+
def set_custom_property(name, value, type = nil)
|
|
852
|
+
# Valid types.
|
|
853
|
+
valid_type = {
|
|
854
|
+
'text' => 1,
|
|
855
|
+
'date' => 1,
|
|
856
|
+
'number' => 1,
|
|
857
|
+
'number_int' => 1,
|
|
858
|
+
'bool' => 1,
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
if !name || (type != 'bool' && !value)
|
|
862
|
+
raise "The name and value parameters must be defined in set_custom_property()"
|
|
863
|
+
end
|
|
864
|
+
|
|
865
|
+
# Determine the type for strings and numbers if it hasn't been specified.
|
|
866
|
+
if !ptrue?(type)
|
|
867
|
+
if value =~ /^\d+$/
|
|
868
|
+
type = 'number_int'
|
|
869
|
+
elsif value =~
|
|
870
|
+
/^([+-]?)(?=[0-9]|\.[0-9])[0-9]*(\.[0-9]*)?([Ee]([+-]?[0-9]+))?$/
|
|
871
|
+
type = 'number'
|
|
872
|
+
else
|
|
873
|
+
type = 'text'
|
|
874
|
+
end
|
|
875
|
+
end
|
|
876
|
+
|
|
877
|
+
# Check for valid validation types.
|
|
878
|
+
if !valid_type[type]
|
|
879
|
+
raise "Unknown custom type '$type' in set_custom_property()"
|
|
880
|
+
end
|
|
881
|
+
|
|
882
|
+
# Check for strings longer than Excel's limit of 255 chars.
|
|
883
|
+
if type == 'text' && value.length > 255
|
|
884
|
+
raise "Length of text custom value '$value' exceeds Excel's limit of 255 in set_custom_property()"
|
|
885
|
+
end
|
|
886
|
+
|
|
887
|
+
if type == 'bool'
|
|
888
|
+
value = value ? 1 : 0
|
|
889
|
+
end
|
|
890
|
+
|
|
891
|
+
@custom_properties << [name, value, type]
|
|
892
|
+
end
|
|
893
|
+
|
|
894
|
+
|
|
822
895
|
#
|
|
823
896
|
# The add_vba_project method can be used to add macros or functions to an
|
|
824
897
|
# WriteXLSX file using a binary VBA project file that has been extracted
|
|
@@ -877,6 +950,16 @@ def set_calc_mode(mode, calc_id = nil)
|
|
|
877
950
|
@calc_id = calc_id if calc_id
|
|
878
951
|
end
|
|
879
952
|
|
|
953
|
+
#
|
|
954
|
+
# Get the default url format used when a user defined format isn't specified
|
|
955
|
+
# with write_url(). The format is the hyperlink style defined by Excel for the
|
|
956
|
+
# default theme.
|
|
957
|
+
#
|
|
958
|
+
def default_url_format
|
|
959
|
+
@default_url_format
|
|
960
|
+
end
|
|
961
|
+
alias get_default_url_format default_url_format
|
|
962
|
+
|
|
880
963
|
#
|
|
881
964
|
# Change the RGB components of the elements in the colour palette.
|
|
882
965
|
#
|
|
@@ -1922,6 +2005,10 @@ def get_image_properties(filename)
|
|
|
1922
2005
|
|
|
1923
2006
|
@images << [filename, type]
|
|
1924
2007
|
|
|
2008
|
+
# Set a default dpi for images with 0 dpi.
|
|
2009
|
+
x_dpi = 96 if x_dpi == 0
|
|
2010
|
+
y_dpi = 96 if y_dpi == 0
|
|
2011
|
+
|
|
1925
2012
|
[type, width, height, File.basename(filename), x_dpi, y_dpi]
|
|
1926
2013
|
end
|
|
1927
2014
|
|
data/lib/write_xlsx/worksheet.rb
CHANGED
|
@@ -294,7 +294,7 @@ class Worksheet
|
|
|
294
294
|
attr_reader :writer, :set_rows, :col_formats # :nodoc:
|
|
295
295
|
attr_reader :vml_shape_id # :nodoc:
|
|
296
296
|
attr_reader :comments, :comments_author # :nodoc:
|
|
297
|
-
attr_accessor :dxf_priority # :nodoc:
|
|
297
|
+
attr_accessor :data_bars_2010, :dxf_priority # :nodoc:
|
|
298
298
|
attr_reader :vba_codename # :nodoc:
|
|
299
299
|
attr_writer :excel_version
|
|
300
300
|
|
|
@@ -308,6 +308,7 @@ def initialize(workbook, index, name) #:nodoc:
|
|
|
308
308
|
@cell_data_table = {}
|
|
309
309
|
@excel_version = 2007
|
|
310
310
|
@palette = workbook.palette
|
|
311
|
+
@default_url_format = workbook.default_url_format
|
|
311
312
|
|
|
312
313
|
@page_setup = PageSetup.new
|
|
313
314
|
|
|
@@ -376,8 +377,9 @@ def initialize(workbook, index, name) #:nodoc:
|
|
|
376
377
|
|
|
377
378
|
@validations = []
|
|
378
379
|
|
|
379
|
-
@cond_formats
|
|
380
|
-
@
|
|
380
|
+
@cond_formats = {}
|
|
381
|
+
@data_bars_2010 = []
|
|
382
|
+
@dxf_priority = 1
|
|
381
383
|
|
|
382
384
|
if excel2003_style?
|
|
383
385
|
@original_row_height = 12.75
|
|
@@ -422,7 +424,7 @@ def assemble_xml_file #:nodoc:
|
|
|
422
424
|
write_legacy_drawing
|
|
423
425
|
write_legacy_drawing_hf
|
|
424
426
|
write_table_parts
|
|
425
|
-
|
|
427
|
+
write_ext_list
|
|
426
428
|
end
|
|
427
429
|
end
|
|
428
430
|
end
|
|
@@ -2781,6 +2783,9 @@ def write_url(*args)
|
|
|
2781
2783
|
raise "URL '#{url}' added but number of URLS is over Excel's limit of 65,530 URLS per worksheet."
|
|
2782
2784
|
end
|
|
2783
2785
|
|
|
2786
|
+
# Add the default URL format.
|
|
2787
|
+
xf = @default_url_format unless xf
|
|
2788
|
+
|
|
2784
2789
|
# Write the hyperlink string.
|
|
2785
2790
|
write_string(row, col, hyperlink.str, xf)
|
|
2786
2791
|
end
|
|
@@ -6037,6 +6042,26 @@ def set_vba_name(vba_codename = nil)
|
|
|
6037
6042
|
end
|
|
6038
6043
|
end
|
|
6039
6044
|
|
|
6045
|
+
def write_ext(url)
|
|
6046
|
+
attributes = [
|
|
6047
|
+
['xmlns:x14', "#{OFFICE_URL}spreadsheetml/2009/9/main"],
|
|
6048
|
+
['uri', url]
|
|
6049
|
+
]
|
|
6050
|
+
@writer.tag_elements('ext', attributes) do
|
|
6051
|
+
yield
|
|
6052
|
+
end
|
|
6053
|
+
end
|
|
6054
|
+
|
|
6055
|
+
def write_sparkline_groups
|
|
6056
|
+
# Write the x14:sparklineGroups element.
|
|
6057
|
+
@writer.tag_elements('x14:sparklineGroups', sparkline_groups_attributes) do
|
|
6058
|
+
# Write the sparkline elements.
|
|
6059
|
+
@sparklines.reverse.each do |sparkline|
|
|
6060
|
+
sparkline.write_sparkline_group(@writer)
|
|
6061
|
+
end
|
|
6062
|
+
end
|
|
6063
|
+
end
|
|
6064
|
+
|
|
6040
6065
|
private
|
|
6041
6066
|
|
|
6042
6067
|
def hyperlinks_count
|
|
@@ -6648,9 +6673,10 @@ def encode_password(password) #:nodoc:
|
|
|
6648
6673
|
def write_worksheet_attributes #:nodoc:
|
|
6649
6674
|
schema = 'http://schemas.openxmlformats.org/'
|
|
6650
6675
|
attributes = [
|
|
6651
|
-
|
|
6652
|
-
|
|
6653
|
-
|
|
6676
|
+
['xmlns', "#{schema}spreadsheetml/2006/main"],
|
|
6677
|
+
['xmlns:r', "#{schema}officeDocument/2006/relationships"]
|
|
6678
|
+
]
|
|
6679
|
+
|
|
6654
6680
|
if @excel_version == 2010
|
|
6655
6681
|
attributes << ['xmlns:mc', "#{schema}markup-compatibility/2006"]
|
|
6656
6682
|
attributes << ['xmlns:x14ac', "#{OFFICE_URL}spreadsheetml/2009/9/ac"]
|
|
@@ -7506,31 +7532,229 @@ def write_r_id(tag, id)
|
|
|
7506
7532
|
end
|
|
7507
7533
|
|
|
7508
7534
|
#
|
|
7509
|
-
# Write the <extLst> element and
|
|
7535
|
+
# Write the <extLst> element for data bars and sparklines.
|
|
7510
7536
|
#
|
|
7511
|
-
def
|
|
7512
|
-
@
|
|
7537
|
+
def write_ext_list # :nodoc:
|
|
7538
|
+
return if @data_bars_2010.empty? && @sparklines.empty?
|
|
7539
|
+
|
|
7540
|
+
@writer.tag_elements('extLst') do
|
|
7541
|
+
write_ext_list_data_bars if @data_bars_2010.size > 0
|
|
7542
|
+
write_ext_list_sparklines if @sparklines.size > 0
|
|
7543
|
+
end
|
|
7513
7544
|
end
|
|
7514
7545
|
|
|
7515
|
-
|
|
7516
|
-
|
|
7517
|
-
|
|
7546
|
+
#
|
|
7547
|
+
# Write the Excel 2010 data_bar subelements.
|
|
7548
|
+
#
|
|
7549
|
+
def write_ext_list_data_bars
|
|
7550
|
+
# Write the ext element.
|
|
7551
|
+
write_ext('{78C0D931-6437-407d-A8EE-F0AAD7539E65}') do
|
|
7552
|
+
|
|
7553
|
+
@writer.tag_elements('x14:conditionalFormattings') do
|
|
7554
|
+
# Write each of the Excel 2010 conditional formatting data bar elements.
|
|
7555
|
+
@data_bars_2010.each do |data_bar|
|
|
7556
|
+
# Write the x14:conditionalFormatting element.
|
|
7557
|
+
write_conditional_formatting_2010(data_bar)
|
|
7558
|
+
end
|
|
7559
|
+
end
|
|
7518
7560
|
end
|
|
7519
7561
|
end
|
|
7562
|
+
#
|
|
7563
|
+
# Write the <x14:conditionalFormatting> element.
|
|
7564
|
+
#
|
|
7565
|
+
def write_conditional_formatting_2010(data_bar)
|
|
7566
|
+
xmlns_xm = 'http://schemas.microsoft.com/office/excel/2006/main'
|
|
7520
7567
|
|
|
7521
|
-
|
|
7522
|
-
|
|
7523
|
-
|
|
7524
|
-
|
|
7568
|
+
attributes = [ ['xmlns:xm', xmlns_xm] ]
|
|
7569
|
+
|
|
7570
|
+
@writer.tag_elements('x14:conditionalFormatting', attributes) do
|
|
7571
|
+
|
|
7572
|
+
# Write the '<x14:cfRule element.
|
|
7573
|
+
write_x14_cf_rule(data_bar)
|
|
7574
|
+
|
|
7575
|
+
# Write the x14:dataBar element.
|
|
7576
|
+
write_x14_data_bar(data_bar)
|
|
7577
|
+
|
|
7578
|
+
# Write the x14 max and min data bars.
|
|
7579
|
+
write_x14_cfvo(data_bar[:x14_min_type], data_bar[:min_value])
|
|
7580
|
+
write_x14_cfvo(data_bar[:x14_max_type], data_bar[:max_value])
|
|
7581
|
+
|
|
7582
|
+
# Write the x14:borderColor element.
|
|
7583
|
+
if !ptrue?(data_bar[:bar_no_border])
|
|
7584
|
+
write_x14_border_color(data_bar[:bar_border_color])
|
|
7585
|
+
end
|
|
7586
|
+
|
|
7587
|
+
# Write the x14:negativeFillColor element.
|
|
7588
|
+
if !ptrue?(data_bar[:bar_negative_color_same])
|
|
7589
|
+
write_x14_negative_fill_color(data_bar[:bar_negative_color])
|
|
7590
|
+
end
|
|
7591
|
+
|
|
7592
|
+
# Write the x14:negativeBorderColor element.
|
|
7593
|
+
if !ptrue?(data_bar[:bar_no_border]) &&
|
|
7594
|
+
!ptrue?(data_bar[:bar_negative_border_color_same])
|
|
7595
|
+
write_x14_negative_border_color(
|
|
7596
|
+
data_bar[:bar_negative_border_color])
|
|
7597
|
+
end
|
|
7598
|
+
|
|
7599
|
+
# Write the x14:axisColor element.
|
|
7600
|
+
if data_bar[:bar_axis_position] != 'none'
|
|
7601
|
+
write_x14_axis_color(data_bar[:bar_axis_color])
|
|
7602
|
+
end
|
|
7603
|
+
|
|
7604
|
+
# Write closing elements.
|
|
7605
|
+
@writer.end_tag('x14:dataBar')
|
|
7606
|
+
@writer.end_tag('x14:cfRule')
|
|
7607
|
+
|
|
7608
|
+
# Add the conditional format range.
|
|
7609
|
+
@writer.data_element('xm:sqref', data_bar[:range])
|
|
7610
|
+
end
|
|
7611
|
+
end
|
|
7612
|
+
|
|
7613
|
+
#
|
|
7614
|
+
# Write the <cfvo> element.
|
|
7615
|
+
#
|
|
7616
|
+
def write_x14_cfvo(type, value)
|
|
7617
|
+
attributes = [ ['type', type ] ]
|
|
7618
|
+
|
|
7619
|
+
if %w(min max autoMin autoMax).include?(type)
|
|
7620
|
+
@writer.empty_tag('x14:cfvo', attributes)
|
|
7621
|
+
else
|
|
7622
|
+
@writer.tag_elements('x14:cfvo', attributes) do
|
|
7623
|
+
@writer.data_element('xm:f', value)
|
|
7624
|
+
end
|
|
7625
|
+
end
|
|
7626
|
+
end
|
|
7627
|
+
|
|
7628
|
+
#
|
|
7629
|
+
# Write the <'<x14:cfRule> element.
|
|
7630
|
+
#
|
|
7631
|
+
def write_x14_cf_rule(data_bar)
|
|
7632
|
+
type = 'dataBar'
|
|
7633
|
+
id = data_bar[:guid]
|
|
7634
|
+
|
|
7635
|
+
attributes = [
|
|
7636
|
+
['type', type],
|
|
7637
|
+
['id', id]
|
|
7638
|
+
]
|
|
7639
|
+
|
|
7640
|
+
@writer.start_tag('x14:cfRule', attributes)
|
|
7641
|
+
|
|
7642
|
+
end
|
|
7643
|
+
|
|
7644
|
+
#
|
|
7645
|
+
# Write the <x14:dataBar> element.
|
|
7646
|
+
#
|
|
7647
|
+
def write_x14_data_bar(data_bar)
|
|
7648
|
+
min_length = 0
|
|
7649
|
+
max_length = 100
|
|
7650
|
+
|
|
7651
|
+
attributes = [
|
|
7652
|
+
['minLength', min_length],
|
|
7653
|
+
['maxLength', max_length]
|
|
7525
7654
|
]
|
|
7655
|
+
|
|
7656
|
+
attributes << ['border', 1] if !ptrue?(data_bar[:bar_no_border])
|
|
7657
|
+
attributes << ['gradient', 0] if ptrue?(data_bar[:bar_solid])
|
|
7658
|
+
|
|
7659
|
+
if data_bar[:bar_direction] == 'left'
|
|
7660
|
+
attributes << ['direction', 'leftToRight']
|
|
7661
|
+
end
|
|
7662
|
+
if data_bar[:bar_direction] == 'right'
|
|
7663
|
+
attributes << ['direction', 'rightToLeft']
|
|
7664
|
+
end
|
|
7665
|
+
|
|
7666
|
+
if ptrue?(data_bar[:bar_negative_color_same])
|
|
7667
|
+
attributes << ['negativeBarColorSameAsPositive', 1]
|
|
7668
|
+
end
|
|
7669
|
+
|
|
7670
|
+
if !ptrue?(data_bar[:bar_no_border]) &&
|
|
7671
|
+
!ptrue?(data_bar[:bar_negative_border_color_same])
|
|
7672
|
+
attributes << ['negativeBarBorderColorSameAsPositive', 0]
|
|
7673
|
+
end
|
|
7674
|
+
|
|
7675
|
+
if data_bar[:bar_axis_position] == 'middle'
|
|
7676
|
+
attributes << ['axisPosition', 'middle']
|
|
7677
|
+
end
|
|
7678
|
+
|
|
7679
|
+
if data_bar[:bar_axis_position] == 'none'
|
|
7680
|
+
attributes << ['axisPosition', 'none']
|
|
7681
|
+
end
|
|
7682
|
+
|
|
7683
|
+
@writer.start_tag('x14:dataBar', attributes)
|
|
7526
7684
|
end
|
|
7527
7685
|
|
|
7528
|
-
|
|
7529
|
-
|
|
7530
|
-
|
|
7531
|
-
|
|
7532
|
-
|
|
7533
|
-
|
|
7686
|
+
#
|
|
7687
|
+
# Write the <x14:borderColor> element.
|
|
7688
|
+
#
|
|
7689
|
+
def write_x14_border_color(rgb)
|
|
7690
|
+
attributes = [ ['rgb', rgb] ]
|
|
7691
|
+
|
|
7692
|
+
@writer.empty_tag('x14:borderColor', attributes)
|
|
7693
|
+
end
|
|
7694
|
+
|
|
7695
|
+
#
|
|
7696
|
+
# Write the <x14:negativeFillColor> element.
|
|
7697
|
+
#
|
|
7698
|
+
def write_x14_negative_fill_color(rgb)
|
|
7699
|
+
attributes = [ ['rgb', rgb] ]
|
|
7700
|
+
|
|
7701
|
+
@writer.empty_tag('x14:negativeFillColor', attributes)
|
|
7702
|
+
end
|
|
7703
|
+
|
|
7704
|
+
#
|
|
7705
|
+
# Write the <x14:negativeBorderColor> element.
|
|
7706
|
+
#
|
|
7707
|
+
def write_x14_negative_border_color(rgb)
|
|
7708
|
+
attributes = [ ['rgb', rgb] ]
|
|
7709
|
+
|
|
7710
|
+
@writer.empty_tag('x14:negativeBorderColor', attributes)
|
|
7711
|
+
end
|
|
7712
|
+
|
|
7713
|
+
#
|
|
7714
|
+
# Write the <x14:axisColor> element.
|
|
7715
|
+
#
|
|
7716
|
+
def write_x14_axis_color(rgb)
|
|
7717
|
+
attributes = [ ['rgb', rgb] ]
|
|
7718
|
+
|
|
7719
|
+
@writer.empty_tag('x14:axisColor', attributes)
|
|
7720
|
+
end
|
|
7721
|
+
|
|
7722
|
+
#
|
|
7723
|
+
# Write the sparkline subelements.
|
|
7724
|
+
#
|
|
7725
|
+
def write_ext_list_sparklines
|
|
7726
|
+
# Write the ext element.
|
|
7727
|
+
write_ext('{05C60535-1F16-4fd2-B633-F4F36F0B64E0}') do
|
|
7728
|
+
|
|
7729
|
+
# Write the x14:sparklineGroups element.
|
|
7730
|
+
write_sparkline_groups
|
|
7731
|
+
|
|
7732
|
+
# # Write the sparkline elements.
|
|
7733
|
+
# @sparklines.reverse.each do |sparkline|
|
|
7734
|
+
# # Write the x14:sparklineGroup element.
|
|
7735
|
+
# # sparkline.write_sparkline_group(@writer)
|
|
7736
|
+
|
|
7737
|
+
# @writer.end_tag('x14:sparklineGroup')
|
|
7738
|
+
# end
|
|
7739
|
+
|
|
7740
|
+
# @writer.end_tag('x14:sparklineGroups')
|
|
7741
|
+
end
|
|
7742
|
+
end
|
|
7743
|
+
|
|
7744
|
+
#
|
|
7745
|
+
# Write the <x14:sparklines> element and <x14:sparkline> subelements.
|
|
7746
|
+
#
|
|
7747
|
+
def write_sparklines(sparkline)
|
|
7748
|
+
# Write the sparkline elements.
|
|
7749
|
+
@writer.tag_elements('x14:sparklines') do
|
|
7750
|
+
(0..sparkline[:count]-1).each do |i|
|
|
7751
|
+
range = sparkline[:ranges][i]
|
|
7752
|
+
location = sparkline[:locations][i]
|
|
7753
|
+
|
|
7754
|
+
@writer.tag_elements('x14:sparkline') do
|
|
7755
|
+
@writer.data_element('xm:f', range)
|
|
7756
|
+
@writer.data_element('xm:sqref', location)
|
|
7757
|
+
end
|
|
7534
7758
|
end
|
|
7535
7759
|
end
|
|
7536
7760
|
end
|