write_xlsx 0.97.0 → 1.04.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Changes +78 -0
- data/LICENSE.txt +1 -1
- data/README.md +2 -2
- data/examples/a_simple.rb +1 -1
- data/examples/add_vba_project.rb +1 -1
- data/examples/array_formula.rb +1 -1
- data/examples/chart_area.rb +5 -2
- data/examples/chart_bar.rb +5 -2
- data/examples/chart_clustered.rb +1 -1
- data/examples/chart_column.rb +5 -2
- data/examples/chart_combined.rb +1 -1
- data/examples/chart_data_table.rb +9 -3
- data/examples/chart_data_tools.rb +25 -7
- data/examples/chart_doughnut.rb +17 -5
- data/examples/chart_gauge.rb +73 -0
- data/examples/chart_line.rb +90 -12
- data/examples/chart_pareto.rb +1 -1
- data/examples/chart_pie.rb +9 -3
- data/examples/chart_radar.rb +13 -4
- data/examples/chart_scatter.rb +5 -2
- data/examples/chart_secondary_axis.rb +5 -2
- data/examples/chart_stock.rb +1 -1
- data/examples/chart_styles.rb +1 -1
- data/examples/colors.rb +1 -1
- data/examples/data_validate.rb +1 -1
- data/examples/date_time.rb +1 -1
- data/examples/demo.rb +4 -1
- data/examples/formats.rb +1 -1
- data/examples/headers.rb +1 -1
- data/examples/hide_row_col.rb +1 -1
- data/examples/hide_sheet.rb +1 -1
- data/examples/hyperlink1.rb +1 -1
- data/examples/indent.rb +1 -1
- data/examples/macros.rb +1 -1
- data/examples/merge1.rb +1 -1
- data/examples/merge2.rb +1 -1
- data/examples/merge3.rb +1 -1
- data/examples/merge4.rb +1 -1
- data/examples/merge5.rb +1 -1
- data/examples/merge6.rb +1 -1
- data/examples/outline.rb +1 -1
- data/examples/outline_collapsed.rb +1 -1
- data/examples/panes.rb +1 -1
- data/examples/properties.rb +1 -1
- data/examples/regions.rb +1 -1
- data/examples/rich_strings.rb +1 -1
- data/examples/right_to_left.rb +1 -1
- data/examples/shape1.rb +1 -1
- data/examples/shape2.rb +1 -1
- data/examples/shape3.rb +1 -1
- data/examples/shape4.rb +1 -1
- data/examples/shape5.rb +1 -1
- data/examples/shape6.rb +1 -1
- data/examples/shape7.rb +1 -1
- data/examples/shape8.rb +1 -1
- data/examples/shape_all.rb +1 -1
- data/examples/sparklines1.rb +1 -1
- data/examples/sparklines2.rb +1 -1
- data/examples/stats.rb +1 -1
- data/examples/stats_ext.rb +1 -1
- data/examples/stocks.rb +1 -1
- data/examples/tab_colors.rb +1 -1
- data/examples/tables.rb +78 -43
- data/lib/write_xlsx/chart.rb +43 -35
- data/lib/write_xlsx/chart/area.rb +1 -1
- data/lib/write_xlsx/chart/axis.rb +2 -2
- data/lib/write_xlsx/chart/bar.rb +1 -1
- data/lib/write_xlsx/chart/column.rb +1 -1
- data/lib/write_xlsx/chart/doughnut.rb +1 -1
- data/lib/write_xlsx/chart/legend.rb +14 -0
- data/lib/write_xlsx/chart/line.rb +16 -2
- data/lib/write_xlsx/chart/pie.rb +30 -15
- data/lib/write_xlsx/chart/radar.rb +1 -1
- data/lib/write_xlsx/chart/scatter.rb +1 -1
- data/lib/write_xlsx/chart/stock.rb +1 -1
- data/lib/write_xlsx/chartsheet.rb +35 -7
- data/lib/write_xlsx/drawing.rb +86 -30
- data/lib/write_xlsx/format.rb +9 -9
- data/lib/write_xlsx/package/comments.rb +61 -58
- data/lib/write_xlsx/package/conditional_format.rb +9 -1
- data/lib/write_xlsx/package/relationships.rb +4 -4
- data/lib/write_xlsx/package/styles.rb +26 -8
- data/lib/write_xlsx/package/table.rb +13 -7
- data/lib/write_xlsx/package/vml.rb +20 -19
- data/lib/write_xlsx/shape.rb +4 -3
- data/lib/write_xlsx/sheets.rb +18 -16
- data/lib/write_xlsx/sparkline.rb +1 -1
- data/lib/write_xlsx/utility.rb +96 -7
- data/lib/write_xlsx/version.rb +1 -1
- data/lib/write_xlsx/workbook.rb +99 -49
- data/lib/write_xlsx/worksheet.rb +225 -145
- data/lib/write_xlsx/worksheet/data_validation.rb +10 -14
- data/lib/write_xlsx/worksheet/hyperlink.rb +16 -37
- data/test/chart/test_write_legend_pos.rb +9 -1
- data/test/chartsheet/test_write_sheet_protection.rb +91 -0
- data/test/drawing/test_drawing_chart_01.rb +6 -2
- data/test/drawing/test_drawing_image_01.rb +12 -3
- data/test/drawing/test_drawing_shape_01.rb +8 -5
- data/test/drawing/test_drawing_shape_02.rb +12 -5
- data/test/drawing/test_drawing_shape_03.rb +8 -5
- data/test/drawing/test_drawing_shape_04.rb +8 -24
- data/test/drawing/test_drawing_shape_05.rb +8 -5
- data/test/drawing/test_drawing_shape_06.rb +11 -6
- data/test/drawing/test_drawing_shape_07.rb +11 -6
- data/test/drawing/test_write_a_graphic_frame_locks.rb +1 -1
- data/test/drawing/test_write_c_chart.rb +1 -1
- data/test/drawing/test_write_c_nv_graphic_frame_pr.rb +1 -1
- data/test/drawing/test_write_c_nv_pr.rb +1 -1
- data/test/drawing/test_write_col.rb +1 -1
- data/test/drawing/test_write_col_off.rb +1 -1
- data/test/drawing/test_write_ext.rb +1 -1
- data/test/drawing/test_write_pos.rb +1 -1
- data/test/drawing/test_write_row.rb +1 -1
- data/test/drawing/test_write_row_off.rb +1 -1
- data/test/drawing/test_write_xfrm_extension.rb +1 -1
- data/test/drawing/test_write_xfrm_offset.rb +1 -1
- data/test/package/comments/test_comments_01.rb +54 -0
- data/test/package/comments/test_comments_02.rb +54 -0
- data/test/perl_output/chart_gauge.xlsx +0 -0
- data/test/perl_output/chart_line.xlsx +0 -0
- data/test/perl_output/comments2.xlsx +0 -0
- data/test/perl_output/formats.xlsx +0 -0
- data/test/perl_output/tables.xlsx +0 -0
- data/test/regression/images/happy.jpg +0 -0
- data/test/regression/images/red2.png +0 -0
- data/test/regression/test_array_formula03.rb +36 -0
- data/test/regression/test_autofilter08.rb +110 -0
- data/test/regression/test_autofilter09.rb +110 -0
- data/test/regression/test_autofilter10.rb +110 -0
- data/test/regression/test_chart_axis26.rb +10 -8
- data/test/regression/test_chart_axis27.rb +1 -1
- data/test/regression/test_chart_axis28.rb +1 -1
- data/test/regression/test_chart_axis29.rb +1 -1
- data/test/regression/test_chart_axis33.rb +1 -1
- data/test/regression/test_chart_axis42.rb +44 -0
- data/test/regression/test_chart_axis43.rb +44 -0
- data/test/regression/test_chart_axis44.rb +54 -0
- data/test/regression/test_chart_axis45.rb +54 -0
- data/test/regression/test_chart_axis46.rb +54 -0
- data/test/regression/test_chart_combined10.rb +43 -0
- data/test/regression/test_chart_combined11.rb +63 -0
- data/test/regression/test_chart_data_labels25.rb +1 -1
- data/test/regression/test_chart_doughnut07.rb +37 -0
- data/test/regression/test_chart_font09.rb +1 -1
- data/test/regression/test_chart_legend03.rb +41 -0
- data/test/regression/test_chart_legend04.rb +41 -0
- data/test/regression/test_chart_legend05.rb +41 -0
- data/test/regression/test_chart_legend06.rb +41 -0
- data/test/regression/test_chart_legend07.rb +38 -0
- data/test/regression/test_chart_line05.rb +43 -0
- data/test/regression/test_chart_line06.rb +43 -0
- data/test/regression/test_chart_size03.rb +4 -1
- data/test/regression/test_comment13.rb +36 -0
- data/test/regression/test_comment14.rb +29 -0
- data/test/regression/test_comment15.rb +28 -0
- data/test/regression/test_comment16.rb +34 -0
- data/test/regression/test_cond_format19.rb +64 -0
- data/test/regression/test_cond_format20.rb +43 -0
- data/test/regression/test_format15.rb +26 -0
- data/test/regression/test_header_image15.rb +36 -0
- data/test/regression/test_header_image16.rb +42 -0
- data/test/regression/test_header_image17.rb +46 -0
- data/test/regression/test_header_image18.rb +48 -0
- data/test/regression/test_header_image19.rb +36 -0
- data/test/regression/test_hyperlink32.rb +27 -0
- data/test/regression/test_hyperlink33.rb +28 -0
- data/test/regression/test_hyperlink34.rb +33 -0
- data/test/regression/test_hyperlink35.rb +39 -0
- data/test/regression/test_hyperlink36.rb +34 -0
- data/test/regression/test_hyperlink37.rb +33 -0
- data/test/regression/test_hyperlink38.rb +27 -0
- data/test/regression/test_hyperlink39.rb +27 -0
- data/test/regression/test_hyperlink40.rb +27 -0
- data/test/regression/test_hyperlink41.rb +27 -0
- data/test/regression/test_hyperlink42.rb +27 -0
- data/test/regression/test_hyperlink43.rb +27 -0
- data/test/regression/test_hyperlink44.rb +27 -0
- data/test/regression/test_hyperlink45.rb +27 -0
- data/test/regression/test_hyperlink47.rb +27 -0
- data/test/regression/test_hyperlink48.rb +31 -0
- data/test/regression/test_hyperlink49.rb +29 -0
- data/test/regression/test_image06.rb +5 -5
- data/test/regression/test_image08.rb +5 -4
- data/test/regression/test_image15.rb +4 -2
- data/test/regression/test_image28.rb +1 -1
- data/test/regression/test_image36.rb +26 -0
- data/test/regression/test_image44.rb +28 -0
- data/test/regression/test_image45.rb +29 -0
- data/test/regression/test_image46.rb +29 -0
- data/test/regression/test_image47.rb +28 -0
- data/test/regression/test_image48.rb +32 -0
- data/test/regression/test_image49.rb +38 -0
- data/test/regression/test_image50.rb +24 -0
- data/test/regression/test_image51.rb +30 -0
- data/test/regression/test_object_position01.rb +26 -0
- data/test/regression/test_object_position02.rb +26 -0
- data/test/regression/test_object_position03.rb +26 -0
- data/test/regression/test_object_position04.rb +44 -0
- data/test/regression/test_object_position06.rb +28 -0
- data/test/regression/test_object_position07.rb +28 -0
- data/test/regression/test_object_position08.rb +47 -0
- data/test/regression/test_object_position09.rb +50 -0
- data/test/regression/test_object_position10.rb +28 -0
- data/test/regression/test_object_position12.rb +25 -0
- data/test/regression/test_object_position13.rb +25 -0
- data/test/regression/test_object_position14.rb +25 -0
- data/test/regression/test_object_position15.rb +29 -0
- data/test/regression/test_object_position16.rb +29 -0
- data/test/regression/test_object_position17.rb +29 -0
- data/test/regression/test_object_position18.rb +29 -0
- data/test/regression/test_object_position19.rb +29 -0
- data/test/regression/test_object_position20.rb +29 -0
- data/test/regression/test_shape_connect01.rb +4 -2
- data/test/regression/test_table23.rb +56 -0
- data/test/regression/test_table24.rb +27 -0
- data/test/regression/test_table25.rb +27 -0
- data/test/regression/xlsx_files/array_formula03.xlsx +0 -0
- data/test/regression/xlsx_files/autofilter08.xlsx +0 -0
- data/test/regression/xlsx_files/autofilter09.xlsx +0 -0
- data/test/regression/xlsx_files/autofilter10.xlsx +0 -0
- data/test/regression/xlsx_files/chart_axis26.xlsx +0 -0
- data/test/regression/xlsx_files/chart_axis27.xlsx +0 -0
- data/test/regression/xlsx_files/chart_axis28.xlsx +0 -0
- data/test/regression/xlsx_files/chart_axis29.xlsx +0 -0
- data/test/regression/xlsx_files/chart_axis33.xlsx +0 -0
- data/test/regression/xlsx_files/chart_axis42.xlsx +0 -0
- data/test/regression/xlsx_files/chart_axis43.xlsx +0 -0
- data/test/regression/xlsx_files/chart_axis44.xlsx +0 -0
- data/test/regression/xlsx_files/chart_axis45.xlsx +0 -0
- data/test/regression/xlsx_files/chart_axis46.xlsx +0 -0
- data/test/regression/xlsx_files/chart_combined10.xlsx +0 -0
- data/test/regression/xlsx_files/chart_combined11.xlsx +0 -0
- data/test/regression/xlsx_files/chart_data_labels25.xlsx +0 -0
- data/test/regression/xlsx_files/chart_doughnut07.xlsx +0 -0
- data/test/regression/xlsx_files/chart_font09.xlsx +0 -0
- data/test/regression/xlsx_files/chart_legend03.xlsx +0 -0
- data/test/regression/xlsx_files/chart_legend04.xlsx +0 -0
- data/test/regression/xlsx_files/chart_legend05.xlsx +0 -0
- data/test/regression/xlsx_files/chart_legend06.xlsx +0 -0
- data/test/regression/xlsx_files/chart_legend07.xlsx +0 -0
- data/test/regression/xlsx_files/chart_line05.xlsx +0 -0
- data/test/regression/xlsx_files/chart_line06.xlsx +0 -0
- data/test/regression/xlsx_files/comment13.xlsx +0 -0
- data/test/regression/xlsx_files/comment14.xlsx +0 -0
- data/test/regression/xlsx_files/comment15.xlsx +0 -0
- data/test/regression/xlsx_files/comment16.xlsx +0 -0
- data/test/regression/xlsx_files/cond_format19.xlsx +0 -0
- data/test/regression/xlsx_files/cond_format20.xlsx +0 -0
- data/test/regression/xlsx_files/format15.xlsx +0 -0
- data/test/regression/xlsx_files/header_image15.xlsx +0 -0
- data/test/regression/xlsx_files/header_image16.xlsx +0 -0
- data/test/regression/xlsx_files/header_image17.xlsx +0 -0
- data/test/regression/xlsx_files/header_image18.xlsx +0 -0
- data/test/regression/xlsx_files/header_image19.xlsx +0 -0
- data/test/regression/xlsx_files/hyperlink32.xlsx +0 -0
- data/test/regression/xlsx_files/hyperlink33.xlsx +0 -0
- data/test/regression/xlsx_files/hyperlink34.xlsx +0 -0
- data/test/regression/xlsx_files/hyperlink35.xlsx +0 -0
- data/test/regression/xlsx_files/hyperlink36.xlsx +0 -0
- data/test/regression/xlsx_files/hyperlink37.xlsx +0 -0
- data/test/regression/xlsx_files/hyperlink38.xlsx +0 -0
- data/test/regression/xlsx_files/hyperlink39.xlsx +0 -0
- data/test/regression/xlsx_files/hyperlink40.xlsx +0 -0
- data/test/regression/xlsx_files/hyperlink41.xlsx +0 -0
- data/test/regression/xlsx_files/hyperlink42.xlsx +0 -0
- data/test/regression/xlsx_files/hyperlink43.xlsx +0 -0
- data/test/regression/xlsx_files/hyperlink44.xlsx +0 -0
- data/test/regression/xlsx_files/hyperlink45.xlsx +0 -0
- data/test/regression/xlsx_files/hyperlink46.xlsx +0 -0
- data/test/regression/xlsx_files/hyperlink47.xlsx +0 -0
- data/test/regression/xlsx_files/hyperlink48.xlsx +0 -0
- data/test/regression/xlsx_files/hyperlink49.xlsx +0 -0
- data/test/regression/xlsx_files/image06.xlsx +0 -0
- data/test/regression/xlsx_files/image36.xlsx +0 -0
- data/test/regression/xlsx_files/image44.xlsx +0 -0
- data/test/regression/xlsx_files/image45.xlsx +0 -0
- data/test/regression/xlsx_files/image46.xlsx +0 -0
- data/test/regression/xlsx_files/image47.xlsx +0 -0
- data/test/regression/xlsx_files/image48.xlsx +0 -0
- data/test/regression/xlsx_files/image49.xlsx +0 -0
- data/test/regression/xlsx_files/image50.xlsx +0 -0
- data/test/regression/xlsx_files/image51.xlsx +0 -0
- data/test/regression/xlsx_files/object_position01.xlsx +0 -0
- data/test/regression/xlsx_files/object_position02.xlsx +0 -0
- data/test/regression/xlsx_files/object_position03.xlsx +0 -0
- data/test/regression/xlsx_files/object_position04.xlsx +0 -0
- data/test/regression/xlsx_files/object_position06.xlsx +0 -0
- data/test/regression/xlsx_files/object_position07.xlsx +0 -0
- data/test/regression/xlsx_files/object_position08.xlsx +0 -0
- data/test/regression/xlsx_files/object_position09.xlsx +0 -0
- data/test/regression/xlsx_files/object_position10.xlsx +0 -0
- data/test/regression/xlsx_files/object_position12.xlsx +0 -0
- data/test/regression/xlsx_files/object_position13.xlsx +0 -0
- data/test/regression/xlsx_files/object_position14.xlsx +0 -0
- data/test/regression/xlsx_files/object_position15.xlsx +0 -0
- data/test/regression/xlsx_files/object_position16.xlsx +0 -0
- data/test/regression/xlsx_files/object_position17.xlsx +0 -0
- data/test/regression/xlsx_files/object_position18.xlsx +0 -0
- data/test/regression/xlsx_files/object_position19.xlsx +0 -0
- data/test/regression/xlsx_files/object_position20.xlsx +0 -0
- data/test/regression/xlsx_files/table23.xlsx +0 -0
- data/test/regression/xlsx_files/table24.xlsx +0 -0
- data/test/regression/xlsx_files/table25.xlsx +0 -0
- data/test/test_example_match.rb +955 -780
- data/test/workbook/test_check_sheetname.rb +51 -0
- data/test/workbook/test_write_workbook_view.rb +36 -0
- data/test/worksheet/test_write_data_validation_02.rb +17 -0
- data/test/worksheet/test_write_sheet_view.rb +19 -1
- data/write_xlsx.gemspec +1 -0
- metadata +349 -7
- data/test/package/comments/test_write_text_t.rb +0 -44
@@ -219,10 +219,17 @@ def check_valid_citeria_types
|
|
219
219
|
end
|
220
220
|
|
221
221
|
def convert_date_time_value_if_required
|
222
|
-
@date_1904 = date_1904?
|
223
222
|
if @validate == 'date' || @validate == 'time'
|
224
|
-
|
225
|
-
|
223
|
+
date_time = convert_date_time(@value)
|
224
|
+
if date_time
|
225
|
+
@value = date_time
|
226
|
+
end
|
227
|
+
|
228
|
+
if @maximum
|
229
|
+
date_time = convert_date_time(@maximum)
|
230
|
+
if date_time
|
231
|
+
@maximum = date_time
|
232
|
+
end
|
226
233
|
end
|
227
234
|
end
|
228
235
|
end
|
@@ -292,17 +299,6 @@ def valid_criteria_type # :nodoc:
|
|
292
299
|
}
|
293
300
|
end
|
294
301
|
|
295
|
-
def convert_date_time_value(key) # :nodoc:
|
296
|
-
value = instance_variable_get("@#{key}")
|
297
|
-
if value && value.to_s =~ /T/
|
298
|
-
date_time = convert_date_time(value)
|
299
|
-
instance_variable_set("@#{key}", date_time) if date_time
|
300
|
-
date_time
|
301
|
-
else
|
302
|
-
true
|
303
|
-
end
|
304
|
-
end
|
305
|
-
|
306
302
|
def date_1904?
|
307
303
|
@date_1904
|
308
304
|
end
|
@@ -7,19 +7,19 @@ class Hyperlink # :nodoc:
|
|
7
7
|
|
8
8
|
attr_reader :str, :tip
|
9
9
|
|
10
|
-
MAXIMUM_URLS_SIZE =
|
10
|
+
MAXIMUM_URLS_SIZE = 2079
|
11
11
|
|
12
|
-
def self.factory(url, str = nil, tip = nil)
|
12
|
+
def self.factory(url, str = nil, tip = nil, max_url_length = MAXIMUM_URLS_SIZE)
|
13
13
|
if url =~ /^internal:(.+)/
|
14
|
-
InternalHyperlink.new($~[1], str, tip)
|
14
|
+
InternalHyperlink.new($~[1], str, tip, max_url_length)
|
15
15
|
elsif url =~ /^external:(.+)/
|
16
|
-
ExternalHyperlink.new($~[1], str, tip)
|
16
|
+
ExternalHyperlink.new($~[1], str, tip, max_url_length)
|
17
17
|
else
|
18
|
-
new(url, str, tip)
|
18
|
+
new(url, str, tip, max_url_length)
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
def initialize(url, str, tip)
|
22
|
+
def initialize(url, str, tip, max_url_length)
|
23
23
|
# The displayed string defaults to the url string.
|
24
24
|
str ||= url.dup
|
25
25
|
|
@@ -33,8 +33,8 @@ def initialize(url, str, tip)
|
|
33
33
|
url = escape_url(url)
|
34
34
|
|
35
35
|
# Excel limits the escaped URL and location/anchor to 255 characters.
|
36
|
-
if url.bytesize >
|
37
|
-
raise "Ignoring URL '#{url}' where link or anchor >
|
36
|
+
if url.bytesize > max_url_length || (!@url_str.nil? && @url_str.bytesize > max_url_length)
|
37
|
+
raise "Ignoring URL '#{url}' where link or anchor > #{max_url_length} characters since it exceeds Excel's limit for URLS. See LIMITATIONS section of the Excel::Writer::XLSX documentation."
|
38
38
|
end
|
39
39
|
|
40
40
|
@url = url
|
@@ -61,33 +61,12 @@ def external_hyper_link
|
|
61
61
|
def display_on
|
62
62
|
@display = @url_str
|
63
63
|
end
|
64
|
-
|
65
|
-
private
|
66
|
-
|
67
|
-
def escape_url(url)
|
68
|
-
unless url =~ /%[0-9a-fA-F]{2}/
|
69
|
-
# Escape the URL escape symbol.
|
70
|
-
url = url.gsub(/%/, "%25")
|
71
|
-
|
72
|
-
# Escape whitespae in URL.
|
73
|
-
url = url.gsub(/[\s\x00]/, '%20')
|
74
|
-
|
75
|
-
# Escape other special characters in URL.
|
76
|
-
re = /(["<>\[\]`^{}])/
|
77
|
-
while re =~ url
|
78
|
-
match = $~[1]
|
79
|
-
url = url.sub(re, sprintf("%%%x", match.ord))
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
url
|
84
|
-
end
|
85
64
|
end
|
86
65
|
|
87
66
|
class InternalHyperlink < Hyperlink
|
88
67
|
undef external_hyper_link
|
89
68
|
|
90
|
-
def initialize(url, str, tip)
|
69
|
+
def initialize(url, str, tip, max_url_length)
|
91
70
|
@url = url
|
92
71
|
# The displayed string defaults to the url string.
|
93
72
|
str ||= @url.dup
|
@@ -98,9 +77,9 @@ def initialize(url, str, tip)
|
|
98
77
|
# Copy string for use in hyperlink elements.
|
99
78
|
@url_str = @str.dup
|
100
79
|
|
101
|
-
# Excel limits escaped URL to
|
102
|
-
if @url.bytesize >
|
103
|
-
raise "URL '#{@url}' > #{
|
80
|
+
# Excel limits escaped URL to #{max_url_length} characters.
|
81
|
+
if @url.bytesize > max_url_length
|
82
|
+
raise "URL '#{@url}' > #{max_url_length} characters, it exceeds Excel's limit for URLS."
|
104
83
|
end
|
105
84
|
|
106
85
|
@tip = tip
|
@@ -118,7 +97,7 @@ def attributes(row, col, dummy = nil)
|
|
118
97
|
end
|
119
98
|
|
120
99
|
class ExternalHyperlink < Hyperlink
|
121
|
-
def initialize(url, str, tip)
|
100
|
+
def initialize(url, str, tip, max_url_length)
|
122
101
|
# The displayed string defaults to the url string.
|
123
102
|
str ||= url.dup
|
124
103
|
|
@@ -145,9 +124,9 @@ def initialize(url, str, tip)
|
|
145
124
|
url = url.sub(%r!^.\\!, '')
|
146
125
|
@url_str = url_str
|
147
126
|
|
148
|
-
# Excel limits the escaped URL and location/anchor to
|
149
|
-
if url.bytesize >
|
150
|
-
raise "Ignoring URL '#{url}' where link or anchor >
|
127
|
+
# Excel limits the escaped URL and location/anchor to max_url_length characters.
|
128
|
+
if url.bytesize > max_url_length || (!@url_str.nil? && @url_str.bytesize > max_url_length)
|
129
|
+
raise "Ignoring URL '#{url}' where link or anchor > #{max_url_length} characters since it exceeds Excel's limit for URLS. See LIMITATIONS section of the Excel::Writer::XLSX documentation."
|
151
130
|
end
|
152
131
|
|
153
132
|
@url = url
|
@@ -7,9 +7,17 @@ def setup
|
|
7
7
|
@chart = Writexlsx::Chart.new('Bar')
|
8
8
|
end
|
9
9
|
|
10
|
-
def
|
10
|
+
def test_write_legend_pos_default
|
11
11
|
expected = '<c:legendPos val="r"/>'
|
12
12
|
result = @chart.__send__('write_legend_pos', 'r')
|
13
13
|
assert_equal(expected, result)
|
14
14
|
end
|
15
|
+
|
16
|
+
def test_write_legend_overlay_top_right
|
17
|
+
expected = '<c:legend><c:legendPos val="tr"/><c:layout/><c:overlay val="1"/></c:legend>'
|
18
|
+
@chart.set_legend(:position => 'overlay_top_right')
|
19
|
+
@chart.__send__('write_legend')
|
20
|
+
result = @chart.instance_variable_get(:@writer).string
|
21
|
+
assert_equal(expected, result)
|
22
|
+
end
|
15
23
|
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'helper'
|
3
|
+
|
4
|
+
class TestChartsheetWriteSheetProtection < Minitest::Test
|
5
|
+
def setup
|
6
|
+
workbook = WriteXLSX.new(StringIO.new)
|
7
|
+
workbook.add_chart(:type => 'line')
|
8
|
+
@chartsheet = workbook.sheets.first
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_chartsheet_write_sheet_protection
|
12
|
+
expected = '<sheetProtection password="83AF" content="1" objects="1"/>'
|
13
|
+
|
14
|
+
@chartsheet.protect('', {})
|
15
|
+
result = @chartsheet.__send__(:write_sheet_protection)
|
16
|
+
assert_equal(expected_to_array(expected), got_to_array(result))
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_chartsheet_write_sheet_protection
|
20
|
+
expected = '<sheetProtection password="83AF" content="1" objects="1"/>'
|
21
|
+
|
22
|
+
@chartsheet.protect('password', {})
|
23
|
+
result = @chartsheet.__send__(:write_sheet_protection)
|
24
|
+
assert_equal(expected_to_array(expected), got_to_array(result))
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_chartsheet_write_sheet_protection_without_password_and_content
|
28
|
+
expected = '<sheetProtection content="1"/>'
|
29
|
+
|
30
|
+
@chartsheet.protect('', {:objects => 0})
|
31
|
+
result = @chartsheet.__send__(:write_sheet_protection)
|
32
|
+
assert_equal(expected_to_array(expected), got_to_array(result))
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_chartsheet_write_sheet_protection_with_opjects0_option
|
36
|
+
expected = '<sheetProtection password="83AF" content="1"/>'
|
37
|
+
|
38
|
+
@chartsheet.protect('password', { :objects => 0 })
|
39
|
+
result = @chartsheet.__send__(:write_sheet_protection)
|
40
|
+
assert_equal(expected_to_array(expected), got_to_array(result))
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_chartsheet_write_sheet_protection_without_password
|
44
|
+
expected = '<sheetProtection objects="1"/>'
|
45
|
+
|
46
|
+
@chartsheet.protect('', { :content => 0 })
|
47
|
+
result = @chartsheet.__send__(:write_sheet_protection)
|
48
|
+
assert_equal(expected_to_array(expected), got_to_array(result))
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_chartsheet_write_sheet_protection_without_password_and_content_option
|
52
|
+
expected = ''
|
53
|
+
|
54
|
+
@chartsheet.protect('', { :content => 0, :objects => 0 })
|
55
|
+
result = @chartsheet.__send__(:write_sheet_protection) || ''
|
56
|
+
assert_equal(expected_to_array(expected), got_to_array(result))
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_chartsheet_write_sheet_protection_with_password_and_content_objects_option
|
60
|
+
expected = '<sheetProtection password="83AF"/>'
|
61
|
+
|
62
|
+
@chartsheet.protect('password', { :content => 0, :objects => 0 })
|
63
|
+
result = @chartsheet.__send__(:write_sheet_protection)
|
64
|
+
assert_equal(expected_to_array(expected), got_to_array(result))
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_chartsheet_write_sheet_protection_with_password_full_options
|
68
|
+
expected = '<sheetProtection password="83AF" content="1" objects="1"/>'
|
69
|
+
|
70
|
+
options = {
|
71
|
+
:objects => 1,
|
72
|
+
:scenarios => 1,
|
73
|
+
:format_cells => 1,
|
74
|
+
:format_columns => 1,
|
75
|
+
:format_rows => 1,
|
76
|
+
:insert_columns => 1,
|
77
|
+
:insert_rows => 1,
|
78
|
+
:insert_hyperlinks => 1,
|
79
|
+
:delete_columns => 1,
|
80
|
+
:delete_rows => 1,
|
81
|
+
:select_locked_cells => 0,
|
82
|
+
:sort => 1,
|
83
|
+
:autofilter => 1,
|
84
|
+
:pivot_tables => 1,
|
85
|
+
:select_unlocked_cells => 0
|
86
|
+
}
|
87
|
+
@chartsheet.protect('password', options)
|
88
|
+
result = @chartsheet.__send__(:write_sheet_protection)
|
89
|
+
assert_equal(expected_to_array(expected), got_to_array(result))
|
90
|
+
end
|
91
|
+
end
|
@@ -4,8 +4,12 @@
|
|
4
4
|
|
5
5
|
class DrawingChart011 < Minitest::Test
|
6
6
|
def test_drawing_chart_01
|
7
|
-
@obj = Writexlsx::
|
8
|
-
|
7
|
+
@obj = Writexlsx::Drawings.new
|
8
|
+
dimensions = [4, 8, 457200, 104775, 12, 22, 152400, 180975]
|
9
|
+
drawing = Writexlsx::Drawing.new(
|
10
|
+
1, dimensions, nil, nil, nil, nil, 1, 1
|
11
|
+
)
|
12
|
+
@obj.add_drawing_object(drawing)
|
9
13
|
@obj.embedded = true
|
10
14
|
@obj.assemble_xml_file
|
11
15
|
result = got_to_array(@obj.xml_str)
|
@@ -4,9 +4,18 @@
|
|
4
4
|
|
5
5
|
class DrawingImage011 < Minitest::Test
|
6
6
|
def test_drawing_image_01
|
7
|
-
@obj = Writexlsx::
|
8
|
-
|
9
|
-
|
7
|
+
@obj = Writexlsx::Drawings.new
|
8
|
+
dimensions = [
|
9
|
+
2, 1, 0, 0, 3, 6, 533257, 190357, 1219200, 190500
|
10
|
+
]
|
11
|
+
drawing = Writexlsx::Drawing.new(
|
12
|
+
2, dimensions, 1142857, 1142857, 'republic.png', nil, 2, 1
|
13
|
+
)
|
14
|
+
@obj.add_drawing_object(drawing)
|
15
|
+
# @obj.add_drawing_object(
|
16
|
+
# 2, 2, 1, 0, 0, 3, 6, 533257, 190357,
|
17
|
+
# 1219200, 190500, 1142857, 1142857, 'republic.png', nil, 2
|
18
|
+
# )
|
10
19
|
@obj.embedded = true
|
11
20
|
@obj.assemble_xml_file
|
12
21
|
result = got_to_array(@obj.xml_str)
|
@@ -8,12 +8,15 @@ def test_drawing_shape_01
|
|
8
8
|
shape = Writexlsx::Shape.new
|
9
9
|
shape.id = 1000
|
10
10
|
|
11
|
-
@obj = Writexlsx::
|
11
|
+
@obj = Writexlsx::Drawings.new
|
12
12
|
@obj.embedded = 1
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
dimensions = [
|
14
|
+
4, 8, 209550, 95250, 12, 22, 209660, 96260, 10000, 20000
|
15
|
+
]
|
16
|
+
drawing = Writexlsx::Drawing.new(
|
17
|
+
3, dimensions, 95250, 190500, 'rect 1', shape, 1
|
18
|
+
)
|
19
|
+
@obj.add_drawing_object(drawing)
|
17
20
|
@obj.assemble_xml_file
|
18
21
|
result = got_to_array(@obj.xml_str)
|
19
22
|
expected = expected_to_array(<<EOS
|
@@ -13,12 +13,19 @@ def test_drawing_shape_02
|
|
13
13
|
# Set bulk shape properties via set_properties method
|
14
14
|
shape.set_properties(:type => 'straightConnector1', :connect => 1)
|
15
15
|
|
16
|
-
@obj = Writexlsx::
|
16
|
+
@obj = Writexlsx::Drawings.new
|
17
17
|
@obj.embedded = 1
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
dimensions = [
|
19
|
+
4, 8, 209550, 95250, 12, 22, 209660, 96260, 10000, 20000
|
20
|
+
]
|
21
|
+
drawing = Writexlsx::Drawing.new(
|
22
|
+
3, dimensions, 95250, 190500, 'Connector 1', shape, 1
|
23
|
+
)
|
24
|
+
@obj.add_drawing_object(drawing)
|
25
|
+
# @obj.add_drawing_object(
|
26
|
+
# 3, 4, 8, 209550, 95250, 12, 22, 209660,
|
27
|
+
# 96260, 10000, 20000, 95250, 190500, 'Connector 1', shape, 1
|
28
|
+
# )
|
22
29
|
@obj.assemble_xml_file
|
23
30
|
result = got_to_array(@obj.xml_str)
|
24
31
|
expected = expected_to_array(<<EOS
|
@@ -13,12 +13,15 @@ def test_drawing_shape_03
|
|
13
13
|
shape.end = 1002
|
14
14
|
shape.end_index = 4
|
15
15
|
|
16
|
-
@obj = Writexlsx::
|
16
|
+
@obj = Writexlsx::Drawings.new
|
17
17
|
@obj.embedded = 1
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
dimensions = [
|
19
|
+
4, 8, 209550, 95250, 12, 22, 209660, 96260, 10000, 20000
|
20
|
+
]
|
21
|
+
drawing = Writexlsx::Drawing.new(
|
22
|
+
3, dimensions, 95250, 190500, '', shape, 1
|
23
|
+
)
|
24
|
+
@obj.add_drawing_object(drawing)
|
22
25
|
@obj.__send__('write_nv_cxn_sp_pr', 1, shape)
|
23
26
|
|
24
27
|
result = got_to_array(@obj.xml_str)
|
@@ -19,36 +19,20 @@ def test_drawing_shape_04
|
|
19
19
|
shape.palette[0] = [0x00, 0x00, 0x00, 0x00]
|
20
20
|
shape.palette[7] = [0x00, 0x00, 0x00, 0x00]
|
21
21
|
|
22
|
-
@obj = Writexlsx::
|
22
|
+
@obj = Writexlsx::Drawings.new
|
23
23
|
@obj.embedded = 2
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
24
|
+
dimensions = [
|
25
|
+
4, 8, 209550, 95250, 12, 22, 209660, 96260, 10000, 20000
|
26
|
+
]
|
27
|
+
drawing = Writexlsx::Drawing.new(
|
28
|
+
3, dimensions, 95250, 190500, 'rect 1', shape, 1
|
29
|
+
)
|
30
|
+
@obj.add_drawing_object(drawing)
|
28
31
|
@obj.assemble_xml_file
|
29
32
|
|
30
33
|
result = got_to_array(@obj.xml_str)
|
31
34
|
expected = expected_to_array(expected_str)
|
32
35
|
assert_equal(expected, result)
|
33
|
-
|
34
|
-
drawing1 = Writexlsx::Drawing.new
|
35
|
-
@worksheet.instance_variable_set(:@drawing, drawing1)
|
36
|
-
inserted = @worksheet.insert_shape(4, 8, shape, 300, 400)
|
37
|
-
|
38
|
-
# Force the shape cell x offset to be non-integer
|
39
|
-
inserted.x_offset += 0.5
|
40
|
-
@worksheet.__send__(:prepare_shape, 0, 1)
|
41
|
-
|
42
|
-
# Truncate drawing object to just the dimensions
|
43
|
-
drawing1.instance_variable_get(:@drawings)[0] =
|
44
|
-
drawing1.instance_variable_get(:@drawings)[0][0..12]
|
45
|
-
|
46
|
-
# Verify fractional dimensions have been rounded
|
47
|
-
expected = [
|
48
|
-
3, 12, 24, 423862, 0, 13, 26, 290512,
|
49
|
-
95250, 7739062, 4572000, 476250, 476250
|
50
|
-
]
|
51
|
-
assert_equal(expected, drawing1.instance_variable_get(:@drawings)[0])
|
52
36
|
end
|
53
37
|
|
54
38
|
def expected_str
|
@@ -19,14 +19,17 @@ def test_drawing_shape_05
|
|
19
19
|
shape.flip_h = 1
|
20
20
|
shape.rotation = 90
|
21
21
|
|
22
|
-
@obj = Writexlsx::
|
22
|
+
@obj = Writexlsx::Drawings.new
|
23
23
|
@obj.instance_variable_set(:@palette, @worksheet.instance_variable_get(:@palette))
|
24
24
|
@obj.embedded = 1
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
26
|
+
dimensions = [
|
27
|
+
4, 8, 209550, 95250, 12, 22, 209660, 96260, 10000, 20000
|
28
|
+
]
|
29
|
+
drawing = Writexlsx::Drawing.new(
|
30
|
+
3, dimensions, 95250, 190500, '', shape, 1
|
31
|
+
)
|
32
|
+
@obj.add_drawing_object(drawing)
|
30
33
|
@obj.__send__(:write_a_xfrm, 100, 200, 10, 20, shape)
|
31
34
|
|
32
35
|
result = got_to_array(@obj.xml_str)
|
@@ -16,13 +16,18 @@ def test_drawing_shape_06
|
|
16
16
|
shape = Writexlsx::Shape.new
|
17
17
|
shape.adjustments = -10, 100, 20
|
18
18
|
|
19
|
-
@obj = Writexlsx::
|
19
|
+
@obj = Writexlsx::Drawings.new
|
20
20
|
@obj.embedded = 1
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
21
|
+
dimensions = [
|
22
|
+
4, 8, 209550, 95250, 12, 22, 209660, 96260, 10000, 20000
|
23
|
+
]
|
24
|
+
drawing = Writexlsx::Drawing.new(
|
25
|
+
3, dimensions, 95250, 190500, '', shape, 1
|
26
|
+
)
|
27
|
+
@obj.add_drawing_object(drawing)
|
28
|
+
# 3, 4, 8, 209550, 95250, 12, 22, 209660,
|
29
|
+
# 96260, 10000, 20000, 95250, 190500, '', shape
|
30
|
+
# )
|
26
31
|
@obj.__send__(:write_a_av_lst, shape)
|
27
32
|
|
28
33
|
result = got_to_array(@obj.xml_str)
|