write_xlsx 0.64.1 → 0.65.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/README.rdoc +10 -1
  3. data/examples/conditional_format.rb +251 -18
  4. data/examples/demo.rb +2 -3
  5. data/examples/macros.rb +42 -0
  6. data/examples/outline_collapsed.rb +160 -0
  7. data/examples/republic.png +0 -0
  8. data/examples/shape3.rb +2 -2
  9. data/examples/shape4.rb +5 -5
  10. data/examples/shape5.rb +6 -6
  11. data/examples/shape6.rb +6 -6
  12. data/examples/shape7.rb +11 -11
  13. data/examples/shape8.rb +10 -10
  14. data/examples/shape_all.rb +0 -0
  15. data/examples/vbaProject.bin +0 -0
  16. data/lib/write_xlsx/chart.rb +656 -56
  17. data/lib/write_xlsx/chartsheet.rb +26 -2
  18. data/lib/write_xlsx/format.rb +50 -27
  19. data/lib/write_xlsx/formats.rb +32 -0
  20. data/lib/write_xlsx/package/packager.rb +45 -238
  21. data/lib/write_xlsx/package/table.rb +9 -18
  22. data/lib/write_xlsx/package/xml_writer_simple.rb +26 -9
  23. data/lib/write_xlsx/sheets.rb +223 -0
  24. data/lib/write_xlsx/sparkline.rb +140 -4
  25. data/lib/write_xlsx/version.rb +1 -1
  26. data/lib/write_xlsx/workbook.rb +34 -121
  27. data/lib/write_xlsx/worksheet/data_validation.rb +291 -0
  28. data/lib/write_xlsx/worksheet/hyperlink.rb +111 -0
  29. data/lib/write_xlsx/worksheet/page_setup.rb +170 -0
  30. data/lib/write_xlsx/worksheet.rb +1112 -1334
  31. data/test/helper.rb +1 -1
  32. data/test/package/styles/test_styles_01.rb +1 -10
  33. data/test/package/styles/test_styles_02.rb +1 -10
  34. data/test/package/styles/test_styles_03.rb +1 -10
  35. data/test/package/styles/test_styles_04.rb +1 -10
  36. data/test/package/styles/test_styles_05.rb +1 -10
  37. data/test/package/styles/test_styles_06.rb +1 -10
  38. data/test/package/styles/test_styles_07.rb +1 -10
  39. data/test/package/styles/test_styles_08.rb +1 -10
  40. data/test/package/styles/test_styles_09.rb +1 -10
  41. data/test/perl_output/conditional_format.xlsx +0 -0
  42. data/test/perl_output/outline_collapsed.xlsx +0 -0
  43. data/test/perl_output/protection.xlsx +0 -0
  44. data/test/regression/test_chart_gap01.rb +47 -0
  45. data/test/regression/test_chart_gap02.rb +47 -0
  46. data/test/regression/test_chart_gap03.rb +47 -0
  47. data/test/regression/test_format05.rb +26 -0
  48. data/test/regression/test_rich_string12.rb +32 -0
  49. data/test/regression/xlsx_files/chart_gap01.xlsx +0 -0
  50. data/test/regression/xlsx_files/chart_gap02.xlsx +0 -0
  51. data/test/regression/xlsx_files/chart_gap03.xlsx +0 -0
  52. data/test/regression/xlsx_files/format05.xlsx +0 -0
  53. data/test/regression/xlsx_files/rich_string12.xlsx +0 -0
  54. data/test/test_example_match.rb +253 -20
  55. data/test/worksheet/test_set_column.rb +25 -0
  56. data/test/worksheet/test_worksheet_03.rb +1 -1
  57. data/test/worksheet/test_worksheet_04.rb +1 -1
  58. data/test/worksheet/test_write_array_formula_01.rb +7 -0
  59. data/test/worksheet/test_write_col_breaks.rb +2 -2
  60. data/test/worksheet/test_write_col_info.rb +8 -8
  61. data/test/worksheet/test_write_conditional_formatting.rb +4 -4
  62. data/test/worksheet/test_write_formula_does_not_change_formula_string.rb +18 -0
  63. data/test/worksheet/test_write_header_footer.rb +8 -3
  64. data/test/worksheet/test_write_hyperlink.rb +10 -5
  65. data/test/worksheet/test_write_merge_cells.rb +6 -6
  66. data/test/worksheet/test_write_page_set_up_pr.rb +1 -1
  67. data/test/worksheet/test_write_page_setup.rb +1 -1
  68. data/test/worksheet/test_write_row_breaks.rb +2 -2
  69. data/test/worksheet/test_write_row_element.rb +1 -1
  70. data/test/worksheet/test_write_sheet_pr.rb +2 -2
  71. data/test/worksheet/test_write_sheet_view.rb +0 -9
  72. data/test/worksheet/test_write_url.rb +19 -0
  73. data/test/worksheet/test_write_worksheet_attributes.rb +21 -0
  74. metadata +38 -5
  75. data/lib/write_xlsx/worksheet/print_style.rb +0 -51
  76. data/test/worksheet/test_write_worksheet.rb +0 -19
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8c364d46a510e23e976941e667f64e828966e67c
4
- data.tar.gz: 5d395615effa546f49df304d0ce8c4ee7c151507
3
+ metadata.gz: 30c458c96dc291036baa7b64c8099b044c10e18c
4
+ data.tar.gz: 589e734bee933c9ab1f0904f59ce69f101251159
5
5
  SHA512:
6
- metadata.gz: 89064c672d2a9fd303234f0e327930ff41bd1d1a21908b9afb1182310eb4bebb8f802e3c174bf86b2f0390bed5e4b850e0173bb2b80ae13a632b27a04242e3e8
7
- data.tar.gz: 8dcfd96eecba6faa2c9d5eb7336d87178db710d38318d62e1e6ab0b391d23217f96da25b17f51b2fcf01ee0625416fa31b1f7baf008e1bc79a91466f17cd0eda
6
+ metadata.gz: 1865380215d25cfa2e16af387be17263669fb62bea666e75f10f1f2719450120eed303aaea7f457ac60514af0d323c8552409bfacdae573ae19b4349cb42c5f7
7
+ data.tar.gz: 645cd41d3b387e77448b97494ccd87f2f39a29a49b21202f699b99a776845ef0d159044283556ae57ef0d2b0ff5fcc6a35ab4390a6da205ef8c557d1b46db368
data/README.rdoc CHANGED
@@ -1,6 +1,6 @@
1
1
  = write_xlsx
2
2
 
3
- gem to create a new file in the Excel 2007+ XLSX format, and you can use the same interface as writeexcel gem. write_xlsx is converted from Perl's module Excel::Writer::XLSX-0.63, https://github.com/jmcnamara/excel-writer-xlsx .
3
+ gem to create a new file in the Excel 2007+ XLSX format, and you can use the same interface as writeexcel gem. write_xlsx is converted from Perl's module Excel::Writer::XLSX-0.65, https://github.com/jmcnamara/excel-writer-xlsx .
4
4
 
5
5
  == Description
6
6
 
@@ -75,6 +75,15 @@ the first worksheet in an Excel XML spreadsheet called ruby.xlsx:
75
75
  workbook.close
76
76
 
77
77
  == Recent change
78
+ 2013-03-23 v0.65.0
79
+ Added options to format series Gap/Overlap for Bar/Column charts.
80
+
81
+ Bug fix in Worksheet#write_formula
82
+ (write_formula change original formula string)
83
+
84
+ Bug fix in Worksheet#set_column
85
+ (failure when parameter level is out of range)
86
+
78
87
  2013-03-06 v0.64.1
79
88
  Bug fix in handling utf-8 string under ruby 1.8.7
80
89
  (examples/demo.rb failed under ruby 1.8.7)
@@ -6,6 +6,13 @@ require 'write_xlsx'
6
6
 
7
7
  workbook = WriteXLSX.new('conditional_format.xlsx')
8
8
  worksheet1 = workbook.add_worksheet
9
+ worksheet2 = workbook.add_worksheet
10
+ worksheet3 = workbook.add_worksheet
11
+ worksheet4 = workbook.add_worksheet
12
+ worksheet5 = workbook.add_worksheet
13
+ worksheet6 = workbook.add_worksheet
14
+ worksheet7 = workbook.add_worksheet
15
+ worksheet8 = workbook.add_worksheet
9
16
 
10
17
  # Light red fill with dark red text.
11
18
  format1 = workbook.add_format(
@@ -21,24 +28,24 @@ format2 = workbook.add_format(
21
28
 
22
29
  # Some sample data to run the conditional formatting against.
23
30
  data = [
24
- [ 90, 80, 50, 10, 20, 90, 40, 90, 30, 40 ],
25
- [ 20, 10, 90, 100, 30, 60, 70, 60, 50, 90 ],
26
- [ 10, 50, 60, 50, 20, 50, 80, 30, 40, 60 ],
27
- [ 10, 90, 20, 40, 10, 40, 50, 70, 90, 50 ],
28
- [ 70, 100, 10, 90, 10, 10, 20, 100, 100, 40 ],
29
- [ 20, 60, 10, 100, 30, 10, 20, 60, 100, 10 ],
30
- [ 10, 60, 10, 80, 100, 80, 30, 30, 70, 40 ],
31
- [ 30, 90, 60, 10, 10, 100, 40, 40, 30, 40 ],
32
- [ 80, 90, 10, 20, 20, 50, 80, 20, 60, 90 ],
33
- [ 60, 80, 30, 30, 10, 50, 80, 60, 50, 30 ]
31
+ [ 34, 72, 38, 30, 75, 48, 75, 66, 84, 86 ],
32
+ [ 6, 24, 1, 84, 54, 62, 60, 3, 26, 59 ],
33
+ [ 28, 79, 97, 13, 85, 93, 93, 22, 5, 14 ],
34
+ [ 27, 71, 40, 17, 18, 79, 90, 93, 29, 47 ],
35
+ [ 88, 25, 33, 23, 67, 1, 59, 79, 47, 36 ],
36
+ [ 24, 100, 20, 88, 29, 33, 38, 54, 54, 88 ],
37
+ [ 6, 57, 88, 28, 10, 26, 37, 7, 41, 48 ],
38
+ [ 52, 78, 1, 96, 26, 45, 47, 33, 96, 36 ],
39
+ [ 60, 54, 81, 66, 81, 90, 80, 93, 12, 55 ],
40
+ [ 70, 5, 46, 14, 71, 19, 66, 36, 41, 21 ]
34
41
  ]
35
42
 
36
-
37
- # This example below highlights cells that have a value greater than or
38
- # equal to 50 in red and cells below that value in green.
39
-
43
+ ###############################################################################
44
+ #
45
+ # Example 1.
46
+ #
40
47
  caption = 'Cells with values >= 50 are in light red. ' +
41
- 'Values < 50 are in light green'
48
+ 'Values < 50 are in light green.'
42
49
 
43
50
  # Write the data.
44
51
  worksheet1.write('A1', caption)
@@ -48,9 +55,9 @@ worksheet1.write_col('B3', data)
48
55
  worksheet1.conditional_formatting('B3:K12',
49
56
  {
50
57
  :type => 'cell',
51
- :format => format1,
52
58
  :criteria => '>=',
53
- :value => 50
59
+ :value => 50,
60
+ :format => format1
54
61
  }
55
62
  )
56
63
 
@@ -58,9 +65,235 @@ worksheet1.conditional_formatting('B3:K12',
58
65
  worksheet1.conditional_formatting('B3:K12',
59
66
  {
60
67
  :type => 'cell',
68
+ :criteria => '<',
69
+ :value => 50,
70
+ :format => format2
71
+ }
72
+ )
73
+
74
+
75
+ ###############################################################################
76
+ #
77
+ # Example 2.
78
+ #
79
+ caption = 'Values between 30 and 70 are in light red. ' +
80
+ 'Values outside that range are in light green.'
81
+
82
+ worksheet2.write('A1', caption)
83
+ worksheet2.write_col('B3', data)
84
+
85
+ worksheet2.conditional_formatting('B3:K12',
86
+ {
87
+ :type => 'cell',
88
+ :criteria => 'between',
89
+ :minimum => 30,
90
+ :maximum => 70,
91
+ :format => format1
92
+ }
93
+ )
94
+
95
+ worksheet2.conditional_formatting('B3:K12',
96
+ {
97
+ :type => 'cell',
98
+ :criteria => 'not between',
99
+ :minimum => 30,
100
+ :maximum => 70,
101
+ :format => format2
102
+ }
103
+ )
104
+
105
+
106
+ ###############################################################################
107
+ #
108
+ # Example 3.
109
+ #
110
+ caption = 'Duplicate values are in light red. ' +
111
+ 'Unique values are in light green.'
112
+
113
+ worksheet3.write('A1', caption)
114
+ worksheet3.write_col('B3', data)
115
+
116
+ worksheet3.conditional_formatting('B3:K12',
117
+ {
118
+ :type => 'duplicate',
119
+ :format => format1,
120
+ }
121
+ )
122
+
123
+ worksheet3.conditional_formatting('B3:K12',
124
+ {
125
+ :type => 'unique',
61
126
  :format => format2,
127
+ }
128
+ )
129
+
130
+
131
+ ###############################################################################
132
+ #
133
+ # Example 4.
134
+ #
135
+ caption = 'Above average values are in light red. ' +
136
+ 'Below average values are in light green.'
137
+
138
+ worksheet4.write('A1', caption)
139
+ worksheet4.write_col('B3', data)
140
+
141
+ worksheet4.conditional_formatting('B3:K12',
142
+ {
143
+ :type => 'average',
144
+ :criteria => 'above',
145
+ :format => format1
146
+ }
147
+ )
148
+
149
+ worksheet4.conditional_formatting('B3:K12',
150
+ {
151
+ :type => 'average',
152
+ :criteria => 'below',
153
+ :format => format2
154
+ }
155
+ )
156
+
157
+
158
+ ###############################################################################
159
+ #
160
+ # Example 5.
161
+ #
162
+ caption = 'Top 10 values are in light red. ' +
163
+ 'Bottom 10 values are in light green.'
164
+
165
+ worksheet5.write('A1', caption)
166
+ worksheet5.write_col('B3', data)
167
+
168
+ worksheet5.conditional_formatting('B3:K12',
169
+ {
170
+ :type => 'top',
171
+ :value => '10',
172
+ :format => format1
173
+ }
174
+ )
175
+
176
+ worksheet5.conditional_formatting('B3:K12',
177
+ {
178
+ :type => 'bottom',
179
+ :value => '10',
180
+ :format => format2
181
+ }
182
+ )
183
+
184
+
185
+ ###############################################################################
186
+ #
187
+ # Example 6.
188
+ #
189
+ caption = 'Cells with values >= 50 are in light red. ' +
190
+ 'Values < 50 are in light green. Non-contiguous ranges.'
191
+
192
+ # Write the data.
193
+ worksheet6.write('A1', caption)
194
+ worksheet6.write_col('B3', data)
195
+
196
+ # Write a conditional format over a range.
197
+ worksheet6.conditional_formatting('B3:K6,B9:K12',
198
+ {
199
+ :type => 'cell',
200
+ :criteria => '>=',
201
+ :value => 50,
202
+ :format => format1
203
+ }
204
+ )
205
+
206
+ # Write another conditional format over the same range.
207
+ worksheet6.conditional_formatting('B3:K6,B9:K12',
208
+ {
209
+ :type => 'cell',
62
210
  :criteria => '<',
63
- :value => 50
211
+ :value => 50,
212
+ :format => format2
213
+ }
214
+ )
215
+
216
+
217
+ ###############################################################################
218
+ #
219
+ # Example 7.
220
+ #
221
+ caption = 'Examples of color scales and data bars. Default colors.'
222
+
223
+ data = 1 .. 12
224
+
225
+ worksheet7.write('A1', caption)
226
+
227
+ worksheet7.write('B2', "2 Color Scale")
228
+ worksheet7.write_col('B3', data)
229
+
230
+ worksheet7.write('D2', "3 Color Scale")
231
+ worksheet7.write_col('D3', data)
232
+
233
+ worksheet7.write('F2', "Data Bars")
234
+ worksheet7.write_col('F3', data)
235
+
236
+
237
+ worksheet7.conditional_formatting('B3:B14',
238
+ {
239
+ :type => '2_color_scale'
240
+ }
241
+ )
242
+
243
+ worksheet7.conditional_formatting('D3:D14',
244
+ {
245
+ :type => '3_color_scale'
246
+ }
247
+ )
248
+
249
+ worksheet7.conditional_formatting('F3:F14',
250
+ {
251
+ :type => 'data_bar'
252
+ }
253
+ )
254
+
255
+
256
+ ###############################################################################
257
+ #
258
+ # Example 8.
259
+ #
260
+ caption = 'Examples of color scales and data bars. Modified colors.'
261
+
262
+ data = 1 .. 12
263
+
264
+ worksheet8.write('A1', caption)
265
+
266
+ worksheet8.write('B2', "2 Color Scale")
267
+ worksheet8.write_col('B3', data)
268
+
269
+ worksheet8.write('D2', "3 Color Scale")
270
+ worksheet8.write_col('D3', data)
271
+
272
+ worksheet8.write('F2', "Data Bars")
273
+ worksheet8.write_col('F3', data)
274
+
275
+
276
+ worksheet8.conditional_formatting('B3:B14',
277
+ {
278
+ :type => '2_color_scale',
279
+ :min_color => "#FF0000",
280
+ :max_color => "#00FF00"
281
+ }
282
+ )
283
+
284
+ worksheet8.conditional_formatting('D3:D14',
285
+ {
286
+ :type => '3_color_scale',
287
+ :min_color => "#C5D9F1",
288
+ :mid_color => "#8DB4E3",
289
+ :max_color => "#538ED5"
290
+ }
291
+ )
292
+
293
+ worksheet8.conditional_formatting('F3:F14',
294
+ {
295
+ :type => 'data_bar',
296
+ :bar_color => '#63C384'
64
297
  }
65
298
  )
66
299
 
data/examples/demo.rb CHANGED
@@ -88,9 +88,8 @@ worksheet.write('B9', 'http://www.ruby-lang.org/', hyperlink_format)
88
88
  #
89
89
  # Images
90
90
  #
91
- # Not implemented yet.
92
- #worksheet.write('A10', "Images")
93
- #worksheet.insert_image('B10', 'republic.png', 16, 8)
91
+ worksheet.write('A10', "Images")
92
+ worksheet.insert_image('B10', 'republic.png', 16, 8)
94
93
 
95
94
 
96
95
  #######################################################################
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+
4
+ #######################################################################
5
+ #
6
+ # An example of adding macros to an WriteXLSX file using VBA project file
7
+ # extracted from an existing Excel xlsm file.
8
+ #
9
+ # The +extract_vba.rb+ utility supplied with WriteXLSX can be used to extract
10
+ # the vbaProject.bin file.
11
+ #
12
+ # An embedded macro is connected to a form button on the worksheet.
13
+ #
14
+ # reverse(c), November 2012, John McNamara, jmcnamara@cpan.org
15
+ # convert to ruby by Hideo NAKAMURA, cxn03651@msj.biglobe.ne.jp
16
+ #
17
+
18
+ require 'rubygems'
19
+ require 'write_xlsx'
20
+
21
+ # Note the file extension should be .xlsm.
22
+ workbook = WriteXLSX.new('macros.xlsm')
23
+ worksheet = workbook.add_worksheet
24
+
25
+ worksheet.set_column('A:A', 30)
26
+
27
+ # Add the VBA project binary.
28
+ workbook.add_vba_project('./vbaProject.bin')
29
+
30
+ # Show text for the end user.
31
+ worksheet.write('A3', 'Press the button to say hello.')
32
+
33
+ # Add a button tied to a macro in the VBA project.
34
+ worksheet.insert_button(
35
+ 'B3',
36
+ :macro => 'say_hello',
37
+ :caption => 'Press Me',
38
+ :width => 80,
39
+ :height => 30
40
+ )
41
+
42
+ workbook.close
@@ -0,0 +1,160 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+
4
+ #
5
+ # Example of how to use Excel::Writer::XLSX to generate Excel outlines and
6
+ # grouping.
7
+ #
8
+ # These examples focus mainly on collapsed outlines. See also the
9
+ # outlines.pl example program for more general examples.
10
+ #
11
+ # reverse ('(c)'), March 2008, John McNamara, jmcnamara@cpan.org
12
+ # convert to ruby by Hideo NAKAMURA, cxn03651@msj.biglobe.ne.jp
13
+ #
14
+
15
+ require 'rubygems'
16
+ require 'write_xlsx'
17
+
18
+ # Create a new workbook and add some worksheets
19
+ workbook = WriteXLSX.new('outline.xlsx')
20
+ worksheet1 = workbook.add_worksheet('Outlined Rows')
21
+ worksheet2 = workbook.add_worksheet('Collapsed Rows 1')
22
+ worksheet3 = workbook.add_worksheet('Collapsed Rows 2')
23
+ worksheet4 = workbook.add_worksheet('Collapsed Rows 3')
24
+ worksheet5 = workbook.add_worksheet('Outline Columns')
25
+ worksheet6 = workbook.add_worksheet('Collapsed Columns')
26
+
27
+ # Add a general format
28
+ bold = workbook.add_format(:bold => 1)
29
+
30
+ ###############################################################################
31
+ #
32
+ # Example 1: Create a worksheet with outlined rows. It also includes SUBTOTAL()
33
+ # functions so that it looks like the type of automatic outlines that are
34
+ # generated when you use the Excel Data->SubTotals menu item.
35
+ #
36
+
37
+ # The syntax is: set_row(row, height, XF, hidden, level, collapsed)
38
+ worksheet1.set_row(1, nil, nil, 0, 2)
39
+ worksheet1.set_row(2, nil, nil, 0, 2)
40
+ worksheet1.set_row(3, nil, nil, 0, 2)
41
+ worksheet1.set_row(4, nil, nil, 0, 2)
42
+ worksheet1.set_row(5, nil, nil, 0, 1)
43
+
44
+ worksheet1.set_row(6, nil, nil, 0, 2)
45
+ worksheet1.set_row(7, nil, nil, 0, 2)
46
+ worksheet1.set_row(8, nil, nil, 0, 2)
47
+ worksheet1.set_row(9, nil, nil, 0, 2)
48
+ worksheet1.set_row(10, nil, nil, 0, 1)
49
+
50
+ # Write the sub-total data that is common to the row examples.
51
+ create_sub_totals(worksheet1, bold)
52
+
53
+ ###############################################################################
54
+ #
55
+ # Example 2: Create a worksheet with collapsed outlined rows.
56
+ # This is the same as the example 1 except that the all rows are collapsed.
57
+ # Note: We need to indicate the row that contains the collapsed symbol '+' with
58
+ # the optional parameter, collapsed.
59
+
60
+ worksheet2.set_row(1, nil, nil, 1, 2)
61
+ worksheet2.set_row(2, nil, nil, 1, 2)
62
+ worksheet2.set_row(3, nil, nil, 1, 2)
63
+ worksheet2.set_row(4, nil, nil, 1, 2)
64
+ worksheet2.set_row(5, nil, nil, 1, 1)
65
+
66
+ worksheet2.set_row(6, nil, nil, 1, 2)
67
+ worksheet2.set_row(7, nil, nil, 1, 2)
68
+ worksheet2.set_row(8, nil, nil, 1, 2)
69
+ worksheet2.set_row(9, nil, nil, 1, 2)
70
+ worksheet2.set_row(10, nil, nil, 1, 1)
71
+
72
+ worksheet2.set_row(11, nil, nil, 0, 0, 1)
73
+
74
+ # Write the sub-total data that is common to the row examples.
75
+ create_sub_totals(worksheet2, bold)
76
+
77
+ ###############################################################################
78
+ #
79
+ # Example 3: Create a worksheet with collapsed outlined rows.
80
+ # Same as the example 1 except that the two sub-totals are collapsed.
81
+
82
+ worksheet3.set_row(1, nil, nil, 1, 2)
83
+ worksheet3.set_row(2, nil, nil, 1, 2)
84
+ worksheet3.set_row(3, nil, nil, 1, 2)
85
+ worksheet3.set_row(4, nil, nil, 1, 2)
86
+ worksheet3.set_row(5, nil, nil, 0, 1, 1)
87
+
88
+ worksheet3.set_row(6, nil, nil, 1, 2)
89
+ worksheet3.set_row(7, nil, nil, 1, 2)
90
+ worksheet3.set_row(8, nil, nil, 1, 2)
91
+ worksheet3.set_row(9, nil, nil, 1, 2)
92
+ worksheet3.set_row(10, nil, nil, 0, 1, 1)
93
+
94
+ # Write the sub-total data that is common to the row examples.
95
+ create_sub_totals(worksheet3, bold)
96
+
97
+ ###############################################################################
98
+ #
99
+ # Example 4: Create a worksheet with outlined rows.
100
+ # Same as the example 1 except that the two sub-totals are collapsed.
101
+
102
+ worksheet4.set_row(1, nil, nil, 1, 2)
103
+ worksheet4.set_row(2, nil, nil, 1, 2)
104
+ worksheet4.set_row(3, nil, nil, 1, 2)
105
+ worksheet4.set_row(4, nil, nil, 1, 2)
106
+ worksheet4.set_row(5, nil, nil, 1, 1, 1)
107
+
108
+ worksheet4.set_row(6, nil, nil, 1, 2)
109
+ worksheet4.set_row(7, nil, nil, 1, 2)
110
+ worksheet4.set_row(8, nil, nil, 1, 2)
111
+ worksheet4.set_row(9, nil, nil, 1, 2)
112
+ worksheet4.set_row(10, nil, nil, 1, 1, 1)
113
+
114
+ worksheet4.set_row(11, nil, nil, 0, 0, 1)
115
+
116
+ # Write the sub-total data that is common to the row examples.
117
+ create_sub_totals(worksheet4, bold)
118
+
119
+ ###############################################################################
120
+ #
121
+ # Example 5: Create a worksheet with outlined columns.
122
+ #
123
+ data = [
124
+ [ 'Month', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Total' ],
125
+ [ 'North', 50, 20, 15, 25, 65, 80, '=SUM(B2:G2)' ],
126
+ [ 'South', 10, 20, 30, 50, 50, 50, '=SUM(B3:G3)' ],
127
+ [ 'East', 45, 75, 50, 15, 75, 100, '=SUM(B4:G4)' ],
128
+ [ 'West', 15, 15, 55, 35, 20, 50, '=SUM(B5:G6)' ]
129
+ ]
130
+
131
+ # Add bold format to the first row
132
+ worksheet5.set_row(0, nil, bold)
133
+
134
+ # Syntax: set_column(col1, col2, width, XF, hidden, level, collapsed)
135
+ worksheet5.set_column('A:A', 10, bold)
136
+ worksheet5.set_column('B:G', 5, nil, 0, 1)
137
+ worksheet5.set_column('H:H', 10)
138
+
139
+ # Write the data and a formula
140
+ worksheet5.write_col('A1', data)
141
+ worksheet5.write('H6', '=SUM(H2:H5)', bold)
142
+
143
+ ###############################################################################
144
+ #
145
+ # Example 6: Create a worksheet with collapsed outlined columns.
146
+ # This is the same as the previous example except collapsed columns.
147
+
148
+ # Add bold format to the first row
149
+ worksheet6.set_row(0, nil, bold)
150
+
151
+ # Syntax: set_column(col1, col2, width, XF, hidden, level, collapsed)
152
+ worksheet6.set_column('A:A', 10, bold)
153
+ worksheet6.set_column('B:G', 5, nil, 1, 1)
154
+ worksheet6.set_column('H:H', 10, nil, 0, 0, 1)
155
+
156
+ # Write the data and a formula
157
+ worksheet6.write_col('A1', data)
158
+ worksheet6.write('H6', '=SUM(H2:H5)', bold)
159
+
160
+ workbook.close
Binary file
data/examples/shape3.rb CHANGED
@@ -25,8 +25,8 @@ normal = workbook.add_shape(
25
25
  )
26
26
 
27
27
  worksheet.insert_shape('A1', normal, 50, 50)
28
- normal[:text] = 'Scaled 3w x 2h'
29
- normal[:name] = 'Hope'
28
+ normal.text = 'Scaled 3w x 2h'
29
+ normal.name = 'Hope'
30
30
  worksheet.insert_shape('A1', normal, 250, 50, 3, 2)
31
31
 
32
32
  workbook.close
data/examples/shape4.rb CHANGED
@@ -29,8 +29,8 @@ shape = workbook.add_shape(
29
29
  # Change the last 5 rectangles to stars. Previously
30
30
  # inserted shapes stay as rectangles.
31
31
  type = 'star5' if n == 6
32
- shape[:type] = type
33
- shape[:text] = "#{type} #{n}"
32
+ shape.type = type
33
+ shape.text = "#{type} #{n}"
34
34
  worksheet.insert_shape('A1', shape, n * 100, 50)
35
35
  end
36
36
 
@@ -42,14 +42,14 @@ stencil = workbook.add_shape(
42
42
  )
43
43
  worksheet.insert_shape('A1', stencil, 100, 150)
44
44
 
45
- stencil[:stencil] = 0
45
+ stencil.stencil = 0
46
46
  worksheet.insert_shape('A1', stencil, 200, 150)
47
47
  worksheet.insert_shape('A1', stencil, 300, 150)
48
48
 
49
49
  # Ooopa! Changed my mind.
50
50
  # Change the rectangle to an ellipse (circle),
51
51
  # for the last two shapes.
52
- stencil[:type] = 'ellipse'
53
- stencil[:text] = 'Now its a circle'
52
+ stencil.type = 'ellipse'
53
+ stencil.text = 'Now its a circle'
54
54
 
55
55
  workbook.close
data/examples/shape5.rb CHANGED
@@ -34,14 +34,14 @@ worksheet.insert_shape('A1', s2, 250, 200)
34
34
  cxn_shape = workbook.add_shape(:type => 'bentConnector3')
35
35
 
36
36
  # Link the start of the connector to the right side.
37
- cxn_shape[:start] = s1[:id]
38
- cxn_shape[:start_index] = 4 # 4th connection pt, clockwise from top(0).
39
- cxn_shape[:start_side] = 'b' # r)ight or b)ottom.
37
+ cxn_shape.start = s1.id
38
+ cxn_shape.start_index = 4 # 4th connection pt, clockwise from top(0).
39
+ cxn_shape.start_side = 'b' # r)ight or b)ottom.
40
40
 
41
41
  # Link the end of the connector to the left side.
42
- cxn_shape[:end] = s2[:id]
43
- cxn_shape[:end_index] = 0 # clockwise from top(0).
44
- cxn_shape[:end_side] = 't' # t)op.
42
+ cxn_shape.end = s2.id
43
+ cxn_shape.end_index = 0 # clockwise from top(0).
44
+ cxn_shape.end_side = 't' # t)op.
45
45
 
46
46
  worksheet.insert_shape('A1', cxn_shape, 0, 0)
47
47
 
data/examples/shape6.rb CHANGED
@@ -34,14 +34,14 @@ worksheet.insert_shape('A1', s2, 250, 200)
34
34
  cxn_shape = workbook.add_shape(:type => 'curvedConnector3')
35
35
 
36
36
  # Link the start of the connector to the right side.
37
- cxn_shape[:start] = s1[:id]
38
- cxn_shape[:start_index] = 2 # 2nd connection pt, clockwise from top(0).
39
- cxn_shape[:start_side] = 'r' # r)ight or b)ottom.
37
+ cxn_shape.start = s1.id
38
+ cxn_shape.start_index = 2 # 2nd connection pt, clockwise from top(0).
39
+ cxn_shape.start_side = 'r' # r)ight or b)ottom.
40
40
 
41
41
  # Link the end of the connector to the left side.
42
- cxn_shape[:end] = s2[:id]
43
- cxn_shape[:end_index] = 4 # 4th connection pt, clockwise from top(0).
44
- cxn_shape[:end_side] = 'l' # l)eft or t)op.
42
+ cxn_shape.end = s2.id
43
+ cxn_shape.end_index = 4 # 4th connection pt, clockwise from top(0).
44
+ cxn_shape.end_side = 'l' # l)eft or t)op.
45
45
 
46
46
  worksheet.insert_shape('A1', cxn_shape, 0, 0)
47
47
 
data/examples/shape7.rb CHANGED
@@ -47,28 +47,28 @@ plus = workbook.add_shape(
47
47
  p1 = worksheet.insert_shape('A1', plus, 350, 350)
48
48
  p2 = worksheet.insert_shape('A1', plus, 150, 350)
49
49
  p3 = worksheet.insert_shape('A1', plus, 350, 150)
50
- plus[:adjustments] = 35 # change shape of plus symbol.
50
+ plus.adjustments = 35 # change shape of plus symbol.
51
51
  p4 = worksheet.insert_shape('A1', plus, 150, 150)
52
52
 
53
53
  cxn_shape = workbook.add_shape(:type => 'bentConnector3', :fill => 0)
54
54
 
55
- cxn_shape[:start] = ellipse[:id]
56
- cxn_shape[:start_index] = 4 # 4th connection pt, clockwise from top(0).
57
- cxn_shape[:start_side] = 'b' # r)ight or b)ottom.
55
+ cxn_shape.start = ellipse.id
56
+ cxn_shape.start_index = 4 # 4th connection pt, clockwise from top(0).
57
+ cxn_shape.start_side = 'b' # r)ight or b)ottom.
58
58
 
59
- cxn_shape[:end] = p1[:id]
60
- cxn_shape[:end_index] = 0
61
- cxn_shape[:end_side] = 't' # l)eft or t)op.
59
+ cxn_shape.end = p1.id
60
+ cxn_shape.end_index = 0
61
+ cxn_shape.end_side = 't' # l)eft or t)op.
62
62
  worksheet.insert_shape('A1', cxn_shape, 0, 0)
63
63
 
64
- cxn_shape[:end] = p2[:id]
64
+ cxn_shape.end = p2.id
65
65
  worksheet.insert_shape('A1', cxn_shape, 0, 0)
66
66
 
67
- cxn_shape[:end] = p3[:id]
67
+ cxn_shape.end = p3.id
68
68
  worksheet.insert_shape('A1', cxn_shape, 0, 0)
69
69
 
70
- cxn_shape[:end] = p4[:id]
71
- cxn_shape[:adjustments] = [-50, 45, 120]
70
+ cxn_shape.end = p4.id
71
+ cxn_shape.adjustments = [-50, 45, 120]
72
72
  worksheet.insert_shape('A1', cxn_shape, 0, 0)
73
73
 
74
74
  workbook.close