write_xlsx 1.09.5 → 1.10.1

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.
Files changed (110) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +6 -1
  3. data/Changes +8 -0
  4. data/LICENSE.txt +1 -1
  5. data/README.md +1 -1
  6. data/examples/autofilter.rb +39 -10
  7. data/examples/chart_area.rb +12 -12
  8. data/examples/chart_bar.rb +12 -12
  9. data/examples/chart_clustered.rb +12 -12
  10. data/examples/chart_column.rb +12 -12
  11. data/examples/chart_combined.rb +25 -25
  12. data/examples/chart_data_labels.rb +99 -99
  13. data/examples/chart_data_table.rb +25 -25
  14. data/examples/chart_data_tools.rb +50 -50
  15. data/examples/chart_doughnut.rb +29 -29
  16. data/examples/chart_gauge.rb +18 -18
  17. data/examples/chart_line.rb +32 -32
  18. data/examples/chart_pareto.rb +16 -16
  19. data/examples/chart_pie.rb +17 -17
  20. data/examples/chart_radar.rb +38 -38
  21. data/examples/chart_scatter.rb +12 -12
  22. data/examples/chart_secondary_axis.rb +13 -13
  23. data/examples/chart_stock.rb +12 -12
  24. data/examples/chart_styles.rb +5 -5
  25. data/examples/colors.rb +11 -11
  26. data/examples/comments2.rb +15 -15
  27. data/examples/conditional_format.rb +74 -74
  28. data/examples/data_validate.rb +64 -64
  29. data/examples/date_time.rb +3 -3
  30. data/examples/demo.rb +14 -14
  31. data/examples/diag_border.rb +6 -6
  32. data/examples/dynamic_arrays.rb +247 -0
  33. data/examples/formats.rb +10 -10
  34. data/examples/hyperlink1.rb +4 -4
  35. data/examples/ignore_errors.rb +2 -2
  36. data/examples/indent.rb +2 -2
  37. data/examples/lambda.rb +43 -0
  38. data/examples/macros.rb +4 -4
  39. data/examples/merge1.rb +1 -1
  40. data/examples/merge2.rb +9 -9
  41. data/examples/merge3.rb +5 -5
  42. data/examples/merge4.rb +20 -20
  43. data/examples/merge5.rb +18 -18
  44. data/examples/merge6.rb +7 -7
  45. data/examples/outline.rb +1 -1
  46. data/examples/outline_collapsed.rb +1 -1
  47. data/examples/panes.rb +4 -4
  48. data/examples/properties.rb +9 -9
  49. data/examples/protection.rb +2 -2
  50. data/examples/rich_strings.rb +6 -6
  51. data/examples/shape1.rb +7 -7
  52. data/examples/shape2.rb +16 -16
  53. data/examples/shape3.rb +5 -5
  54. data/examples/shape4.rb +7 -7
  55. data/examples/shape5.rb +7 -7
  56. data/examples/shape6.rb +7 -7
  57. data/examples/shape7.rb +10 -10
  58. data/examples/shape8.rb +10 -10
  59. data/examples/shape_all.rb +4 -4
  60. data/examples/sparklines1.rb +11 -11
  61. data/examples/sparklines2.rb +76 -76
  62. data/examples/tables.rb +87 -87
  63. data/examples/watermark.png +0 -0
  64. data/examples/watermark.rb +26 -0
  65. data/lib/write_xlsx/chart/bar.rb +4 -4
  66. data/lib/write_xlsx/chart/line.rb +1 -1
  67. data/lib/write_xlsx/chart/radar.rb +2 -2
  68. data/lib/write_xlsx/chart/scatter.rb +4 -4
  69. data/lib/write_xlsx/chart/series.rb +27 -27
  70. data/lib/write_xlsx/chart/stock.rb +5 -5
  71. data/lib/write_xlsx/chart.rb +31 -30
  72. data/lib/write_xlsx/chartsheet.rb +1 -0
  73. data/lib/write_xlsx/col_name.rb +1 -0
  74. data/lib/write_xlsx/colors.rb +20 -19
  75. data/lib/write_xlsx/compatibility.rb +1 -0
  76. data/lib/write_xlsx/drawing.rb +20 -10
  77. data/lib/write_xlsx/format.rb +5 -0
  78. data/lib/write_xlsx/formats.rb +1 -0
  79. data/lib/write_xlsx/gradient.rb +2 -0
  80. data/lib/write_xlsx/package/app.rb +1 -0
  81. data/lib/write_xlsx/package/button.rb +6 -2
  82. data/lib/write_xlsx/package/comments.rb +3 -1
  83. data/lib/write_xlsx/package/conditional_format.rb +4 -3
  84. data/lib/write_xlsx/package/content_types.rb +1 -0
  85. data/lib/write_xlsx/package/core.rb +1 -0
  86. data/lib/write_xlsx/package/custom.rb +1 -0
  87. data/lib/write_xlsx/package/metadata.rb +1 -0
  88. data/lib/write_xlsx/package/packager.rb +1 -0
  89. data/lib/write_xlsx/package/relationships.rb +1 -0
  90. data/lib/write_xlsx/package/shared_strings.rb +1 -1
  91. data/lib/write_xlsx/package/styles.rb +1 -0
  92. data/lib/write_xlsx/package/table.rb +9 -8
  93. data/lib/write_xlsx/package/theme.rb +1 -0
  94. data/lib/write_xlsx/package/vml.rb +1 -0
  95. data/lib/write_xlsx/package/xml_writer_simple.rb +21 -2
  96. data/lib/write_xlsx/shape.rb +6 -5
  97. data/lib/write_xlsx/sheets.rb +2 -1
  98. data/lib/write_xlsx/sparkline.rb +287 -286
  99. data/lib/write_xlsx/utility.rb +25 -26
  100. data/lib/write_xlsx/version.rb +3 -1
  101. data/lib/write_xlsx/workbook.rb +20 -20
  102. data/lib/write_xlsx/worksheet/cell_data.rb +53 -63
  103. data/lib/write_xlsx/worksheet/data_validation.rb +1 -0
  104. data/lib/write_xlsx/worksheet/hyperlink.rb +3 -2
  105. data/lib/write_xlsx/worksheet/page_setup.rb +1 -0
  106. data/lib/write_xlsx/worksheet.rb +287 -74
  107. data/lib/write_xlsx/zip_file_utils.rb +1 -0
  108. data/lib/write_xlsx.rb +1 -0
  109. data/write_xlsx.gemspec +1 -0
  110. metadata +8 -4
@@ -0,0 +1,247 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+
4
+ #######################################################################
5
+ #
6
+ # An example of how to use the write_xlsx rubygem to write functions
7
+ # that create dynamic arrays. These functions are new to Excel 365. The
8
+ # examples mirror the examples in the Excel documentation on these functions.
9
+ #
10
+ # Copyright 2000-2021, John McNamara, jmcnamara@cpan.org
11
+ # convert to ruby by Hideo NAKAMURA, nakamura.hideo@gmail.com
12
+ #
13
+
14
+ require 'write_xlsx'
15
+
16
+ # Used from test_dynamic_arrays
17
+ # Utility function to write the data some of the functions work on.
18
+ def write_worksheet_data(worksheet, header)
19
+ worksheet.write('A1', 'Region', header)
20
+ worksheet.write('B1', 'Sales Rep', header)
21
+ worksheet.write('C1', 'Product', header)
22
+ worksheet.write('D1', 'Units', header)
23
+
24
+ data = [
25
+ ['East', 'Tom', 'Apple', 6380],
26
+ ['West', 'Fred', 'Grape', 5619],
27
+ ['North', 'Amy', 'Pear', 4565],
28
+ ['South', 'Sal', 'Banana', 5323],
29
+ ['East', 'Fritz', 'Apple', 4394],
30
+ ['West', 'Sravan', 'Grape', 7195],
31
+ ['North', 'Xi', 'Pear', 5231],
32
+ ['South', 'Hector', 'Banana', 2427],
33
+ ['East', 'Tom', 'Banana', 4213],
34
+ ['West', 'Fred', 'Pear', 3239],
35
+ ['North', 'Amy', 'Grape', 6520],
36
+ ['South', 'Sal', 'Apple', 1310],
37
+ ['East', 'Fritz', 'Banana', 6274],
38
+ ['West', 'Sravan', 'Pear', 4894],
39
+ ['North', 'Xi', 'Grape', 7580],
40
+ ['South', 'Hector', 'Apple', 9814]
41
+ ]
42
+
43
+ row_num = 1
44
+ data.each do |row_data|
45
+ worksheet.write_row(row_num, 0, row_data)
46
+ row_num += 1
47
+ end
48
+ end
49
+
50
+ # Create a new workbook called simple.xls and add a worksheet
51
+ workbook = WriteXLSX.new('dynamic_arrays.xlsx')
52
+ worksheet1 = workbook.add_worksheet('Filter')
53
+ worksheet2 = workbook.add_worksheet('Unique')
54
+ worksheet3 = workbook.add_worksheet('Sort')
55
+ worksheet4 = workbook.add_worksheet('Sortby')
56
+ worksheet5 = workbook.add_worksheet('Xlookup')
57
+ worksheet6 = workbook.add_worksheet('Xmatch')
58
+ worksheet7 = workbook.add_worksheet('Randarray')
59
+ worksheet8 = workbook.add_worksheet('Sequence')
60
+ worksheet9 = workbook.add_worksheet('Spill ranges')
61
+ worksheet10 = workbook.add_worksheet('Older functions')
62
+ header1 = workbook.add_format(fg_color: '#74AC4C', color: '#FFFFFF')
63
+ header2 = workbook.add_format(fg_color: '#528FD3', color: '#FFFFFF')
64
+
65
+ #
66
+ # Example of using the FILTER() function.
67
+ #
68
+ worksheet1.write('F2', '=FILTER(A1:D17,C1:C17=K2)')
69
+
70
+ # Write the data the function will work on.
71
+ worksheet1.write('K1', 'Product', header2)
72
+ worksheet1.write('K2', 'Apple')
73
+ worksheet1.write('F1', 'Region', header2)
74
+ worksheet1.write('G1', 'Sales Rep', header2)
75
+ worksheet1.write('H1', 'Product', header2)
76
+ worksheet1.write('I1', 'Units', header2)
77
+
78
+ write_worksheet_data(worksheet1, header1)
79
+ worksheet1.set_column_pixels('E:E', 20)
80
+ worksheet1.set_column_pixels('J:J', 20)
81
+
82
+ #
83
+ # Example of using the UNIQUE() function.
84
+ #
85
+ worksheet2.write('F2', '=UNIQUE(B2:B17)')
86
+
87
+ # A more complex example combining SORT and UNIQUE.
88
+ worksheet2.write('H2', '=SORT(UNIQUE(B2:B17))')
89
+
90
+ # Write the data the function will work on.
91
+ worksheet2.write('F1', 'Sales Rep', header2)
92
+ worksheet2.write('H1', 'Sales Rep', header2)
93
+
94
+ write_worksheet_data(worksheet2, header1)
95
+ worksheet2.set_column_pixels('E:E', 20)
96
+ worksheet2.set_column_pixels('G:G', 20)
97
+
98
+ #
99
+ # Example of using the SORT() function.
100
+ #
101
+ worksheet3.write('F2', '=SORT(B2:B17)')
102
+
103
+ # A more complex example combining SORT and FILTER.
104
+ worksheet3.write('H2', '=SORT(FILTER(C2:D17,D2:D17>5000,""),2,1)')
105
+
106
+ # Write the data the function will work on.
107
+ worksheet3.write('F1', 'Sales Rep', header2)
108
+ worksheet3.write('H1', 'Product', header2)
109
+ worksheet3.write('I1', 'Units', header2)
110
+
111
+ write_worksheet_data(worksheet3, header1)
112
+ worksheet3.set_column_pixels('E:E', 20)
113
+ worksheet3.set_column_pixels('G:G', 20)
114
+
115
+ #
116
+ # Example of using the SORTBY() function.
117
+ #
118
+ worksheet4.write('D2', '=SORTBY(A2:B9,B2:B9)')
119
+
120
+ # Write the data the function will work on.
121
+ worksheet4.write('A1', 'Name', header1)
122
+ worksheet4.write('B1', 'Age', header1)
123
+
124
+ worksheet4.write('A2', 'Tom')
125
+ worksheet4.write('A3', 'Fred')
126
+ worksheet4.write('A4', 'Amy')
127
+ worksheet4.write('A5', 'Sal')
128
+ worksheet4.write('A6', 'Fritz')
129
+ worksheet4.write('A7', 'Srivan')
130
+ worksheet4.write('A8', 'Xi')
131
+ worksheet4.write('A9', 'Hector')
132
+
133
+ worksheet4.write('B2', 52)
134
+ worksheet4.write('B3', 65)
135
+ worksheet4.write('B4', 22)
136
+ worksheet4.write('B5', 73)
137
+ worksheet4.write('B6', 19)
138
+ worksheet4.write('B7', 39)
139
+ worksheet4.write('B8', 19)
140
+ worksheet4.write('B9', 66)
141
+
142
+ worksheet4.write('D1', 'Name', header2)
143
+ worksheet4.write('E1', 'Age', header2)
144
+
145
+ worksheet4.set_column_pixels('C:C', 20)
146
+
147
+ #
148
+ # Example of using the XLOOKUP() function.
149
+ #
150
+ worksheet5.write('F1', '=XLOOKUP(E1,A2:A9,C2:C9)')
151
+
152
+ # Write the data the function will work on.
153
+ worksheet5.write('A1', 'Country', header1)
154
+ worksheet5.write('B1', 'Abr', header1)
155
+ worksheet5.write('C1', 'Prefix', header1)
156
+
157
+ worksheet5.write('A2', 'China')
158
+ worksheet5.write('A3', 'India')
159
+ worksheet5.write('A4', 'United States')
160
+ worksheet5.write('A5', 'Indonesia')
161
+ worksheet5.write('A6', 'Brazil')
162
+ worksheet5.write('A7', 'Pakistan')
163
+ worksheet5.write('A8', 'Nigeria')
164
+ worksheet5.write('A9', 'Bangladesh')
165
+
166
+ worksheet5.write('B2', 'CN')
167
+ worksheet5.write('B3', 'IN')
168
+ worksheet5.write('B4', 'US')
169
+ worksheet5.write('B5', 'ID')
170
+ worksheet5.write('B6', 'BR')
171
+ worksheet5.write('B7', 'PK')
172
+ worksheet5.write('B8', 'NG')
173
+ worksheet5.write('B9', 'BD')
174
+
175
+ worksheet5.write('C2', 86)
176
+ worksheet5.write('C3', 91)
177
+ worksheet5.write('C4', 1)
178
+ worksheet5.write('C5', 62)
179
+ worksheet5.write('C6', 55)
180
+ worksheet5.write('C7', 92)
181
+ worksheet5.write('C8', 234)
182
+ worksheet5.write('C9', 880)
183
+
184
+ worksheet5.write('E1', 'Brazil', header2)
185
+
186
+ worksheet5.set_column_pixels('A:A', 100)
187
+ worksheet5.set_column_pixels('D:D', 20)
188
+
189
+ #
190
+ # Example of using the XMATCH() function.
191
+ #
192
+ worksheet6.write('D2', '=XMATCH(C2,A2:A6)')
193
+
194
+ # Write the data the function will work on.
195
+ worksheet6.write('A1', 'Product', header1)
196
+
197
+ worksheet6.write('A2', 'Apple')
198
+ worksheet6.write('A3', 'Grape')
199
+ worksheet6.write('A4', 'Pear')
200
+ worksheet6.write('A5', 'Banana')
201
+ worksheet6.write('A6', 'Cherry')
202
+
203
+ worksheet6.write('C1', 'Product', header2)
204
+ worksheet6.write('D1', 'Position', header2)
205
+ worksheet6.write('C2', 'Grape')
206
+
207
+ worksheet6.set_column_pixels('B:B', 20)
208
+
209
+ #
210
+ # Example of using the RANDARRAY() function.
211
+ #
212
+ worksheet7.write('A1', '=RANDARRAY(5,3,1,100, TRUE)')
213
+
214
+ #
215
+ # Example of using the SEQUENCE() function.
216
+ #
217
+ worksheet8.write('A1', '=SEQUENCE(4,5)')
218
+
219
+ #
220
+ # Example of using the Spill range operator.
221
+ #
222
+ worksheet9.write('H2', '=ANCHORARRAY(F2)')
223
+
224
+ worksheet9.write('J2', '=COUNTA(ANCHORARRAY(F2))')
225
+
226
+ # Write the data the to work on.
227
+ worksheet9.write('F2', '=UNIQUE(B2:B17)')
228
+ worksheet9.write('F1', 'Unique', header2)
229
+ worksheet9.write('H1', 'Spill', header2)
230
+ worksheet9.write('J1', 'Spill', header2)
231
+
232
+ write_worksheet_data(worksheet9, header1)
233
+ worksheet9.set_column_pixels('E:E', 20)
234
+ worksheet9.set_column_pixels('G:G', 20)
235
+ worksheet9.set_column_pixels('I:I', 20)
236
+ #
237
+ # Example of using dynamic ranges with older Excel functions.
238
+ #
239
+ worksheet10.write_dynamic_array_formula('B1:B3', '=LEN(A1:A3)')
240
+
241
+ # Write the data the to work on.
242
+ worksheet10.write('A1', 'Foo')
243
+ worksheet10.write('A2', 'Food')
244
+ worksheet10.write('A3', 'Frood')
245
+
246
+ # Close the workbook.
247
+ workbook.close
data/examples/formats.rb CHANGED
@@ -18,8 +18,8 @@ require 'write_xlsx'
18
18
  workbook = WriteXLSX.new('formats.xlsx')
19
19
 
20
20
  # Some common formats
21
- center = workbook.add_format(:align => 'center')
22
- heading = workbook.add_format(:align => 'center', :bold => 1)
21
+ center = workbook.add_format(align: 'center')
22
+ heading = workbook.add_format(align: 'center', bold: 1)
23
23
 
24
24
  # The named colors
25
25
  colors = {
@@ -61,8 +61,8 @@ def intro(workbook, _center, _heading, _colors)
61
61
  format2.set_color('blue')
62
62
 
63
63
  format3 = workbook.add_format(
64
- :color => 'blue',
65
- :underline => 1
64
+ color: 'blue',
65
+ underline: 1
66
66
  )
67
67
 
68
68
  worksheet.write(2, 0, 'This workbook demonstrates some of', format)
@@ -113,9 +113,9 @@ def named_colors(workbook, center, heading, colors)
113
113
  [33, 11, 53, 17, 22, 18, 13, 16, 23, 9, 12, 15, 14, 20, 8, 10].each do |index|
114
114
  color = colors[index]
115
115
  format = workbook.add_format(
116
- :bg_color => color,
117
- :pattern => 1,
118
- :border => 1
116
+ bg_color: color,
117
+ pattern: 1,
118
+ border: 1
119
119
  )
120
120
 
121
121
  worksheet.write(i + 1, 0, index, center)
@@ -142,9 +142,9 @@ def standard_colors(workbook, center, heading, colors)
142
142
 
143
143
  (8..63).each do |i|
144
144
  format = workbook.add_format(
145
- :bg_color => i,
146
- :pattern => 1,
147
- :border => 1
145
+ bg_color: i,
146
+ pattern: 1,
147
+ border: 1
148
148
  )
149
149
 
150
150
  worksheet.write((i - 7), 0, i, center)
@@ -24,10 +24,10 @@ worksheet.set_selection('B1')
24
24
 
25
25
  # Add a sample format.
26
26
  red_format = workbook.add_format(
27
- :color => 'red',
28
- :bold => 1,
29
- :underline => 1,
30
- :size => 12
27
+ color: 'red',
28
+ bold: 1,
29
+ underline: 1,
30
+ size: 12
31
31
  )
32
32
 
33
33
  # Add an alternate description string to the URL.
@@ -25,8 +25,8 @@ worksheet.write_formula('C6', '=1/0')
25
25
 
26
26
  # Turn off some of the warnings:
27
27
  worksheet.ignore_errors(
28
- :number_stored_as_text => 'C3',
29
- :eval_error => 'C6'
28
+ number_stored_as_text: 'C3',
29
+ eval_error: 'C6'
30
30
  )
31
31
 
32
32
  # Write some descriptions for the cells and make the column wider for clarity.
data/examples/indent.rb CHANGED
@@ -16,8 +16,8 @@ require 'write_xlsx'
16
16
  workbook = WriteXLSX.new('indent.xlsx')
17
17
 
18
18
  worksheet = workbook.add_worksheet
19
- indent1 = workbook.add_format(:indent => 1)
20
- indent2 = workbook.add_format(:indent => 2)
19
+ indent1 = workbook.add_format(indent: 1)
20
+ indent2 = workbook.add_format(indent: 2)
21
21
 
22
22
  worksheet.set_column('A:A', 40)
23
23
 
@@ -0,0 +1,43 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+
4
+ #######################################################################
5
+ #
6
+ # An example of using the new Excel LAMBDA() function with the
7
+ # WriteXLSX rubygem. Note, this function is only currently available
8
+ # if you are subscribed to the Microsoft Office Beta program.
9
+ #
10
+ # Copyright 2000-2021, John McNamara, jmcnamara@cpan.org
11
+ # convert to ruby by Hideo NAKAMURA, nakamura.hideo@gmail.com
12
+ #
13
+
14
+ require 'write_xlsx'
15
+
16
+ workbook = WriteXLSX.new('lambda.xlsx')
17
+ worksheet = workbook.add_worksheet
18
+
19
+ worksheet.write(
20
+ 'A1',
21
+ 'Note: Lambda functions currently only work with the Beta Channel versions of Excel 365'
22
+ )
23
+
24
+ # Write a Lambda function to convert Fahrenheit to Celsius to a cell.
25
+ #
26
+ # Note that the lambda function parameters must be prefixed with
27
+ # "_xlpm.". These prefixes won't show up in Excel.
28
+ worksheet.write('A2', '=LAMBDA(_xlpm.temp, (5/9) * (_xlpm.temp-32))(32)')
29
+
30
+ # Create the same formula (without an argument) as a defined name and use that
31
+ # to calculate a value.
32
+ #
33
+ # Note that the formula name is prefixed with "_xlfn." (this is normally
34
+ # converted automatically by write_formula but isn't for defined names)
35
+ # and note that the lambda function parameters are prefixed with
36
+ # "_xlpm.". These prefixes won't show up in Excel.
37
+ workbook.define_name(
38
+ 'ToCelsius',
39
+ '=_xlfn.LAMBDA(_xlpm.temp, (5/9) * (_xlpm.temp-32))'
40
+ )
41
+ worksheet.write_dynamic_array_formula('A3', '=ToCelsius(212)')
42
+
43
+ workbook.close
data/examples/macros.rb CHANGED
@@ -32,10 +32,10 @@ worksheet.write('A3', 'Press the button to say hello.')
32
32
  # Add a button tied to a macro in the VBA project.
33
33
  worksheet.insert_button(
34
34
  'B3',
35
- :macro => 'say_hello',
36
- :caption => 'Press Me',
37
- :width => 80,
38
- :height => 30
35
+ macro: 'say_hello',
36
+ caption: 'Press Me',
37
+ width: 80,
38
+ height: 30
39
39
  )
40
40
 
41
41
  workbook.close
data/examples/merge1.rb CHANGED
@@ -24,7 +24,7 @@ worksheet.set_column('B:D', 20)
24
24
  worksheet.set_row(2, 30)
25
25
 
26
26
  # Create a merge format
27
- format = workbook.add_format(:center_across => 1)
27
+ format = workbook.add_format(center_across: 1)
28
28
 
29
29
  # Only one cell should contain text, the others should be blank.
30
30
  worksheet.write(2, 1, "Center across selection", format)
data/examples/merge2.rb CHANGED
@@ -26,15 +26,15 @@ worksheet.set_row(2, 40)
26
26
 
27
27
  # Create a merged format
28
28
  format = workbook.add_format(
29
- :center_across => 1,
30
- :bold => 1,
31
- :size => 15,
32
- :pattern => 1,
33
- :border => 6,
34
- :color => 'white',
35
- :fg_color => 'green',
36
- :border_color => 'yellow',
37
- :align => 'vcenter'
29
+ center_across: 1,
30
+ bold: 1,
31
+ size: 15,
32
+ pattern: 1,
33
+ border: 6,
34
+ color: 'white',
35
+ fg_color: 'green',
36
+ border_color: 'yellow',
37
+ align: 'vcenter'
38
38
  )
39
39
 
40
40
  # Only one cell should contain text, the others should be blank.
data/examples/merge3.rb CHANGED
@@ -25,11 +25,11 @@ worksheet.set_column('B:D', 20)
25
25
  # Example: Merge cells containing a hyperlink using merge_range().
26
26
  #
27
27
  format = workbook.add_format(
28
- :border => 1,
29
- :underline => 1,
30
- :color => 'blue',
31
- :align => 'center',
32
- :valign => 'vcenter'
28
+ border: 1,
29
+ underline: 1,
30
+ color: 'blue',
31
+ align: 'center',
32
+ valign: 'vcenter'
33
33
  )
34
34
 
35
35
  # Merge 3 cells
data/examples/merge4.rb CHANGED
@@ -25,11 +25,11 @@ worksheet.set_column('B:D', 20)
25
25
  # Example 1: Text centered vertically and horizontally
26
26
  #
27
27
  format1 = workbook.add_format(
28
- :border => 6,
29
- :bold => 1,
30
- :color => 'red',
31
- :valign => 'vcenter',
32
- :align => 'center'
28
+ border: 6,
29
+ bold: 1,
30
+ color: 'red',
31
+ valign: 'vcenter',
32
+ align: 'center'
33
33
  )
34
34
 
35
35
  worksheet.merge_range('B2:D3', 'Vertical and horizontal', format1)
@@ -39,11 +39,11 @@ worksheet.merge_range('B2:D3', 'Vertical and horizontal', format1)
39
39
  # Example 2: Text aligned to the top and left
40
40
  #
41
41
  format2 = workbook.add_format(
42
- :border => 6,
43
- :bold => 1,
44
- :color => 'red',
45
- :valign => 'top',
46
- :align => 'left'
42
+ border: 6,
43
+ bold: 1,
44
+ color: 'red',
45
+ valign: 'top',
46
+ align: 'left'
47
47
  )
48
48
 
49
49
  worksheet.merge_range('B5:D6', 'Aligned to the top and left', format2)
@@ -53,11 +53,11 @@ worksheet.merge_range('B5:D6', 'Aligned to the top and left', format2)
53
53
  # Example 3: Text aligned to the bottom and right
54
54
  #
55
55
  format3 = workbook.add_format(
56
- :border => 6,
57
- :bold => 1,
58
- :color => 'red',
59
- :valign => 'bottom',
60
- :align => 'right'
56
+ border: 6,
57
+ bold: 1,
58
+ color: 'red',
59
+ valign: 'bottom',
60
+ align: 'right'
61
61
  )
62
62
 
63
63
  worksheet.merge_range('B8:D9', 'Aligned to the bottom and right', format3)
@@ -67,11 +67,11 @@ worksheet.merge_range('B8:D9', 'Aligned to the bottom and right', format3)
67
67
  # Example 4: Text justified (i.e. wrapped) in the cell
68
68
  #
69
69
  format4 = workbook.add_format(
70
- :border => 6,
71
- :bold => 1,
72
- :color => 'red',
73
- :valign => 'top',
74
- :align => 'justify'
70
+ border: 6,
71
+ bold: 1,
72
+ color: 'red',
73
+ valign: 'top',
74
+ align: 'justify'
75
75
  )
76
76
 
77
77
  worksheet.merge_range('B11:D12', 'Justified: ' << ('so on and ' * 18), format4)
data/examples/merge5.rb CHANGED
@@ -26,12 +26,12 @@ worksheet = workbook.add_worksheet
26
26
  # Rotation 1, letters run from top to bottom
27
27
  #
28
28
  format1 = workbook.add_format(
29
- :border => 6,
30
- :bold => 1,
31
- :color => 'red',
32
- :valign => 'vcentre',
33
- :align => 'centre',
34
- :rotation => 270
29
+ border: 6,
30
+ bold: 1,
31
+ color: 'red',
32
+ valign: 'vcentre',
33
+ align: 'centre',
34
+ rotation: 270
35
35
  )
36
36
 
37
37
  worksheet.merge_range('B4:B9', 'Rotation 270', format1)
@@ -41,12 +41,12 @@ worksheet.merge_range('B4:B9', 'Rotation 270', format1)
41
41
  # Rotation 2, 90ー anticlockwise
42
42
  #
43
43
  format2 = workbook.add_format(
44
- :border => 6,
45
- :bold => 1,
46
- :color => 'red',
47
- :valign => 'vcentre',
48
- :align => 'centre',
49
- :rotation => 90
44
+ border: 6,
45
+ bold: 1,
46
+ color: 'red',
47
+ valign: 'vcentre',
48
+ align: 'centre',
49
+ rotation: 90
50
50
  )
51
51
 
52
52
  worksheet.merge_range('D4:D9', 'Rotation 90', format2)
@@ -56,12 +56,12 @@ worksheet.merge_range('D4:D9', 'Rotation 90', format2)
56
56
  # Rotation 3, 90ー clockwise
57
57
  #
58
58
  format3 = workbook.add_format(
59
- :border => 6,
60
- :bold => 1,
61
- :color => 'red',
62
- :valign => 'vcentre',
63
- :align => 'centre',
64
- :rotation => -90
59
+ border: 6,
60
+ bold: 1,
61
+ color: 'red',
62
+ valign: 'vcentre',
63
+ align: 'centre',
64
+ rotation: -90
65
65
  )
66
66
 
67
67
  worksheet.merge_range('F4:F9', 'Rotation -90', format3)
data/examples/merge6.rb CHANGED
@@ -22,13 +22,13 @@ worksheet.set_column('B:D', 25)
22
22
 
23
23
  # Format for the merged cells.
24
24
  format = workbook.add_format(
25
- :border => 6,
26
- :bold => 1,
27
- :color => 'red',
28
- :size => 20,
29
- :valign => 'vcentre',
30
- :align => 'left',
31
- :indent => 1
25
+ border: 6,
26
+ bold: 1,
27
+ color: 'red',
28
+ size: 20,
29
+ valign: 'vcentre',
30
+ align: 'left',
31
+ indent: 1
32
32
  )
33
33
 
34
34
  ###############################################################################
data/examples/outline.rb CHANGED
@@ -74,7 +74,7 @@ worksheet3 = workbook.add_worksheet('Outline Columns')
74
74
  worksheet4 = workbook.add_worksheet('Outline levels')
75
75
 
76
76
  # Add a general format
77
- bold = workbook.add_format(:bold => 1)
77
+ bold = workbook.add_format(bold: 1)
78
78
 
79
79
  ###############################################################################
80
80
  #
@@ -24,7 +24,7 @@ worksheet5 = workbook.add_worksheet('Outline Columns')
24
24
  worksheet6 = workbook.add_worksheet('Collapsed Columns')
25
25
 
26
26
  # Add a general format
27
- bold = workbook.add_format(:bold => 1)
27
+ bold = workbook.add_format(bold: 1)
28
28
 
29
29
  ###############################################################################
30
30
  #
data/examples/panes.rb CHANGED
@@ -37,12 +37,12 @@ worksheet4.split_panes(15, 8.43) # 1 row and column
37
37
  #
38
38
 
39
39
  header = workbook.add_format(
40
- :align => 'center',
41
- :valign => 'vcenter',
42
- :fg_color => '#C3FFC0'
40
+ align: 'center',
41
+ valign: 'vcenter',
42
+ fg_color: '#C3FFC0'
43
43
  )
44
44
 
45
- center = workbook.add_format(:align => 'center')
45
+ center = workbook.add_format(align: 'center')
46
46
 
47
47
  #######################################################################
48
48
  #
@@ -15,15 +15,15 @@ workbook = WriteXLSX.new('properties.xlsx')
15
15
  worksheet = workbook.add_worksheet
16
16
 
17
17
  workbook.set_properties(
18
- :title => 'This is an example spreadsheet',
19
- :subject => 'With document properties',
20
- :author => 'John McNamara',
21
- :manager => 'Dr. Heinz Doofenshmirtz',
22
- :company => 'of Wolves',
23
- :category => 'Example spreadsheets',
24
- :keywords => 'Sample, Example, Properties',
25
- :comments => 'Created with Perl and Excel::Writer::XLSX',
26
- :status => 'Quo'
18
+ title: 'This is an example spreadsheet',
19
+ subject: 'With document properties',
20
+ author: 'John McNamara',
21
+ manager: 'Dr. Heinz Doofenshmirtz',
22
+ company: 'of Wolves',
23
+ category: 'Example spreadsheets',
24
+ keywords: 'Sample, Example, Properties',
25
+ comments: 'Created with Perl and Excel::Writer::XLSX',
26
+ status: 'Quo'
27
27
  )
28
28
 
29
29
  worksheet.set_column('A:A', 70)
@@ -7,8 +7,8 @@ workbook = WriteXLSX.new('protection.xlsx')
7
7
  worksheet = workbook.add_worksheet
8
8
 
9
9
  # Create some format objects
10
- unlocked = workbook.add_format(:locked => 0)
11
- hidden = workbook.add_format(:hidden => 1)
10
+ unlocked = workbook.add_format(locked: 0)
11
+ hidden = workbook.add_format(hidden: 1)
12
12
 
13
13
  # Format the columns
14
14
  worksheet.set_column('A:A', 45)