WriteExcel 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +17 -0
- data/Rakefile +47 -0
- data/VERSION +1 -0
- data/examples/a_simple.rb +42 -0
- data/examples/autofilters.rb +266 -0
- data/examples/bigfile.rb +30 -0
- data/examples/copyformat.rb +51 -0
- data/examples/data_validate.rb +278 -0
- data/examples/date_time.rb +86 -0
- data/examples/demo.rb +118 -0
- data/examples/diag_border.rb +35 -0
- data/examples/formats.rb +489 -0
- data/examples/header.rb +136 -0
- data/examples/hidden.rb +28 -0
- data/examples/hyperlink.rb +42 -0
- data/examples/images.rb +52 -0
- data/examples/merge1.rb +39 -0
- data/examples/merge2.rb +44 -0
- data/examples/merge3.rb +65 -0
- data/examples/merge4.rb +82 -0
- data/examples/merge5.rb +79 -0
- data/examples/protection.rb +46 -0
- data/examples/regions.rb +52 -0
- data/examples/repeat.rb +42 -0
- data/examples/stats.rb +75 -0
- data/examples/stocks.rb +80 -0
- data/examples/tab_colors.rb +30 -0
- data/lib/WriteExcel.rb +30 -0
- data/lib/WriteExcel/biffwriter.rb +259 -0
- data/lib/WriteExcel/chart.rb +217 -0
- data/lib/WriteExcel/excelformula.y +138 -0
- data/lib/WriteExcel/excelformulaparser.rb +573 -0
- data/lib/WriteExcel/format.rb +1108 -0
- data/lib/WriteExcel/formula.rb +986 -0
- data/lib/WriteExcel/olewriter.rb +322 -0
- data/lib/WriteExcel/properties.rb +250 -0
- data/lib/WriteExcel/storage_lite.rb +590 -0
- data/lib/WriteExcel/workbook.rb +2602 -0
- data/lib/WriteExcel/worksheet.rb +6378 -0
- data/spec/WriteExcel_spec.rb +7 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +9 -0
- data/test/tc_all.rb +31 -0
- data/test/tc_biff.rb +104 -0
- data/test/tc_chart.rb +22 -0
- data/test/tc_example_match.rb +1280 -0
- data/test/tc_format.rb +1264 -0
- data/test/tc_formula.rb +63 -0
- data/test/tc_ole.rb +110 -0
- data/test/tc_storage_lite.rb +102 -0
- data/test/tc_workbook.rb +115 -0
- data/test/tc_worksheet.rb +115 -0
- data/test/test_00_IEEE_double.rb +14 -0
- data/test/test_01_add_worksheet.rb +12 -0
- data/test/test_02_merge_formats.rb +58 -0
- data/test/test_04_dimensions.rb +397 -0
- data/test/test_05_rows.rb +182 -0
- data/test/test_06_extsst.rb +80 -0
- data/test/test_11_date_time.rb +484 -0
- data/test/test_12_date_only.rb +506 -0
- data/test/test_13_date_seconds.rb +486 -0
- data/test/test_21_escher.rb +629 -0
- data/test/test_22_mso_drawing_group.rb +739 -0
- data/test/test_23_note.rb +78 -0
- data/test/test_24_txo.rb +80 -0
- data/test/test_26_autofilter.rb +327 -0
- data/test/test_27_autofilter.rb +144 -0
- data/test/test_28_autofilter.rb +174 -0
- data/test/test_29_process_jpg.rb +131 -0
- data/test/test_30_validation_dval.rb +82 -0
- data/test/test_31_validation_dv_strings.rb +131 -0
- data/test/test_32_validation_dv_formula.rb +211 -0
- data/test/test_40_property_types.rb +191 -0
- data/test/test_41_properties.rb +238 -0
- data/test/test_42_set_properties.rb +430 -0
- data/test/ts_all.rb +34 -0
- metadata +154 -0
data/examples/header.rb
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
|
3
|
+
######################################################################
|
4
|
+
#
|
5
|
+
# This program shows several examples of how to set up headers and
|
6
|
+
# footers with Spreadsheet::WriteExcel.
|
7
|
+
#
|
8
|
+
# The control characters used in the header/footer strings are:
|
9
|
+
#
|
10
|
+
# Control Category Description
|
11
|
+
# ======= ======== ===========
|
12
|
+
# &L Justification Left
|
13
|
+
# &C Center
|
14
|
+
# &R Right
|
15
|
+
#
|
16
|
+
# &P Information Page number
|
17
|
+
# &N Total number of pages
|
18
|
+
# &D Date
|
19
|
+
# &T Time
|
20
|
+
# &F File name
|
21
|
+
# &A Worksheet name
|
22
|
+
#
|
23
|
+
# &fontsize Font Font size
|
24
|
+
# &"font,style" Font name and style
|
25
|
+
# &U Single underline
|
26
|
+
# &E Double underline
|
27
|
+
# &S Strikethrough
|
28
|
+
# &X Superscript
|
29
|
+
# &Y Subscript
|
30
|
+
#
|
31
|
+
# && Miscellaneous Literal ampersand &
|
32
|
+
#
|
33
|
+
#
|
34
|
+
# reverse('©'), March 2002, John McNamara, jmcnamara@cpan.org
|
35
|
+
#
|
36
|
+
# original written in Perl by John McNamara
|
37
|
+
# converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
|
38
|
+
#
|
39
|
+
|
40
|
+
require 'rubygems'
|
41
|
+
require 'WriteExcel'
|
42
|
+
|
43
|
+
workbook = Spreadsheet::WriteExcel.new("headers.xls")
|
44
|
+
preview = "Select Print Preview to see the header and footer"
|
45
|
+
|
46
|
+
|
47
|
+
######################################################################
|
48
|
+
#
|
49
|
+
# A simple example to start
|
50
|
+
#
|
51
|
+
worksheet1 = workbook.add_worksheet('Simple')
|
52
|
+
|
53
|
+
header1 = '&CHere is some centred text.'
|
54
|
+
|
55
|
+
footer1 = '&LHere is some left aligned text.'
|
56
|
+
|
57
|
+
|
58
|
+
worksheet1.set_header(header1)
|
59
|
+
worksheet1.set_footer(footer1)
|
60
|
+
|
61
|
+
worksheet1.set_column('A:A', 50)
|
62
|
+
worksheet1.write('A1', preview)
|
63
|
+
|
64
|
+
|
65
|
+
######################################################################
|
66
|
+
#
|
67
|
+
# This is an example of some of the header/footer variables.
|
68
|
+
#
|
69
|
+
worksheet2 = workbook.add_worksheet('Variables')
|
70
|
+
|
71
|
+
header2 = '&LPage &P of &N'+
|
72
|
+
'&CFilename: &F' +
|
73
|
+
'&RSheetname: &A'
|
74
|
+
|
75
|
+
footer2 = '&LCurrent date: &D'+
|
76
|
+
'&RCurrent time: &T'
|
77
|
+
|
78
|
+
worksheet2.set_header(header2)
|
79
|
+
worksheet2.set_footer(footer2)
|
80
|
+
|
81
|
+
|
82
|
+
worksheet2.set_column('A:A', 50)
|
83
|
+
worksheet2.write('A1', preview)
|
84
|
+
worksheet2.write('A21', "Next sheet")
|
85
|
+
worksheet2.set_h_pagebreaks(20)
|
86
|
+
|
87
|
+
|
88
|
+
######################################################################
|
89
|
+
#
|
90
|
+
# This example shows how to use more than one font
|
91
|
+
#
|
92
|
+
worksheet3 = workbook.add_worksheet('Mixed fonts')
|
93
|
+
|
94
|
+
header3 = '&C' +
|
95
|
+
'&"Courier New,Bold"Hello ' +
|
96
|
+
'&"Arial,Italic"World'
|
97
|
+
|
98
|
+
footer3 = '&C' +
|
99
|
+
'&"Symbol"e' +
|
100
|
+
'&"Arial" = mc&X2'
|
101
|
+
|
102
|
+
worksheet3.set_header(header3)
|
103
|
+
worksheet3.set_footer(footer3)
|
104
|
+
|
105
|
+
worksheet3.set_column('A:A', 50)
|
106
|
+
worksheet3.write('A1', preview)
|
107
|
+
|
108
|
+
|
109
|
+
######################################################################
|
110
|
+
#
|
111
|
+
# Example of line wrapping
|
112
|
+
#
|
113
|
+
worksheet4 = workbook.add_worksheet('Word wrap')
|
114
|
+
|
115
|
+
header4 = "&CHeading 1\nHeading 2\nHeading 3"
|
116
|
+
|
117
|
+
worksheet4.set_header(header4)
|
118
|
+
|
119
|
+
worksheet4.set_column('A:A', 50)
|
120
|
+
worksheet4.write('A1', preview)
|
121
|
+
|
122
|
+
|
123
|
+
######################################################################
|
124
|
+
#
|
125
|
+
# Example of inserting a literal ampersand &
|
126
|
+
#
|
127
|
+
worksheet5 = workbook.add_worksheet('Ampersand')
|
128
|
+
|
129
|
+
header5 = "&CCuriouser && Curiouser - Attorneys at Law"
|
130
|
+
|
131
|
+
worksheet5.set_header(header5)
|
132
|
+
|
133
|
+
worksheet5.set_column('A:A', 50)
|
134
|
+
worksheet5.write('A1', preview)
|
135
|
+
|
136
|
+
workbook.close
|
data/examples/hidden.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
|
3
|
+
#######################################################################
|
4
|
+
#
|
5
|
+
# Example of how to hide a worksheet with Spreadsheet::WriteExcel.
|
6
|
+
#
|
7
|
+
# reverse('©'), April 2005, John McNamara, jmcnamara@cpan.org
|
8
|
+
#
|
9
|
+
# original written in Perl by John McNamara
|
10
|
+
# converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
|
11
|
+
#
|
12
|
+
require 'rubygems'
|
13
|
+
require 'WriteExcel'
|
14
|
+
|
15
|
+
|
16
|
+
workbook = Spreadsheet::WriteExcel.new('hidden.xls')
|
17
|
+
worksheet1 = workbook.add_worksheet
|
18
|
+
worksheet2 = workbook.add_worksheet
|
19
|
+
worksheet3 = workbook.add_worksheet
|
20
|
+
|
21
|
+
# Sheet2 won't be visible until it is unhidden in Excel.
|
22
|
+
worksheet2.hide
|
23
|
+
|
24
|
+
worksheet1.write(0, 0, 'Sheet2 is hidden')
|
25
|
+
worksheet2.write(0, 0, 'How did you find me?')
|
26
|
+
worksheet3.write(0, 0, 'Sheet2 is hidden')
|
27
|
+
|
28
|
+
workbook.close
|
@@ -0,0 +1,42 @@
|
|
1
|
+
#!/usr/bin/ruby -W0
|
2
|
+
###############################################################################
|
3
|
+
#
|
4
|
+
# Example of how to use the WriteExcel module to write hyperlinks
|
5
|
+
#
|
6
|
+
# See also hyperlink2.pl for worksheet URL examples.
|
7
|
+
#
|
8
|
+
# reverse('©'), March 2001, John McNamara, jmcnamara@cpan.org
|
9
|
+
#
|
10
|
+
# original written in Perl by John McNamara
|
11
|
+
# converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
|
12
|
+
#
|
13
|
+
require 'rubygems'
|
14
|
+
require 'WriteExcel'
|
15
|
+
|
16
|
+
# Create a new workbook and add a worksheet
|
17
|
+
workbook = Spreadsheet::WriteExcel.new("hyperlink.xls")
|
18
|
+
worksheet = workbook.add_worksheet('Hyperlinks')
|
19
|
+
|
20
|
+
# Format the first column
|
21
|
+
worksheet.set_column('A:A', 30)
|
22
|
+
worksheet.set_selection('B1')
|
23
|
+
|
24
|
+
|
25
|
+
# Add a sample format
|
26
|
+
format = workbook.add_format
|
27
|
+
format.set_size(12)
|
28
|
+
format.set_bold
|
29
|
+
format.set_color('red')
|
30
|
+
format.set_underline
|
31
|
+
|
32
|
+
|
33
|
+
# Write some hyperlinks
|
34
|
+
worksheet.write('A1', 'http://www.perl.com/' )
|
35
|
+
worksheet.write('A3', 'http://www.perl.com/', 'Perl home' )
|
36
|
+
worksheet.write('A5', 'http://www.perl.com/', nil, format)
|
37
|
+
worksheet.write('A7', 'mailto:jmcnamara@cpan.org', 'Mail me')
|
38
|
+
|
39
|
+
# Write a URL that isn't a hyperlink
|
40
|
+
worksheet.write_string('A9', 'http://www.perl.com/')
|
41
|
+
|
42
|
+
workbook.close
|
data/examples/images.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
|
3
|
+
#######################################################################
|
4
|
+
#
|
5
|
+
# Example of how to insert images into an Excel worksheet using the
|
6
|
+
# Spreadsheet::WriteExcel insert_image() method.
|
7
|
+
#
|
8
|
+
# reverse('©'), October 2001, John McNamara, jmcnamara@cpan.org
|
9
|
+
#
|
10
|
+
# original written in Perl by John McNamara
|
11
|
+
# converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
|
12
|
+
#
|
13
|
+
|
14
|
+
require 'rubygems'
|
15
|
+
require 'WriteExcel'
|
16
|
+
|
17
|
+
# Create a new workbook called simple.xls and add a worksheet
|
18
|
+
workbook = Spreadsheet::WriteExcel.new("images.xls")
|
19
|
+
worksheet1 = workbook.add_worksheet('Image 1')
|
20
|
+
worksheet2 = workbook.add_worksheet('Image 2')
|
21
|
+
worksheet3 = workbook.add_worksheet('Image 3')
|
22
|
+
worksheet4 = workbook.add_worksheet('Image 4')
|
23
|
+
bp=1
|
24
|
+
|
25
|
+
# Insert a basic image
|
26
|
+
worksheet1.write('A10', "Image inserted into worksheet.")
|
27
|
+
worksheet1.insert_image('A1', 'republic.png')
|
28
|
+
|
29
|
+
|
30
|
+
# Insert an image with an offset
|
31
|
+
worksheet2.write('A10', "Image inserted with an offset.")
|
32
|
+
worksheet2.insert_image('A1', 'republic.png', 32, 10)
|
33
|
+
|
34
|
+
# Insert a scaled image
|
35
|
+
worksheet3.write('A10', "Image scaled: width x 2, height x 0.8.")
|
36
|
+
worksheet3.insert_image('A1', 'republic.png', 0, 0, 2, 0.8)
|
37
|
+
|
38
|
+
# Insert an image over varied column and row sizes
|
39
|
+
# This does not require any additional work
|
40
|
+
|
41
|
+
# Set the cols and row sizes
|
42
|
+
# NOTE: you must do this before you call insert_image()
|
43
|
+
worksheet4.set_column('A:A', 5)
|
44
|
+
worksheet4.set_column('B:B', nil, nil, 1) # Hidden
|
45
|
+
worksheet4.set_column('C:D', 10)
|
46
|
+
worksheet4.set_row(0, 30)
|
47
|
+
worksheet4.set_row(3, 5)
|
48
|
+
|
49
|
+
worksheet4.write('A10', "Image inserted over scaled rows and columns.")
|
50
|
+
worksheet4.insert_image('A1', 'republic.png')
|
51
|
+
|
52
|
+
workbook.close
|
data/examples/merge1.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
|
3
|
+
###############################################################################
|
4
|
+
#
|
5
|
+
# Simple example of merging cells using the Spreadsheet::WriteExcel module.
|
6
|
+
#
|
7
|
+
# This merges three cells using the "Centre Across Selection" alignment.
|
8
|
+
# This was the Excel 5 method of achieving a merge. Use the merge_range()
|
9
|
+
# worksheet method instead. See merge3.pl - merge6.pl.
|
10
|
+
#
|
11
|
+
# reverse('©'), August 2002, 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 'rubygems'
|
18
|
+
require 'WriteExcel'
|
19
|
+
|
20
|
+
# Create a new workbook and add a worksheet
|
21
|
+
workbook = Spreadsheet::WriteExcel.new('merge1.xls')
|
22
|
+
worksheet = workbook.add_worksheet
|
23
|
+
|
24
|
+
|
25
|
+
# Increase the cell size of the merged cells to highlight the formatting.
|
26
|
+
worksheet.set_column('B:D', 20)
|
27
|
+
worksheet.set_row(2, 30)
|
28
|
+
|
29
|
+
|
30
|
+
# Create a merge format
|
31
|
+
format = workbook.add_format(:center_across => 1)
|
32
|
+
|
33
|
+
|
34
|
+
# Only one cell should contain text, the others should be blank.
|
35
|
+
worksheet.write(2, 1, "Center across selection", format)
|
36
|
+
worksheet.write_blank(2, 2, format)
|
37
|
+
worksheet.write_blank(2, 3, format)
|
38
|
+
|
39
|
+
workbook.close
|
data/examples/merge2.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
|
3
|
+
###############################################################################
|
4
|
+
#
|
5
|
+
# Simple example of merging cells using the Spreadsheet::WriteExcel module
|
6
|
+
#
|
7
|
+
# This merges two formatted cells using the "Centre Across Selection" alignment.
|
8
|
+
# This was the Excel 5 method of achieving a merge. Use the merge_range()
|
9
|
+
# worksheet method instead. See merge3.pl - merge6.pl.
|
10
|
+
#
|
11
|
+
# reverse('©'), August 2002, 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 'rubygems'
|
18
|
+
require 'WriteExcel'
|
19
|
+
|
20
|
+
# Create a new workbook and add a worksheet
|
21
|
+
workbook = Spreadsheet::WriteExcel.new("merge2.xls")
|
22
|
+
worksheet = workbook.add_worksheet
|
23
|
+
|
24
|
+
# Increase the cell size of the merged cells to highlight the formatting.
|
25
|
+
worksheet.set_column(1, 2, 30)
|
26
|
+
worksheet.set_row(2, 40)
|
27
|
+
|
28
|
+
# Create a merged format
|
29
|
+
format = workbook.add_format(
|
30
|
+
:center_across => 1,
|
31
|
+
:bold => 1,
|
32
|
+
:size => 15,
|
33
|
+
:pattern => 1,
|
34
|
+
:border => 6,
|
35
|
+
:color => 'white',
|
36
|
+
:fg_color => 'green',
|
37
|
+
:border_color => 'yellow',
|
38
|
+
:align => 'vcenter'
|
39
|
+
)
|
40
|
+
|
41
|
+
# Only one cell should contain text, the others should be blank.
|
42
|
+
worksheet.write(2, 1, "Center across selection", format)
|
43
|
+
worksheet.write_blank(2, 2, format)
|
44
|
+
workbook.close
|
data/examples/merge3.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
|
3
|
+
###############################################################################
|
4
|
+
#
|
5
|
+
# Example of how to use Spreadsheet::WriteExcel to write a hyperlink in a
|
6
|
+
# merged cell. There are two options write_url_range() with a standard merge
|
7
|
+
# format or merge_range().
|
8
|
+
#
|
9
|
+
# reverse('©'), September 2002, 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 'rubygems'
|
16
|
+
require 'WriteExcel'
|
17
|
+
|
18
|
+
# Create a new workbook and add a worksheet
|
19
|
+
workbook = Spreadsheet::WriteExcel.new("merge3.xls")
|
20
|
+
worksheet = workbook.add_worksheet()
|
21
|
+
|
22
|
+
# Increase the cell size of the merged cells to highlight the formatting.
|
23
|
+
[1, 3,6,7].each { |row| worksheet.set_row(row, 30) }
|
24
|
+
worksheet.set_column('B:D', 20)
|
25
|
+
|
26
|
+
bp=1
|
27
|
+
###############################################################################
|
28
|
+
#
|
29
|
+
# Example 1: Merge cells containing a hyperlink using write_url_range()
|
30
|
+
# and the standard Excel 5+ merge property.
|
31
|
+
#
|
32
|
+
format1 = workbook.add_format(
|
33
|
+
:center_across => 1,
|
34
|
+
:border => 1,
|
35
|
+
:underline => 1,
|
36
|
+
:color => 'blue'
|
37
|
+
)
|
38
|
+
|
39
|
+
# Write the cells to be merged
|
40
|
+
worksheet.write_url_range('B2:D2', 'http://www.perl.com', format1)
|
41
|
+
worksheet.write_blank('C2', format1)
|
42
|
+
worksheet.write_blank('D2', format1)
|
43
|
+
|
44
|
+
|
45
|
+
|
46
|
+
###############################################################################
|
47
|
+
#
|
48
|
+
# Example 2: Merge cells containing a hyperlink using merge_range().
|
49
|
+
#
|
50
|
+
format2 = workbook.add_format(
|
51
|
+
:border => 1,
|
52
|
+
:underline => 1,
|
53
|
+
:color => 'blue',
|
54
|
+
:align => 'center',
|
55
|
+
:valign => 'vcenter'
|
56
|
+
)
|
57
|
+
|
58
|
+
# Merge 3 cells
|
59
|
+
worksheet.merge_range('B4:D4', 'http://www.perl.com', format2)
|
60
|
+
|
61
|
+
|
62
|
+
# Merge 3 cells over two rows
|
63
|
+
worksheet.merge_range('B7:D8', 'http://www.perl.com', format2)
|
64
|
+
|
65
|
+
workbook.close
|
data/examples/merge4.rb
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
|
3
|
+
###############################################################################
|
4
|
+
#
|
5
|
+
# Example of how to use the Spreadsheet::WriteExcel merge_range() workbook
|
6
|
+
# method with complex formatting.
|
7
|
+
#
|
8
|
+
# reverse('©'), September 2002, John McNamara, jmcnamara@cpan.org
|
9
|
+
#
|
10
|
+
# original written in Perl by John McNamara
|
11
|
+
# converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
|
12
|
+
#
|
13
|
+
|
14
|
+
require 'rubygems'
|
15
|
+
require 'WriteExcel'
|
16
|
+
|
17
|
+
# Create a new workbook and add a worksheet
|
18
|
+
workbook = Spreadsheet::WriteExcel.new('merge4.xls')
|
19
|
+
worksheet = workbook.add_worksheet
|
20
|
+
|
21
|
+
# Increase the cell size of the merged cells to highlight the formatting.
|
22
|
+
(1..11).each { |row| worksheet.set_row(row, 30) }
|
23
|
+
worksheet.set_column('B:D', 20)
|
24
|
+
|
25
|
+
###############################################################################
|
26
|
+
#
|
27
|
+
# Example 1: Text centered vertically and horizontally
|
28
|
+
#
|
29
|
+
format1 = workbook.add_format(
|
30
|
+
:border => 6,
|
31
|
+
:bold => 1,
|
32
|
+
:color => 'red',
|
33
|
+
:valign => 'vcenter',
|
34
|
+
:align => 'center'
|
35
|
+
)
|
36
|
+
|
37
|
+
worksheet.merge_range('B2:D3', 'Vertical and horizontal', format1)
|
38
|
+
|
39
|
+
|
40
|
+
###############################################################################
|
41
|
+
#
|
42
|
+
# Example 2: Text aligned to the top and left
|
43
|
+
#
|
44
|
+
format2 = workbook.add_format(
|
45
|
+
:border => 6,
|
46
|
+
:bold => 1,
|
47
|
+
:color => 'red',
|
48
|
+
:valign => 'top',
|
49
|
+
:align => 'left'
|
50
|
+
)
|
51
|
+
|
52
|
+
worksheet.merge_range('B5:D6', 'Aligned to the top and left', format2)
|
53
|
+
|
54
|
+
###############################################################################
|
55
|
+
#
|
56
|
+
# Example 3: Text aligned to the bottom and right
|
57
|
+
#
|
58
|
+
format3 = workbook.add_format(
|
59
|
+
:border => 6,
|
60
|
+
:bold => 1,
|
61
|
+
:color => 'red',
|
62
|
+
:valign => 'bottom',
|
63
|
+
:align => 'right'
|
64
|
+
)
|
65
|
+
|
66
|
+
worksheet.merge_range('B8:D9', 'Aligned to the bottom and right', format3)
|
67
|
+
|
68
|
+
###############################################################################
|
69
|
+
#
|
70
|
+
# Example 4: Text justified (i.e. wrapped) in the cell
|
71
|
+
#
|
72
|
+
format4 = workbook.add_format(
|
73
|
+
:border => 6,
|
74
|
+
:bold => 1,
|
75
|
+
:color => 'red',
|
76
|
+
:valign => 'top',
|
77
|
+
:align => 'justify'
|
78
|
+
)
|
79
|
+
|
80
|
+
worksheet.merge_range('B11:D12', 'Justified: '+'so on and '*18, format4)
|
81
|
+
|
82
|
+
workbook.close
|