write_xlsx 0.60.0 → 0.61.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.
- data/README.rdoc +11 -1
- data/examples/hide_row_col.rb +33 -0
- data/html/en/doc_en.html +7765 -0
- data/html/index.html +16 -0
- data/html/style.css +433 -0
- data/lib/write_xlsx/chart.rb +20 -0
- data/lib/write_xlsx/package/button.rb +132 -0
- data/lib/write_xlsx/package/comments.rb +97 -1
- data/lib/write_xlsx/package/shared_strings.rb +2 -2
- data/lib/write_xlsx/package/vml.rb +9 -419
- data/lib/write_xlsx/utility.rb +138 -0
- data/lib/write_xlsx/version.rb +1 -1
- data/lib/write_xlsx/workbook.rb +2 -2
- data/lib/write_xlsx/worksheet.rb +178 -115
- data/test/drawing/test_write_row.rb +1 -1
- data/test/perl_output/hide_row_col.xlsx +0 -0
- data/test/perl_output/merge4.xlsx +0 -0
- data/test/perl_output/merge6.xlsx +0 -0
- data/test/regression/{test_vml04.rb → disabled_test_vml04.rb} +0 -0
- data/test/regression/test_chart_size01.rb +41 -0
- data/test/regression/test_chart_size02.rb +41 -0
- data/test/regression/test_chart_size03.rb +39 -0
- data/test/regression/test_default_row01.rb +26 -0
- data/test/regression/test_default_row02.rb +28 -0
- data/test/regression/test_default_row03.rb +28 -0
- data/test/regression/test_default_row04.rb +31 -0
- data/test/regression/xlsx_files/chart_size01.xlsx +0 -0
- data/test/regression/xlsx_files/default_row01.xlsx +0 -0
- data/test/regression/xlsx_files/default_row02.xlsx +0 -0
- data/test/regression/xlsx_files/default_row03.xlsx +0 -0
- data/test/regression/xlsx_files/default_row04.xlsx +0 -0
- data/test/test_example_match.rb +22 -0
- data/test/worksheet/test_write_methods.rb +0 -7
- metadata +35 -22
- data/test/package/vml/test_write_anchor.rb +0 -14
- data/test/package/vml/test_write_column.rb +0 -14
- data/test/package/vml/test_write_fill.rb +0 -22
- data/test/package/vml/test_write_move_with_cells.rb +0 -14
- data/test/package/vml/test_write_row.rb +0 -14
- data/test/package/vml/test_write_shadow.rb +0 -14
- data/test/package/vml/test_write_size_with_cells.rb +0 -14
- data/test/package/vml/test_write_textbox.rb +0 -14
- data/test/worksheet/test_write_hyperlinks.rb +0 -27
data/lib/write_xlsx/worksheet.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
require 'write_xlsx/package/xml_writer_simple'
|
3
|
+
require 'write_xlsx/package/button'
|
3
4
|
require 'write_xlsx/colors'
|
4
5
|
require 'write_xlsx/format'
|
5
6
|
require 'write_xlsx/drawing'
|
@@ -171,6 +172,10 @@ module Writexlsx
|
|
171
172
|
end
|
172
173
|
attributes
|
173
174
|
end
|
175
|
+
|
176
|
+
def display_url_string?
|
177
|
+
true
|
178
|
+
end
|
174
179
|
end
|
175
180
|
|
176
181
|
class NumberCellData < CellData # :nodoc:
|
@@ -207,6 +212,10 @@ module Writexlsx
|
|
207
212
|
@worksheet.write_cell_value(token)
|
208
213
|
end
|
209
214
|
end
|
215
|
+
|
216
|
+
def display_url_string?
|
217
|
+
false
|
218
|
+
end
|
210
219
|
end
|
211
220
|
|
212
221
|
class FormulaCellData < CellData # :nodoc:
|
@@ -249,41 +258,6 @@ module Writexlsx
|
|
249
258
|
end
|
250
259
|
end
|
251
260
|
|
252
|
-
class HyperlinkCellData < CellData # :nodoc:
|
253
|
-
def initialize(worksheet, row, col, index, xf, link_type, url, str, tip)
|
254
|
-
@worksheet = worksheet
|
255
|
-
@row, @col, @token, @xf, @link_type, @url, @str, @tip =
|
256
|
-
row, col, index, xf, link_type, url, str, tip
|
257
|
-
end
|
258
|
-
|
259
|
-
def data
|
260
|
-
{ :sst_id => token }
|
261
|
-
end
|
262
|
-
|
263
|
-
def write_cell
|
264
|
-
attributes = cell_attributes
|
265
|
-
attributes << 't' << 's'
|
266
|
-
@worksheet.writer.tag_elements('c', attributes) do
|
267
|
-
@worksheet.write_cell_value(token)
|
268
|
-
end
|
269
|
-
|
270
|
-
if link_type == 1
|
271
|
-
# External link with rel file relationship.
|
272
|
-
@worksheet.rel_count += 1
|
273
|
-
@worksheet.hlink_refs <<
|
274
|
-
[
|
275
|
-
link_type, row, col,
|
276
|
-
@worksheet.rel_count, @str, @tip
|
277
|
-
]
|
278
|
-
|
279
|
-
@worksheet.external_hyper_links << [ '/hyperlink', @url, 'External' ]
|
280
|
-
elsif link_type
|
281
|
-
# External link with rel file relationship.
|
282
|
-
@worksheet.hlink_refs << [link_type, row, col, @url, @str, @tip ]
|
283
|
-
end
|
284
|
-
end
|
285
|
-
end
|
286
|
-
|
287
261
|
class BlankCellData < CellData # :nodoc:
|
288
262
|
def initialize(worksheet, row, col, index, xf)
|
289
263
|
@worksheet = worksheet
|
@@ -420,6 +394,9 @@ module Writexlsx
|
|
420
394
|
@outline_row_level = 0
|
421
395
|
@outline_col_level = 0
|
422
396
|
|
397
|
+
@default_row_height = 15
|
398
|
+
@default_row_rezoed = 0
|
399
|
+
|
423
400
|
@merge = []
|
424
401
|
|
425
402
|
@has_vml = false
|
@@ -2642,8 +2619,8 @@ module Writexlsx
|
|
2642
2619
|
check_dimensions(row, col)
|
2643
2620
|
store_row_col_max_min_values(row, col)
|
2644
2621
|
|
2645
|
-
#
|
2646
|
-
|
2622
|
+
# Copy string for use in hyperlink elements.
|
2623
|
+
url_str = str.dup
|
2647
2624
|
|
2648
2625
|
# External links to URLs and to other Excel workbooks have slightly
|
2649
2626
|
# different characteristics that we have to account for.
|
@@ -2665,13 +2642,13 @@ module Writexlsx
|
|
2665
2642
|
end
|
2666
2643
|
|
2667
2644
|
# Ordinary URL style external links don't have a "location" string.
|
2668
|
-
|
2645
|
+
url_str = nil
|
2669
2646
|
elsif link_type == 3
|
2670
2647
|
# External Workbook links need to be modified into the right format.
|
2671
2648
|
# The URL will look something like 'c:\temp\file.xlsx#Sheet!A1'.
|
2672
2649
|
# We need the part to the left of the # as the URL and the part to
|
2673
2650
|
# the right as the "location" string (if it exists).
|
2674
|
-
url,
|
2651
|
+
url, url_str = url.split(/#/)
|
2675
2652
|
|
2676
2653
|
# Add the file:/// URI to the url if non-local.
|
2677
2654
|
if url =~ %r![:]! || # Windows style "C:/" link.
|
@@ -2698,7 +2675,18 @@ module Writexlsx
|
|
2698
2675
|
raise "URL '#{url}' added but number of URLS is over Excel's limit of 65,530 URLS per worksheet."
|
2699
2676
|
end
|
2700
2677
|
|
2701
|
-
|
2678
|
+
# Write the hyperlink string.
|
2679
|
+
write_string(row, col, str, xf)
|
2680
|
+
|
2681
|
+
# Store the hyperlink data in a separate structure.
|
2682
|
+
@hyperlinks ||= {}
|
2683
|
+
@hyperlinks[row] ||= {}
|
2684
|
+
@hyperlinks[row][col] = {
|
2685
|
+
:_link_type => link_type,
|
2686
|
+
:_url => url,
|
2687
|
+
:_str => url_str,
|
2688
|
+
:_tip => tip
|
2689
|
+
}
|
2702
2690
|
end
|
2703
2691
|
|
2704
2692
|
#
|
@@ -2765,7 +2753,7 @@ module Writexlsx
|
|
2765
2753
|
|
2766
2754
|
#
|
2767
2755
|
# :call-seq:
|
2768
|
-
# insert_chart(row, column, chart [ , x, y,
|
2756
|
+
# insert_chart(row, column, chart [ , x, y, x_scale, y_scale ] )
|
2769
2757
|
#
|
2770
2758
|
# Insert a chart into a worksheet. The chart argument should be a Chart
|
2771
2759
|
# object or else it is assumed to be a filename of an external binary file.
|
@@ -2787,7 +2775,7 @@ module Writexlsx
|
|
2787
2775
|
# Writexlsx::Chart for details on how to configure it. See also the
|
2788
2776
|
# chart_*.rb programs in the examples directory of the distro.
|
2789
2777
|
#
|
2790
|
-
# The x, y,
|
2778
|
+
# The x, y, x_scale and y_scale parameters are optional.
|
2791
2779
|
#
|
2792
2780
|
# The parameters x and y can be used to specify an offset from the top
|
2793
2781
|
# left hand corner of the cell specified by row and column. The offset
|
@@ -2795,7 +2783,7 @@ module Writexlsx
|
|
2795
2783
|
#
|
2796
2784
|
# worksheet1.insert_chart('E2', chart, 3, 3)
|
2797
2785
|
#
|
2798
|
-
# The parameters
|
2786
|
+
# The parameters x_scale and y_scale can be used to scale the inserted
|
2799
2787
|
# image horizontally and vertically:
|
2800
2788
|
#
|
2801
2789
|
# # Scale the width by 120% and the height by 150%
|
@@ -2803,29 +2791,35 @@ module Writexlsx
|
|
2803
2791
|
#
|
2804
2792
|
def insert_chart(*args)
|
2805
2793
|
# Check for a cell reference in A1 notation and substitute row and column.
|
2806
|
-
row, col, chart, x_offset, y_offset,
|
2794
|
+
row, col, chart, x_offset, y_offset, x_scale, y_scale = row_col_notation(args)
|
2807
2795
|
raise WriteXLSXInsufficientArgumentError if [row, col, chart].include?(nil)
|
2808
2796
|
|
2809
2797
|
x_offset ||= 0
|
2810
2798
|
y_offset ||= 0
|
2811
|
-
|
2812
|
-
|
2799
|
+
x_scale ||= 1
|
2800
|
+
y_scale ||= 1
|
2813
2801
|
|
2814
2802
|
raise "Not a Chart object in insert_chart()" unless chart.is_a?(Chart) || chart.is_a?(Chartsheet)
|
2815
2803
|
raise "Not a embedded style Chart object in insert_chart()" if chart.respond_to?(:embedded) && chart.embedded == 0
|
2816
2804
|
|
2817
|
-
|
2805
|
+
# Use the values set with chart.size, if any.
|
2806
|
+
x_scale = chart.x_scale if chart.x_scale != 1
|
2807
|
+
y_scale = chart.y_scale if chart.y_scale != 1
|
2808
|
+
x_offset = chart.x_offset if ptrue?(chart.x_offset)
|
2809
|
+
y_offset = chart.y_offset if ptrue?(chart.y_offset)
|
2810
|
+
|
2811
|
+
@charts << [row, col, chart, x_offset, y_offset, x_scale, y_scale]
|
2818
2812
|
end
|
2819
2813
|
|
2820
2814
|
#
|
2821
2815
|
# :call-seq:
|
2822
|
-
# insert_image(row, column, filename [ , x, y,
|
2816
|
+
# insert_image(row, column, filename [ , x, y, x_scale, y_scale ] )
|
2823
2817
|
#
|
2824
2818
|
# Partially supported. Currently only works for 96 dpi images. This
|
2825
2819
|
# will be fixed in an upcoming release.
|
2826
2820
|
#--
|
2827
2821
|
# This method can be used to insert a image into a worksheet. The image
|
2828
|
-
# can be in PNG, JPEG or BMP format. The x, y,
|
2822
|
+
# can be in PNG, JPEG or BMP format. The x, y, x_scale and y_scale
|
2829
2823
|
# parameters are optional.
|
2830
2824
|
#
|
2831
2825
|
# worksheet1.insert_image('A1', 'ruby.bmp')
|
@@ -2842,7 +2836,7 @@ module Writexlsx
|
|
2842
2836
|
# cell. This can be occasionally useful if you wish to align two or more
|
2843
2837
|
# images relative to the same cell.
|
2844
2838
|
#
|
2845
|
-
# The parameters
|
2839
|
+
# The parameters x_scale and y_scale can be used to scale the inserted
|
2846
2840
|
# image horizontally and vertically:
|
2847
2841
|
#
|
2848
2842
|
# # Scale the inserted image: width x 2.0, height x 0.8
|
@@ -2864,15 +2858,15 @@ module Writexlsx
|
|
2864
2858
|
#
|
2865
2859
|
def insert_image(*args)
|
2866
2860
|
# Check for a cell reference in A1 notation and substitute row and column.
|
2867
|
-
row, col, image, x_offset, y_offset,
|
2861
|
+
row, col, image, x_offset, y_offset, x_scale, y_scale = row_col_notation(args)
|
2868
2862
|
raise WriteXLSXInsufficientArgumentError if [row, col, image].include?(nil)
|
2869
2863
|
|
2870
2864
|
x_offset ||= 0
|
2871
2865
|
y_offset ||= 0
|
2872
|
-
|
2873
|
-
|
2866
|
+
x_scale ||= 1
|
2867
|
+
y_scale ||= 1
|
2874
2868
|
|
2875
|
-
@images << [row, col, image, x_offset, y_offset,
|
2869
|
+
@images << [row, col, image, x_offset, y_offset, x_scale, y_scale]
|
2876
2870
|
end
|
2877
2871
|
|
2878
2872
|
#
|
@@ -2985,7 +2979,7 @@ module Writexlsx
|
|
2985
2979
|
#
|
2986
2980
|
def set_row(*args)
|
2987
2981
|
row = args[0]
|
2988
|
-
height = args[1] ||
|
2982
|
+
height = args[1] || @default_height
|
2989
2983
|
xf = args[2]
|
2990
2984
|
hidden = args[3] || 0
|
2991
2985
|
level = args[4] || 0
|
@@ -2993,6 +2987,9 @@ module Writexlsx
|
|
2993
2987
|
|
2994
2988
|
return if row.nil?
|
2995
2989
|
|
2990
|
+
# Get the default row height.
|
2991
|
+
default_height = @default_row_height
|
2992
|
+
|
2996
2993
|
# Use min col in check_dimensions. Default to 0 if undefined.
|
2997
2994
|
min_col = @dim_colmin || 0
|
2998
2995
|
|
@@ -3000,10 +2997,12 @@ module Writexlsx
|
|
3000
2997
|
check_dimensions(row, min_col)
|
3001
2998
|
store_row_col_max_min_values(row, min_col)
|
3002
2999
|
|
3000
|
+
height ||= default_height
|
3001
|
+
|
3003
3002
|
# If the height is 0 the row is hidden and the height is the default.
|
3004
3003
|
if height == 0
|
3005
3004
|
hidden = 1
|
3006
|
-
height =
|
3005
|
+
height = default_height
|
3007
3006
|
end
|
3008
3007
|
|
3009
3008
|
# Set the limits for the outline levels (0 <= x <= 7).
|
@@ -3022,6 +3021,25 @@ module Writexlsx
|
|
3022
3021
|
@row_sizes[row] = height
|
3023
3022
|
end
|
3024
3023
|
|
3024
|
+
#
|
3025
|
+
# Set the default row properties
|
3026
|
+
#
|
3027
|
+
def set_default_row(height = nil, zero_height = nil)
|
3028
|
+
height ||= 15
|
3029
|
+
zero_height ||= 0
|
3030
|
+
|
3031
|
+
if height != 15
|
3032
|
+
@default_row_height = height
|
3033
|
+
|
3034
|
+
# Store the row change to allow optimisations.
|
3035
|
+
@row_size_changed = 1
|
3036
|
+
end
|
3037
|
+
|
3038
|
+
if ptrue?(zero_height)
|
3039
|
+
@default_row_zeroed = 1
|
3040
|
+
end
|
3041
|
+
end
|
3042
|
+
|
3025
3043
|
#
|
3026
3044
|
# merge_range(first_row, first_col, last_row, last_col, string, format)
|
3027
3045
|
#
|
@@ -3822,7 +3840,7 @@ module Writexlsx
|
|
3822
3840
|
sparkline[:_ranges].collect! do |range|
|
3823
3841
|
# Remove the absolute reference $ symbols.
|
3824
3842
|
range = range.gsub(/\$/, '')
|
3825
|
-
# Convert a
|
3843
|
+
# Convert a simple range into a full Sheet1!A1:D1 range.
|
3826
3844
|
range = "#{sheetname}!#{range}" unless range =~ /!/
|
3827
3845
|
range
|
3828
3846
|
end
|
@@ -4767,24 +4785,6 @@ module Writexlsx
|
|
4767
4785
|
!!@is_chartsheet
|
4768
4786
|
end
|
4769
4787
|
|
4770
|
-
#
|
4771
|
-
# Turn the HoH that stores the comments into an array for easier handling
|
4772
|
-
# and set the external links.
|
4773
|
-
#
|
4774
|
-
def set_vml_data_id(vml_data_id) # :nodoc:
|
4775
|
-
count = @comments.sorted_comments.size
|
4776
|
-
start_data_id = vml_data_id
|
4777
|
-
|
4778
|
-
# The VML o:idmap data id contains a comma separated range when there is
|
4779
|
-
# more than one 1024 block of comments, like this: data="1,2".
|
4780
|
-
(1 .. (count / 1024)).each do |i|
|
4781
|
-
vml_data_id = "#{vml_data_id},#{start_data_id + i}"
|
4782
|
-
end
|
4783
|
-
@vml_data_id = vml_data_id
|
4784
|
-
|
4785
|
-
count
|
4786
|
-
end
|
4787
|
-
|
4788
4788
|
def set_external_vml_links(comment_id) # :nodoc:
|
4789
4789
|
@external_vml_links <<
|
4790
4790
|
['/vmlDrawing', "../drawings/vmlDrawing#{comment_id}.vml"]
|
@@ -4801,15 +4801,19 @@ module Writexlsx
|
|
4801
4801
|
def prepare_chart(index, chart_id, drawing_id) # :nodoc:
|
4802
4802
|
drawing_type = 1
|
4803
4803
|
|
4804
|
-
row, col, chart, x_offset, y_offset,
|
4804
|
+
row, col, chart, x_offset, y_offset, x_scale, y_scale = @charts[index]
|
4805
4805
|
chart.id = chart_id - 1
|
4806
|
-
|
4807
|
-
|
4806
|
+
x_scale ||= 0
|
4807
|
+
y_scale ||= 0
|
4808
4808
|
|
4809
|
-
|
4810
|
-
|
4809
|
+
# Use user specified dimensions, if any.
|
4810
|
+
width = chart.width if ptrue?(chart.width)
|
4811
|
+
height = chart.height if ptrue?(chart.height)
|
4811
4812
|
|
4812
|
-
|
4813
|
+
width = (0.5 + (width * x_scale)).to_i
|
4814
|
+
height = (0.5 + (height * y_scale)).to_i
|
4815
|
+
|
4816
|
+
dimensions = position_object_emus(col, row, x_offset, y_offset, width, height, false)
|
4813
4817
|
|
4814
4818
|
# Set the chart name for the embedded object if it has been specified.
|
4815
4819
|
name = chart.name
|
@@ -5409,8 +5413,7 @@ module Writexlsx
|
|
5409
5413
|
# The vertices are expressed as English Metric Units (EMUs). There are 12,700
|
5410
5414
|
# EMUs per point. Therefore, 12,700 * 3 /4 = 9,525 EMUs per pixel.
|
5411
5415
|
#
|
5412
|
-
def position_object_emus(col_start, row_start, x1, y1, width, height) #:nodoc:
|
5413
|
-
is_drawing = true
|
5416
|
+
def position_object_emus(col_start, row_start, x1, y1, width, height, is_drawing = true) #:nodoc:
|
5414
5417
|
col_start, row_start, x1, y1, col_end, row_end, x2, y2, x_abs, y_abs =
|
5415
5418
|
position_object_pixels(col_start, row_start, x1, y1, width, height, is_drawing)
|
5416
5419
|
|
@@ -5506,7 +5509,7 @@ module Writexlsx
|
|
5506
5509
|
pixels = (4 / 3.0 * height).to_i
|
5507
5510
|
end
|
5508
5511
|
else
|
5509
|
-
pixels =
|
5512
|
+
pixels = (4 / 3.0 * @default_row_height).to_i
|
5510
5513
|
end
|
5511
5514
|
pixels
|
5512
5515
|
end
|
@@ -5518,10 +5521,10 @@ module Writexlsx
|
|
5518
5521
|
drawing_type = 2
|
5519
5522
|
drawing
|
5520
5523
|
|
5521
|
-
row, col, image, x_offset, y_offset,
|
5524
|
+
row, col, image, x_offset, y_offset, x_scale, y_scale = @images[index]
|
5522
5525
|
|
5523
|
-
width *=
|
5524
|
-
height *=
|
5526
|
+
width *= x_scale
|
5527
|
+
height *= y_scale
|
5525
5528
|
|
5526
5529
|
dimensions = position_object_emus(col, row, x_offset, y_offset, width, height)
|
5527
5530
|
|
@@ -5565,7 +5568,7 @@ module Writexlsx
|
|
5565
5568
|
# See add_shape() for details on how to create the Shape object
|
5566
5569
|
# and Excel::Writer::XLSX::Shape for details on how to configure it.
|
5567
5570
|
#
|
5568
|
-
# The x, y,
|
5571
|
+
# The x, y, x_scale and y_scale parameters are optional.
|
5569
5572
|
#
|
5570
5573
|
# The parameters x and y can be used to specify an offset
|
5571
5574
|
# from the top left hand corner of the cell specified by row and col.
|
@@ -5573,7 +5576,7 @@ module Writexlsx
|
|
5573
5576
|
#
|
5574
5577
|
# worksheet1.insert_shape('E2', chart, 3, 3)
|
5575
5578
|
#
|
5576
|
-
# The parameters
|
5579
|
+
# The parameters x_scale and y_scale can be used to scale the
|
5577
5580
|
# inserted shape horizontally and vertically:
|
5578
5581
|
#
|
5579
5582
|
# # Scale the width by 120% and the height by 150%
|
@@ -5582,7 +5585,7 @@ module Writexlsx
|
|
5582
5585
|
#
|
5583
5586
|
def insert_shape(*args)
|
5584
5587
|
# Check for a cell reference in A1 notation and substitute row and column.
|
5585
|
-
row_start, column_start, shape, x_offset, y_offset,
|
5588
|
+
row_start, column_start, shape, x_offset, y_offset, x_scale, y_scale =
|
5586
5589
|
row_col_notation(args)
|
5587
5590
|
if [row_start, column_start, shape].include?(nil)
|
5588
5591
|
raise "Insufficient arguments in insert_shape()"
|
@@ -5596,8 +5599,8 @@ module Writexlsx
|
|
5596
5599
|
|
5597
5600
|
# Override shape scale if supplied as an argument. Otherwise, use the
|
5598
5601
|
# existing shape scale factors.
|
5599
|
-
shape[:scale_x] =
|
5600
|
-
shape[:scale_y] =
|
5602
|
+
shape[:scale_x] = x_scale if x_scale
|
5603
|
+
shape[:scale_y] = y_scale if y_scale
|
5601
5604
|
|
5602
5605
|
# Assign a shape ID.
|
5603
5606
|
while true
|
@@ -5779,20 +5782,20 @@ module Writexlsx
|
|
5779
5782
|
# calculating the comment object position and vertices.
|
5780
5783
|
#
|
5781
5784
|
def button_params(row, col, params)
|
5782
|
-
button =
|
5785
|
+
button = Writexlsx::Package::Button.new
|
5783
5786
|
|
5784
5787
|
button_number = 1 + @buttons_array.size
|
5785
5788
|
|
5786
5789
|
# Set the button caption.
|
5787
5790
|
caption = params[:caption] || "Button #{button_number}"
|
5788
5791
|
|
5789
|
-
button
|
5792
|
+
button.font = { :_caption => caption }
|
5790
5793
|
|
5791
5794
|
# Set the macro name.
|
5792
5795
|
if params[:macro]
|
5793
|
-
button
|
5796
|
+
button.macro = "[0]!#{params[:macro]}"
|
5794
5797
|
else
|
5795
|
-
button
|
5798
|
+
button.macro = "[0]!Button#{button_number}_Click"
|
5796
5799
|
end
|
5797
5800
|
|
5798
5801
|
# Ensure that a width and height have been set.
|
@@ -5833,7 +5836,7 @@ module Writexlsx
|
|
5833
5836
|
# Add the width and height for VML.
|
5834
5837
|
vertices << [params[:width], params[:height]]
|
5835
5838
|
|
5836
|
-
button
|
5839
|
+
button.vertices = vertices
|
5837
5840
|
|
5838
5841
|
button
|
5839
5842
|
end
|
@@ -6015,9 +6018,16 @@ module Writexlsx
|
|
6015
6018
|
#
|
6016
6019
|
def write_sheet_format_pr #:nodoc:
|
6017
6020
|
base_col_width = 10
|
6018
|
-
default_row_height = 15
|
6019
6021
|
|
6020
|
-
attributes = ['defaultRowHeight', default_row_height]
|
6022
|
+
attributes = ['defaultRowHeight', @default_row_height]
|
6023
|
+
if @default_row_height != 15
|
6024
|
+
attributes << 'customHeight' << 1
|
6025
|
+
end
|
6026
|
+
|
6027
|
+
if ptrue?(@default_row_zeroed)
|
6028
|
+
attributes << 'zeroHeight' << 1
|
6029
|
+
end
|
6030
|
+
|
6021
6031
|
attributes << 'outlineLevelRow' << @outline_row_level if @outline_row_level > 0
|
6022
6032
|
attributes << 'outlineLevelCol' << @outline_col_level if @outline_col_level > 0
|
6023
6033
|
if @excel_version == 2010
|
@@ -6120,7 +6130,7 @@ module Writexlsx
|
|
6120
6130
|
write_empty_row(row_num, span, *(@set_rows[row_num]))
|
6121
6131
|
else
|
6122
6132
|
# Row attributes only.
|
6123
|
-
write_empty_row(row_num,
|
6133
|
+
write_empty_row(row_num, span, *(@set_rows[row_num]))
|
6124
6134
|
end
|
6125
6135
|
end
|
6126
6136
|
end
|
@@ -6172,8 +6182,8 @@ module Writexlsx
|
|
6172
6182
|
#
|
6173
6183
|
# Write the <row> element.
|
6174
6184
|
#
|
6175
|
-
def write_row_element(r, spans = nil, height =
|
6176
|
-
height ||=
|
6185
|
+
def write_row_element(r, spans = nil, height = nil, format = nil, hidden = false, level = 0, collapsed = false, empty_row = false) #:nodoc:
|
6186
|
+
height ||= @default_row_height
|
6177
6187
|
hidden ||= 0
|
6178
6188
|
level ||= 0
|
6179
6189
|
collapsed ||= 0
|
@@ -6182,14 +6192,14 @@ module Writexlsx
|
|
6182
6192
|
|
6183
6193
|
attributes = ['r', r + 1]
|
6184
6194
|
|
6185
|
-
(attributes << 'spans' << spans)
|
6186
|
-
(attributes << 's' << xf_index) if xf_index
|
6187
|
-
(attributes << 'customFormat' << 1 )
|
6188
|
-
(attributes << 'ht' << height)
|
6189
|
-
(attributes << 'hidden' << 1 )
|
6190
|
-
(attributes << 'customHeight' << 1 )
|
6191
|
-
(attributes << 'outlineLevel' << level)
|
6192
|
-
(attributes << 'collapsed' << 1 )
|
6195
|
+
(attributes << 'spans' << spans) if spans
|
6196
|
+
(attributes << 's' << xf_index) if ptrue?(xf_index)
|
6197
|
+
(attributes << 'customFormat' << 1 ) if ptrue?(format)
|
6198
|
+
(attributes << 'ht' << height) if height != 15
|
6199
|
+
(attributes << 'hidden' << 1 ) if ptrue?(hidden)
|
6200
|
+
(attributes << 'customHeight' << 1 ) if height != 15
|
6201
|
+
(attributes << 'outlineLevel' << level) if ptrue?(level)
|
6202
|
+
(attributes << 'collapsed' << 1 ) if ptrue?(collapsed)
|
6193
6203
|
|
6194
6204
|
if @excel_version == 2010
|
6195
6205
|
attributes << 'x14ac:dyDescent' << '0.25'
|
@@ -6679,12 +6689,64 @@ module Writexlsx
|
|
6679
6689
|
end
|
6680
6690
|
|
6681
6691
|
#
|
6682
|
-
#
|
6683
|
-
# and external links.
|
6692
|
+
# Process any sored hyperlinks in row/col order and write the <hyperlinks>
|
6693
|
+
# element. The attributes are different for internal and external links.
|
6684
6694
|
#
|
6685
6695
|
def write_hyperlinks #:nodoc:
|
6696
|
+
return unless @hyperlinks
|
6697
|
+
|
6698
|
+
# Sort the hyperlinks into row order.
|
6699
|
+
row_nums = @hyperlinks.keys.sort
|
6700
|
+
|
6701
|
+
# Exit if there are no hyperlinks to process.
|
6702
|
+
return if row_nums.empty?
|
6703
|
+
|
6704
|
+
# Iterate over the rows.
|
6705
|
+
row_nums.each do |row_num|
|
6706
|
+
# Sort the hyperlinks into column order.
|
6707
|
+
col_nums = @hyperlinks[row_num].keys.sort
|
6708
|
+
# Iterate over the columns.
|
6709
|
+
col_nums.each do |col_num|
|
6710
|
+
# Get the link data for this cell.
|
6711
|
+
link = @hyperlinks[row_num][col_num]
|
6712
|
+
link_type = link[:_link_type]
|
6713
|
+
|
6714
|
+
# If the cell isn't a string then we have to add the url as
|
6715
|
+
# the string to display
|
6716
|
+
if ptrue?(@cell_data_table) &&
|
6717
|
+
ptrue?(@cell_data_table[row_num]) &&
|
6718
|
+
ptrue?(@cell_data_table[row_num][col_num])
|
6719
|
+
if @cell_data_table[row_num][col_num].display_url_string?
|
6720
|
+
display = link[:_url]
|
6721
|
+
else
|
6722
|
+
display = nil
|
6723
|
+
end
|
6724
|
+
end
|
6725
|
+
|
6726
|
+
if link_type == 1
|
6727
|
+
# External link with rel file relationship.
|
6728
|
+
@rel_count += 1
|
6729
|
+
@hlink_refs << [
|
6730
|
+
link_type, row_num, col_num,
|
6731
|
+
@rel_count, link[:_str], display, link[:_tip]
|
6732
|
+
]
|
6733
|
+
# Links for use by the packager.
|
6734
|
+
@external_hyper_links << [
|
6735
|
+
'/hyperlink', link[:_url], 'External'
|
6736
|
+
]
|
6737
|
+
else
|
6738
|
+
# Internal link with rel file relationship.
|
6739
|
+
@hlink_refs << [
|
6740
|
+
link_type, row_num, col_num,
|
6741
|
+
link[:_url], link[:_str], link[:_tip]
|
6742
|
+
]
|
6743
|
+
end
|
6744
|
+
end
|
6745
|
+
end
|
6746
|
+
|
6686
6747
|
return if @hlink_refs.empty?
|
6687
6748
|
|
6749
|
+
# Write the hyperlink elements.
|
6688
6750
|
@writer.tag_elements('hyperlinks') do
|
6689
6751
|
@hlink_refs.each do |aref|
|
6690
6752
|
type, *args = aref
|
@@ -6701,13 +6763,14 @@ module Writexlsx
|
|
6701
6763
|
#
|
6702
6764
|
# Write the <hyperlink> element for external links.
|
6703
6765
|
#
|
6704
|
-
def write_hyperlink_external(row, col, id, location = nil, tooltip = nil) #:nodoc:
|
6766
|
+
def write_hyperlink_external(row, col, id, location = nil, display = nil, tooltip = nil) #:nodoc:
|
6705
6767
|
ref = xl_rowcol_to_cell(row, col)
|
6706
6768
|
r_id = "rId#{id}"
|
6707
6769
|
|
6708
6770
|
attributes = ['ref', ref, 'r:id', r_id]
|
6709
6771
|
|
6710
6772
|
attributes << 'location' << location if location
|
6773
|
+
attributes << 'display' << display if display
|
6711
6774
|
attributes << 'tooltip' << tooltip if tooltip
|
6712
6775
|
|
6713
6776
|
@writer.empty_tag('hyperlink', attributes)
|
@@ -7712,8 +7775,8 @@ module Writexlsx
|
|
7712
7775
|
# Add a string to the shared string table, if it isn't already there, and
|
7713
7776
|
# return the string index.
|
7714
7777
|
#
|
7715
|
-
def shared_string_index(str) #:nodoc:
|
7716
|
-
@workbook.shared_string_index(str)
|
7778
|
+
def shared_string_index(str, params = {}) #:nodoc:
|
7779
|
+
@workbook.shared_string_index(str, params)
|
7717
7780
|
end
|
7718
7781
|
|
7719
7782
|
#
|
Binary file
|
Binary file
|
Binary file
|
File without changes
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'helper'
|
3
|
+
|
4
|
+
class TestRegressionChartSize01 < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
setup_dir_var
|
7
|
+
end
|
8
|
+
|
9
|
+
def teardown
|
10
|
+
File.delete(@xlsx) if File.exist?(@xlsx)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_chart_size01
|
14
|
+
@xlsx = 'chart_size01.xlsx'
|
15
|
+
workbook = WriteXLSX.new(@xlsx)
|
16
|
+
worksheet = workbook.add_worksheet
|
17
|
+
chart = workbook.add_chart(:type => 'column', :embedded => 1)
|
18
|
+
|
19
|
+
# For testing, copy the randomly generated axis ids in the target xlsx file.
|
20
|
+
chart.instance_variable_set(:@axis_ids, [61355904, 61365248])
|
21
|
+
|
22
|
+
data = [
|
23
|
+
[1, 2, 3, 4, 5],
|
24
|
+
[2, 4, 6, 8, 10],
|
25
|
+
[3, 6, 9, 12, 15]
|
26
|
+
]
|
27
|
+
|
28
|
+
worksheet.write('A1', data)
|
29
|
+
|
30
|
+
chart.add_series(:values => '=Sheet1!$A$1:$A$5')
|
31
|
+
chart.add_series(:values => '=Sheet1!$B$1:$B$5')
|
32
|
+
chart.add_series(:values => '=Sheet1!$C$1:$C$5')
|
33
|
+
|
34
|
+
chart.size(:width => 512, :height => 320)
|
35
|
+
|
36
|
+
worksheet.insert_chart('E9', chart)
|
37
|
+
|
38
|
+
workbook.close
|
39
|
+
compare_xlsx_for_regression(File.join(@regression_output, @xlsx), @xlsx)
|
40
|
+
end
|
41
|
+
end
|