writeexcel 0.3.4 → 0.3.5

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.
@@ -4,6 +4,13 @@ Write to a cross-platform Excel binary file.
4
4
 
5
5
  == Recent Changes
6
6
 
7
+ v0.3.5
8
+ * Bug fix. Worksheet#write_comment() doesn't work when value arg is numeric.
9
+ * Bug fix. TRUE/FALSE in formula was misundarstood as :NAME.
10
+ * Bug fix. Worksheet#close() mis-handled @colinfo.
11
+ * Bug fix. Worksheet#set_row() grbit mis-calculate by param hidden.
12
+ * convert examples.(formula_result, indent, merge6, outline, outline_collapsed, panes, right_to_left, row_wrap)
13
+
7
14
  v0.3.4
8
15
  * Bug fix. add_comment doesn't work.
9
16
  * convert examples.(chess, colors, comment1, comment2)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.4
1
+ 0.3.5
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/ruby -w
2
+
3
+ #######################################################################
4
+ #
5
+ # Example of how to write Spreadsheet::WriteExcel formulas with a user
6
+ # specified result.
7
+ #
8
+ # This is generally only required when writing a spreadsheet for an
9
+ # application other than Excel where the formula isn't evaluated.
10
+ #
11
+ # reverse('©'), August 2005, John McNamara, jmcnamara@cpan.org
12
+ #
13
+ # original written in Perl by John McNamara
14
+ # converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
15
+ #
16
+
17
+ require 'writeexcel'
18
+
19
+ workbook = WriteExcel.new('formula_result.xls')
20
+ worksheet = workbook.add_worksheet()
21
+ format = workbook.add_format(:color => 'blue')
22
+
23
+ worksheet.write('A1', '=1+2')
24
+ worksheet.write('A2', '=1+2', format, 4)
25
+ worksheet.write('A3', '="ABC"', nil, 'DEF')
26
+ worksheet.write('A4', '=IF(A1 > 1, TRUE, FALSE)', nil, 'TRUE')
27
+ worksheet.write('A5', '=1/0', nil, '#DIV/0!')
28
+
29
+ workbook.close
File without changes
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/ruby -w
2
+
3
+ ##############################################################################
4
+ #
5
+ # A simple formatting example using Spreadsheet::WriteExcel.
6
+ #
7
+ # This program demonstrates the indentation cell format.
8
+ #
9
+ # reverse('©'), May 2004, John McNamara, jmcnamara@cpan.org
10
+ #
11
+ # original written in Perl by John McNamara
12
+ # converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
13
+ #
14
+
15
+
16
+ require 'writeexcel'
17
+
18
+ workbook = WriteExcel.new('indent.xls')
19
+
20
+ worksheet = workbook.add_worksheet()
21
+ indent1 = workbook.add_format(:indent => 1)
22
+ indent2 = workbook.add_format(:indent => 2)
23
+
24
+ worksheet.set_column('A:A', 40)
25
+
26
+
27
+ worksheet.write('A1', "This text is indented 1 level", indent1)
28
+ worksheet.write('A2', "This text is indented 2 levels", indent2)
29
+
30
+ workbook.close
@@ -0,0 +1,66 @@
1
+ #!/usr/bin/ruby -w
2
+
3
+ ###############################################################################
4
+ #
5
+ # Example of how to use the Spreadsheet::WriteExcel merge_cells() workbook
6
+ # method with Unicode strings.
7
+ #
8
+ #
9
+ # reverse('©'), December 2005, John McNamara, jmcnamara@cpan.org
10
+ #
11
+ # original written in Perl by John McNamara
12
+ # converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
13
+ #
14
+
15
+ require 'writeexcel'
16
+
17
+ # Create a new workbook and add a worksheet
18
+ workbook = WriteExcel.new('merge6.xls')
19
+ worksheet = workbook.add_worksheet
20
+
21
+ # Increase the cell size of the merged cells to highlight the formatting.
22
+ (2..9).each { |i| worksheet.set_row(i, 36) }
23
+ worksheet.set_column('B:D', 25)
24
+
25
+ # Format for the merged cells.
26
+ format = workbook.add_format(
27
+ :border => 6,
28
+ :bold => 1,
29
+ :color => 'red',
30
+ :size => 20,
31
+ :valign => 'vcentre',
32
+ :align => 'left',
33
+ :indent => 1
34
+ )
35
+
36
+ ###############################################################################
37
+ #
38
+ # Write an Ascii string.
39
+ #
40
+
41
+ worksheet.merge_range('B3:D4', 'ASCII: A simple string', format)
42
+
43
+ ###############################################################################
44
+ #
45
+ # Write a UTF-16 Unicode string.
46
+ #
47
+
48
+ # A phrase in Cyrillic encoded as UTF-16BE.
49
+ utf16_str = [
50
+ '005500540046002d00310036003a0020' <<
51
+ '042d0442043e002004440440043004370430002004' <<
52
+ '3d043000200440044304410441043a043e043c0021'
53
+ ].pack("H*")
54
+
55
+ # Note the extra parameter at the end to indicate UTF-16 encoding.
56
+ worksheet.merge_range('B6:D7', utf16_str, format, 1)
57
+
58
+ ###############################################################################
59
+ #
60
+ # Write a UTF-8 Unicode string.
61
+ #
62
+
63
+ smiley = '☺' # chr 0x263a in perl
64
+ worksheet.merge_range('B9:D10', "UTF-8: A Unicode smiley #{smiley}", format)
65
+
66
+ workbook.close
@@ -0,0 +1,254 @@
1
+ #!/usr/bin/ruby -w
2
+
3
+ ###############################################################################
4
+ #
5
+ # Example of how use Spreadsheet::WriteExcel to generate Excel outlines and
6
+ # grouping.
7
+ #
8
+ #
9
+ # Excel allows you to group rows or columns so that they can be hidden or
10
+ # displayed with a single mouse click. This feature is referred to as outlines.
11
+ #
12
+ # Outlines can reduce complex data down to a few salient sub-totals or
13
+ # summaries.
14
+ #
15
+ # This feature is best viewed in Excel but the following is an ASCII
16
+ # representation of what a worksheet with three outlines might look like.
17
+ # Rows 3-4 and rows 7-8 are grouped at level 2. Rows 2-9 are grouped at
18
+ # level 1. The lines at the left hand side are called outline level bars.
19
+ #
20
+ #
21
+ # ------------------------------------------
22
+ # 1 2 3 | | A | B | C | D | ...
23
+ # ------------------------------------------
24
+ # _ | 1 | A | | | | ...
25
+ # | _ | 2 | B | | | | ...
26
+ # | | | 3 | (C) | | | | ...
27
+ # | | | 4 | (D) | | | | ...
28
+ # | - | 5 | E | | | | ...
29
+ # | _ | 6 | F | | | | ...
30
+ # | | | 7 | (G) | | | | ...
31
+ # | | | 8 | (H) | | | | ...
32
+ # | - | 9 | I | | | | ...
33
+ # - | . | ... | ... | ... | ... | ...
34
+ #
35
+ #
36
+ # Clicking the minus sign on each of the level 2 outlines will collapse and
37
+ # hide the data as shown in the next figure. The minus sign changes to a plus
38
+ # sign to indicate that the data in the outline is hidden.
39
+ #
40
+ # ------------------------------------------
41
+ # 1 2 3 | | A | B | C | D | ...
42
+ # ------------------------------------------
43
+ # _ | 1 | A | | | | ...
44
+ # | | 2 | B | | | | ...
45
+ # | + | 5 | E | | | | ...
46
+ # | | 6 | F | | | | ...
47
+ # | + | 9 | I | | | | ...
48
+ # - | . | ... | ... | ... | ... | ...
49
+ #
50
+ #
51
+ # Clicking on the minus sign on the level 1 outline will collapse the remaining
52
+ # rows as follows:
53
+ #
54
+ # ------------------------------------------
55
+ # 1 2 3 | | A | B | C | D | ...
56
+ # ------------------------------------------
57
+ # | 1 | A | | | | ...
58
+ # + | . | ... | ... | ... | ... | ...
59
+ #
60
+ # See the main Spreadsheet::WriteExcel documentation for more information.
61
+ #
62
+ # reverse('©'), April 2003, John McNamara, jmcnamara@cpan.org
63
+ #
64
+ # original written in Perl by John McNamara
65
+ # converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
66
+ #
67
+
68
+ require 'writeexcel'
69
+
70
+ # Create a new workbook and add some worksheets
71
+ workbook = WriteExcel.new('outline.xls')
72
+ worksheet1 = workbook.add_worksheet('Outlined Rows')
73
+ worksheet2 = workbook.add_worksheet('Collapsed Rows')
74
+ worksheet3 = workbook.add_worksheet('Outline Columns')
75
+ worksheet4 = workbook.add_worksheet('Outline levels')
76
+
77
+ # Add a general format
78
+ bold = workbook.add_format(:bold => 1)
79
+
80
+
81
+
82
+ ###############################################################################
83
+ #
84
+ # Example 1: Create a worksheet with outlined rows. It also includes SUBTOTAL()
85
+ # functions so that it looks like the type of automatic outlines that are
86
+ # generated when you use the Excel Data->SubTotals menu item.
87
+ #
88
+
89
+
90
+ # For outlines the important parameters are $hidden and $level. Rows with the
91
+ # same $level are grouped together. The group will be collapsed if $hidden is
92
+ # non-zero. $height and $XF are assigned default values if they are undef.
93
+ #
94
+ # The syntax is: set_row($row, $height, $XF, $hidden, $level, $collapsed)
95
+ #
96
+ worksheet1.set_row(1, nil, nil, 0, 2)
97
+ worksheet1.set_row(2, nil, nil, 0, 2)
98
+ worksheet1.set_row(3, nil, nil, 0, 2)
99
+ worksheet1.set_row(4, nil, nil, 0, 2)
100
+ worksheet1.set_row(5, nil, nil, 0, 1)
101
+
102
+ worksheet1.set_row(6, nil, nil, 0, 2)
103
+ worksheet1.set_row(7, nil, nil, 0, 2)
104
+ worksheet1.set_row(8, nil, nil, 0, 2)
105
+ worksheet1.set_row(9, nil, nil, 0, 2)
106
+ worksheet1.set_row(10, nil, nil, 0, 1)
107
+
108
+
109
+ # Add a column format for clarity
110
+ worksheet1.set_column('A:A', 20)
111
+
112
+ # Add the data, labels and formulas
113
+ worksheet1.write('A1', 'Region', bold)
114
+ worksheet1.write('A2', 'North')
115
+ worksheet1.write('A3', 'North')
116
+ worksheet1.write('A4', 'North')
117
+ worksheet1.write('A5', 'North')
118
+ worksheet1.write('A6', 'North Total', bold)
119
+
120
+ worksheet1.write('B1', 'Sales', bold)
121
+ worksheet1.write('B2', 1000)
122
+ worksheet1.write('B3', 1200)
123
+ worksheet1.write('B4', 900)
124
+ worksheet1.write('B5', 1200)
125
+ worksheet1.write('B6', '=SUBTOTAL(9,B2:B5)', bold)
126
+
127
+ worksheet1.write('A7', 'South')
128
+ worksheet1.write('A8', 'South')
129
+ worksheet1.write('A9', 'South')
130
+ worksheet1.write('A10', 'South')
131
+ worksheet1.write('A11', 'South Total', bold)
132
+
133
+ worksheet1.write('B7', 400)
134
+ worksheet1.write('B8', 600)
135
+ worksheet1.write('B9', 500)
136
+ worksheet1.write('B10', 600)
137
+ worksheet1.write('B11', '=SUBTOTAL(9,B7:B10)', bold)
138
+
139
+ worksheet1.write('A12', 'Grand Total', bold)
140
+ worksheet1.write('B12', '=SUBTOTAL(9,B2:B10)', bold)
141
+
142
+
143
+ ###############################################################################
144
+ #
145
+ # Example 2: Create a worksheet with outlined rows. This is the same as the
146
+ # previous example except that the rows are collapsed.
147
+ # Note: We need to indicate the row that contains the collapsed symbol '+'
148
+ # with the optional parameter, $collapsed.
149
+
150
+ # The group will be collapsed if $hidden is non-zero.
151
+ # The syntax is: set_row($row, $height, $XF, $hidden, $level, $collapsed)
152
+ #
153
+ worksheet2.set_row(1, nil, nil, 1, 2)
154
+ worksheet2.set_row(2, nil, nil, 1, 2)
155
+ worksheet2.set_row(3, nil, nil, 1, 2)
156
+ worksheet2.set_row(4, nil, nil, 1, 2)
157
+ worksheet2.set_row(5, nil, nil, 1, 1)
158
+
159
+ worksheet2.set_row(6, nil, nil, 1, 2)
160
+ worksheet2.set_row(7, nil, nil, 1, 2)
161
+ worksheet2.set_row(8, nil, nil, 1, 2)
162
+ worksheet2.set_row(9, nil, nil, 1, 2)
163
+ worksheet2.set_row(10, nil, nil, 1, 1)
164
+ worksheet2.set_row(11, nil, nil, 0, 0, 1)
165
+
166
+
167
+ # Add a column format for clarity
168
+ worksheet2.set_column('A:A', 20)
169
+
170
+ # Add the data, labels and formulas
171
+ worksheet2.write('A1', 'Region', bold)
172
+ worksheet2.write('A2', 'North')
173
+ worksheet2.write('A3', 'North')
174
+ worksheet2.write('A4', 'North')
175
+ worksheet2.write('A5', 'North')
176
+ worksheet2.write('A6', 'North Total', bold)
177
+
178
+ worksheet2.write('B1', 'Sales', bold)
179
+ worksheet2.write('B2', 1000)
180
+ worksheet2.write('B3', 1200)
181
+ worksheet2.write('B4', 900)
182
+ worksheet2.write('B5', 1200)
183
+ worksheet2.write('B6', '=SUBTOTAL(9,B2:B5)', bold)
184
+
185
+ worksheet2.write('A7', 'South')
186
+ worksheet2.write('A8', 'South')
187
+ worksheet2.write('A9', 'South')
188
+ worksheet2.write('A10', 'South')
189
+ worksheet2.write('A11', 'South Total', bold)
190
+
191
+ worksheet2.write('B7', 400)
192
+ worksheet2.write('B8', 600)
193
+ worksheet2.write('B9', 500)
194
+ worksheet2.write('B10', 600)
195
+ worksheet2.write('B11', '=SUBTOTAL(9,B7:B10)', bold)
196
+
197
+ worksheet2.write('A12', 'Grand Total', bold)
198
+ worksheet2.write('B12', '=SUBTOTAL(9,B2:B10)', bold)
199
+
200
+
201
+
202
+ ###############################################################################
203
+ #
204
+ # Example 3: Create a worksheet with outlined columns.
205
+ #
206
+ data = [
207
+ ['Month', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', ' Total'],
208
+ ['North', 50, 20, 15, 25, 65, 80, '=SUM(B2:G2)'],
209
+ ['South', 10, 20, 30, 50, 50, 50, '=SUM(B3:G3)'],
210
+ ['East', 45, 75, 50, 15, 75, 100, '=SUM(B4:G4)'],
211
+ ['West', 15, 15, 55, 35, 20, 50, '=SUM(B5:G6)']
212
+ ]
213
+
214
+ # Add bold format to the first row
215
+ worksheet3.set_row(0, nil, bold)
216
+
217
+ # Syntax: set_column(col1, col2, width, XF, hidden, level, collapsed)
218
+ worksheet3.set_column('A:A', 10, bold )
219
+ worksheet3.set_column('B:G', 5, nil, 0, 1)
220
+ worksheet3.set_column('H:H', 10)
221
+
222
+ # Write the data and a formula
223
+ worksheet3.write_col('A1', data)
224
+ worksheet3.write('H6', '=SUM(H2:H5)', bold)
225
+
226
+
227
+
228
+ ###############################################################################
229
+ #
230
+ # Example 4: Show all possible outline levels.
231
+ #
232
+ levels = [
233
+ "Level 1", "Level 2", "Level 3", "Level 4",
234
+ "Level 5", "Level 6", "Level 7", "Level 6",
235
+ "Level 5", "Level 4", "Level 3", "Level 2", "Level 1"
236
+ ]
237
+
238
+ worksheet4.write_col('A1', levels)
239
+
240
+ worksheet4.set_row(0, nil, nil, nil, 1)
241
+ worksheet4.set_row(1, nil, nil, nil, 2)
242
+ worksheet4.set_row(2, nil, nil, nil, 3)
243
+ worksheet4.set_row(3, nil, nil, nil, 4)
244
+ worksheet4.set_row(4, nil, nil, nil, 5)
245
+ worksheet4.set_row(5, nil, nil, nil, 6)
246
+ worksheet4.set_row(6, nil, nil, nil, 7)
247
+ worksheet4.set_row(7, nil, nil, nil, 6)
248
+ worksheet4.set_row(8, nil, nil, nil, 5)
249
+ worksheet4.set_row(9, nil, nil, nil, 4)
250
+ worksheet4.set_row(10, nil, nil, nil, 3)
251
+ worksheet4.set_row(11, nil, nil, nil, 2)
252
+ worksheet4.set_row(12, nil, nil, nil, 1)
253
+
254
+ workbook.close
@@ -0,0 +1,208 @@
1
+ #!/usr/bin/ruby -w
2
+
3
+ ###############################################################################
4
+ #
5
+ # Example of how use Spreadsheet::WriteExcel to generate Excel outlines and
6
+ # grouping.
7
+ #
8
+ # These example focus mainly on collapsed outlines. See also the
9
+ # outlines.pl example program for more general examples.
10
+ #
11
+ # reverse('©'), March 2008, John McNamara, jmcnamara@cpan.org
12
+ #
13
+ # original written in Perl by John McNamara
14
+ # converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
15
+ #
16
+
17
+ require 'writeexcel'
18
+
19
+ # Create a new workbook and add some worksheets
20
+ workbook = WriteExcel.new('outline_collapsed.xls')
21
+ worksheet1 = workbook.add_worksheet('Outlined Rows')
22
+ worksheet2 = workbook.add_worksheet('Collapsed Rows 1')
23
+ worksheet3 = workbook.add_worksheet('Collapsed Rows 2')
24
+ worksheet4 = workbook.add_worksheet('Collapsed Rows 3')
25
+ worksheet5 = workbook.add_worksheet('Outline Columns')
26
+ worksheet6 = workbook.add_worksheet('Collapsed Columns')
27
+
28
+ # Add a general format
29
+ bold = workbook.add_format(:bold => 1)
30
+
31
+ #
32
+ # This function will generate the same data and sub-totals on each worksheet.
33
+ #
34
+ def create_sub_totals(worksheet, bold)
35
+ # Add a column format for clarity
36
+ worksheet.set_column('A:A', 20)
37
+
38
+ # Add the data, labels and formulas
39
+ worksheet.write('A1', 'Region', bold)
40
+ worksheet.write('A2', 'North')
41
+ worksheet.write('A3', 'North')
42
+ worksheet.write('A4', 'North')
43
+ worksheet.write('A5', 'North')
44
+ worksheet.write('A6', 'North Total', bold)
45
+
46
+ worksheet.write('B1', 'Sales', bold)
47
+ worksheet.write('B2', 1000)
48
+ worksheet.write('B3', 1200)
49
+ worksheet.write('B4', 900)
50
+ worksheet.write('B5', 1200)
51
+ worksheet.write('B6', '=SUBTOTAL(9,B2:B5)', bold)
52
+
53
+ worksheet.write('A7', 'South')
54
+ worksheet.write('A8', 'South')
55
+ worksheet.write('A9', 'South')
56
+ worksheet.write('A10', 'South')
57
+ worksheet.write('A11', 'South Total', bold)
58
+
59
+ worksheet.write('B7', 400)
60
+ worksheet.write('B8', 600)
61
+ worksheet.write('B9', 500)
62
+ worksheet.write('B10', 600)
63
+ worksheet.write('B11', '=SUBTOTAL(9,B7:B10)', bold)
64
+
65
+ worksheet.write('A12', 'Grand Total', bold)
66
+ worksheet.write('B12', '=SUBTOTAL(9,B2:B10)', bold)
67
+
68
+ end
69
+
70
+
71
+ ###############################################################################
72
+ #
73
+ # Example 1: Create a worksheet with outlined rows. It also includes SUBTOTAL()
74
+ # functions so that it looks like the type of automatic outlines that are
75
+ # generated when you use the Excel Data.SubTotals menu item.
76
+ #
77
+
78
+ # The syntax is: set_row(row, height, XF, hidden, level, collapsed)
79
+ worksheet1.set_row(1, nil, nil, 0, 2)
80
+ worksheet1.set_row(2, nil, nil, 0, 2)
81
+ worksheet1.set_row(3, nil, nil, 0, 2)
82
+ worksheet1.set_row(4, nil, nil, 0, 2)
83
+ worksheet1.set_row(5, nil, nil, 0, 1)
84
+
85
+ worksheet1.set_row(6, nil, nil, 0, 2)
86
+ worksheet1.set_row(7, nil, nil, 0, 2)
87
+ worksheet1.set_row(8, nil, nil, 0, 2)
88
+ worksheet1.set_row(9, nil, nil, 0, 2)
89
+ worksheet1.set_row(10, nil, nil, 0, 1)
90
+
91
+ # Write the sub-total data that is common to the row examples.
92
+ create_sub_totals(worksheet1, bold)
93
+
94
+
95
+ ###############################################################################
96
+ #
97
+ # Example 2: Create a worksheet with collapsed outlined rows.
98
+ # This is the same as the example 1 except that the all rows are collapsed.
99
+ # Note: We need to indicate the row that contains the collapsed symbol '+' with
100
+ # the optional parameter, collapsed.
101
+
102
+ worksheet2.set_row(1, nil, nil, 1, 2)
103
+ worksheet2.set_row(2, nil, nil, 1, 2)
104
+ worksheet2.set_row(3, nil, nil, 1, 2)
105
+ worksheet2.set_row(4, nil, nil, 1, 2)
106
+ worksheet2.set_row(5, nil, nil, 1, 1)
107
+
108
+ worksheet2.set_row(6, nil, nil, 1, 2)
109
+ worksheet2.set_row(7, nil, nil, 1, 2)
110
+ worksheet2.set_row(8, nil, nil, 1, 2)
111
+ worksheet2.set_row(9, nil, nil, 1, 2)
112
+ worksheet2.set_row(10, nil, nil, 1, 1)
113
+
114
+ worksheet2.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(worksheet2, bold)
118
+
119
+
120
+ ###############################################################################
121
+ #
122
+ # Example 3: Create a worksheet with collapsed outlined rows.
123
+ # Same as the example 1 except that the two sub-totals are collapsed.
124
+
125
+ worksheet3.set_row(1, nil, nil, 1, 2)
126
+ worksheet3.set_row(2, nil, nil, 1, 2)
127
+ worksheet3.set_row(3, nil, nil, 1, 2)
128
+ worksheet3.set_row(4, nil, nil, 1, 2)
129
+ worksheet3.set_row(5, nil, nil, 0, 1, 1)
130
+
131
+ worksheet3.set_row(6, nil, nil, 1, 2)
132
+ worksheet3.set_row(7, nil, nil, 1, 2)
133
+ worksheet3.set_row(8, nil, nil, 1, 2)
134
+ worksheet3.set_row(9, nil, nil, 1, 2)
135
+ worksheet3.set_row(10, nil, nil, 0, 1, 1)
136
+
137
+
138
+ # Write the sub-total data that is common to the row examples.
139
+ create_sub_totals(worksheet3, bold)
140
+
141
+
142
+ ###############################################################################
143
+ #
144
+ # Example 4: Create a worksheet with outlined rows.
145
+ # Same as the example 1 except that the two sub-totals are collapsed.
146
+
147
+ worksheet4.set_row(1, nil, nil, 1, 2)
148
+ worksheet4.set_row(2, nil, nil, 1, 2)
149
+ worksheet4.set_row(3, nil, nil, 1, 2)
150
+ worksheet4.set_row(4, nil, nil, 1, 2)
151
+ worksheet4.set_row(5, nil, nil, 1, 1, 1)
152
+
153
+ worksheet4.set_row(6, nil, nil, 1, 2)
154
+ worksheet4.set_row(7, nil, nil, 1, 2)
155
+ worksheet4.set_row(8, nil, nil, 1, 2)
156
+ worksheet4.set_row(9, nil, nil, 1, 2)
157
+ worksheet4.set_row(10, nil, nil, 1, 1, 1)
158
+
159
+ worksheet4.set_row(11, nil, nil, 0, 0, 1)
160
+
161
+ # Write the sub-total data that is common to the row examples.
162
+ create_sub_totals(worksheet4, bold)
163
+
164
+
165
+
166
+ ###############################################################################
167
+ #
168
+ # Example 5: Create a worksheet with outlined columns.
169
+ #
170
+ data = [
171
+ ['Month', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',' Total'],
172
+ ['North', 50, 20, 15, 25, 65, 80, '=SUM(B2:G2)'],
173
+ ['South', 10, 20, 30, 50, 50, 50, '=SUM(B3:G3)'],
174
+ ['East', 45, 75, 50, 15, 75, 100, '=SUM(B4:G4)'],
175
+ ['West', 15, 15, 55, 35, 20, 50, '=SUM(B5:G6)']
176
+ ]
177
+
178
+ # Add bold format to the first row
179
+ worksheet5.set_row(0, nil, bold)
180
+
181
+ # Syntax: set_column(col1, col2, width, XF, hidden, level, collapsed)
182
+ worksheet5.set_column('A:A', 10, bold )
183
+ worksheet5.set_column('B:G', 5, nil, 0, 1)
184
+ worksheet5.set_column('H:H', 10 )
185
+
186
+ # Write the data and a formula
187
+ worksheet5.write_col('A1', data)
188
+ worksheet5.write('H6', '=SUM(H2:H5)', bold)
189
+
190
+
191
+ ###############################################################################
192
+ #
193
+ # Example 6: Create a worksheet with collapsed outlined columns.
194
+ # This is the same as the previous example except collapsed columns.
195
+
196
+ # Add bold format to the first row
197
+ worksheet6.set_row(0, nil, bold)
198
+
199
+ # Syntax: set_column(col1, col2, width, XF, hidden, level, collapsed)
200
+ worksheet6.set_column('A:A', 10, bold )
201
+ worksheet6.set_column('B:G', 5, nil, 1, 1 )
202
+ worksheet6.set_column('H:H', 10, nil, 0, 0, 1)
203
+
204
+ # Write the data and a formula
205
+ worksheet6.write_col('A1', data)
206
+ worksheet6.write('H6', '=SUM(H2:H5)', bold)
207
+
208
+ workbook.close