writeexcel 0.1.0 → 0.3.0
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.
- data/README +26 -31
- data/examples/a_simple.rb +42 -42
- data/examples/{autofilters.rb → autofilter.rb} +264 -266
- data/examples/bigfile.rb +29 -0
- data/examples/chart_area.rb +120 -0
- data/examples/chart_bar.rb +119 -0
- data/examples/chart_column.rb +119 -0
- data/examples/chart_line.rb +119 -0
- data/examples/chart_pie.rb +107 -0
- data/examples/chart_scatter.rb +120 -0
- data/examples/chart_stock.rb +147 -0
- data/examples/copyformat.rb +51 -51
- data/examples/data_validate.rb +278 -278
- data/examples/date_time.rb +86 -86
- data/examples/defined_name.rb +31 -0
- data/examples/demo.rb +120 -118
- data/examples/diag_border.rb +35 -35
- data/examples/formats.rb +489 -489
- data/examples/header.rb +136 -136
- data/examples/hidden.rb +28 -28
- data/examples/hyperlink.rb +42 -42
- data/examples/images.rb +52 -52
- data/examples/merge1.rb +39 -39
- data/examples/merge2.rb +44 -44
- data/examples/merge3.rb +65 -65
- data/examples/merge4.rb +82 -82
- data/examples/merge5.rb +79 -79
- data/examples/properties.rb +33 -0
- data/examples/properties_jp.rb +32 -0
- data/examples/protection.rb +46 -46
- data/examples/regions.rb +52 -52
- data/examples/repeat.rb +42 -42
- data/examples/stats.rb +75 -75
- data/examples/stocks.rb +80 -80
- data/examples/tab_colors.rb +30 -30
- data/examples/write_arrays.rb +82 -0
- data/lib/writeexcel.rb +1134 -18
- data/lib/writeexcel/biffwriter.rb +273 -260
- data/lib/writeexcel/chart.rb +2306 -217
- data/lib/writeexcel/charts/area.rb +152 -0
- data/lib/writeexcel/charts/bar.rb +177 -0
- data/lib/writeexcel/charts/column.rb +156 -0
- data/lib/writeexcel/charts/external.rb +61 -0
- data/lib/writeexcel/charts/line.rb +152 -0
- data/lib/writeexcel/charts/pie.rb +169 -0
- data/lib/writeexcel/charts/scatter.rb +192 -0
- data/lib/writeexcel/charts/stock.rb +211 -0
- data/lib/writeexcel/excelformulaparser.rb +208 -195
- data/lib/writeexcel/format.rb +1697 -1108
- data/lib/writeexcel/formula.rb +1050 -986
- data/lib/writeexcel/olewriter.rb +322 -322
- data/lib/writeexcel/properties.rb +251 -250
- data/lib/writeexcel/storage_lite.rb +968 -0
- data/lib/writeexcel/workbook.rb +3294 -2630
- data/lib/writeexcel/worksheet.rb +9012 -6377
- data/test/excelfile/Chart1.xls +0 -0
- data/test/excelfile/Chart2.xls +0 -0
- data/test/excelfile/Chart3.xls +0 -0
- data/test/excelfile/Chart4.xls +0 -0
- data/test/excelfile/Chart5.xls +0 -0
- data/test/perl_output/Chart1.xls.data +0 -0
- data/test/perl_output/Chart2.xls.data +0 -0
- data/test/perl_output/Chart3.xls.data +0 -0
- data/test/perl_output/Chart4.xls.data +0 -0
- data/test/perl_output/Chart5.xls.data +0 -0
- data/test/perl_output/a_simple.xls +0 -0
- data/test/perl_output/autofilter.xls +0 -0
- data/test/perl_output/chart_area.xls +0 -0
- data/test/perl_output/chart_bar.xls +0 -0
- data/test/perl_output/chart_column.xls +0 -0
- data/test/perl_output/chart_line.xls +0 -0
- data/test/perl_output/data_validate.xls +0 -0
- data/test/perl_output/date_time.xls +0 -0
- data/test/perl_output/demo.xls +0 -0
- data/test/perl_output/demo101.bin +0 -0
- data/test/perl_output/demo201.bin +0 -0
- data/test/perl_output/demo301.bin +0 -0
- data/test/perl_output/demo401.bin +0 -0
- data/test/perl_output/demo501.bin +0 -0
- data/test/perl_output/diag_border.xls +0 -0
- data/test/perl_output/headers.xls +0 -0
- data/test/perl_output/hyperlink.xls +0 -0
- data/test/perl_output/images.xls +0 -0
- data/test/perl_output/merge1.xls +0 -0
- data/test/perl_output/merge2.xls +0 -0
- data/test/perl_output/merge3.xls +0 -0
- data/test/perl_output/merge4.xls +0 -0
- data/test/perl_output/merge5.xls +0 -0
- data/test/perl_output/protection.xls +0 -0
- data/test/perl_output/regions.xls +0 -0
- data/test/perl_output/stats.xls +0 -0
- data/test/perl_output/stocks.xls +0 -0
- data/test/perl_output/tab_colors.xls +0 -0
- data/test/perl_output/unicode_cyrillic.xls +0 -0
- data/test/perl_output/workbook1.xls +0 -0
- data/test/perl_output/workbook2.xls +0 -0
- data/test/tc_all.rb +32 -31
- data/test/tc_biff.rb +104 -104
- data/test/tc_chart.rb +22 -22
- data/test/tc_example_match.rb +1944 -1280
- data/test/tc_format.rb +1254 -1267
- data/test/tc_formula.rb +63 -63
- data/test/tc_ole.rb +110 -110
- data/test/tc_storage_lite.rb +149 -0
- data/test/tc_workbook.rb +140 -115
- data/test/tc_worksheet.rb +115 -115
- data/test/test_00_IEEE_double.rb +14 -14
- data/test/test_01_add_worksheet.rb +12 -12
- data/test/test_02_merge_formats.rb +58 -58
- data/test/test_04_dimensions.rb +397 -397
- data/test/test_05_rows.rb +182 -182
- data/test/test_06_extsst.rb +80 -80
- data/test/test_11_date_time.rb +484 -484
- data/test/test_12_date_only.rb +506 -506
- data/test/test_13_date_seconds.rb +486 -486
- data/test/test_21_escher.rb +642 -629
- data/test/test_22_mso_drawing_group.rb +750 -739
- data/test/test_23_note.rb +78 -78
- data/test/test_24_txo.rb +80 -80
- data/test/test_25_position_object.rb +82 -0
- data/test/test_26_autofilter.rb +327 -327
- data/test/test_27_autofilter.rb +144 -144
- data/test/test_28_autofilter.rb +174 -174
- data/test/test_29_process_jpg.rb +681 -131
- data/test/test_30_validation_dval.rb +82 -82
- data/test/test_31_validation_dv_strings.rb +131 -131
- data/test/test_32_validation_dv_formula.rb +211 -211
- data/test/test_40_property_types.rb +191 -191
- data/test/test_41_properties.rb +238 -238
- data/test/test_42_set_properties.rb +442 -419
- data/test/test_50_name_stored.rb +305 -0
- data/test/test_51_name_print_area.rb +363 -0
- data/test/test_52_name_print_titles.rb +460 -0
- data/test/test_53_autofilter.rb +209 -0
- data/test/test_60_chart_generic.rb +576 -0
- data/test/test_61_chart_subclasses.rb +97 -0
- data/test/test_62_chart_formats.rb +270 -0
- data/test/test_63_chart_area_formats.rb +647 -0
- data/test/test_chartex.rb +35 -0
- data/test/ts_all.rb +46 -34
- data/writeexcel.gemspec +18 -0
- data/writeexcel.rdoc +583 -0
- metadata +162 -108
data/examples/merge1.rb
CHANGED
@@ -1,39 +1,39 @@
|
|
1
|
-
#!/usr/bin/ruby -w
|
2
|
-
|
3
|
-
###############################################################################
|
4
|
-
#
|
5
|
-
# Simple example of merging cells using the
|
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 =
|
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
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
|
3
|
+
###############################################################################
|
4
|
+
#
|
5
|
+
# Simple example of merging cells using the 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 = 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
CHANGED
@@ -1,44 +1,44 @@
|
|
1
|
-
#!/usr/bin/ruby -w
|
2
|
-
|
3
|
-
###############################################################################
|
4
|
-
#
|
5
|
-
# Simple example of merging cells using the
|
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 =
|
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
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
|
3
|
+
###############################################################################
|
4
|
+
#
|
5
|
+
# Simple example of merging cells using the 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 = 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
CHANGED
@@ -1,65 +1,65 @@
|
|
1
|
-
#!/usr/bin/ruby -w
|
2
|
-
|
3
|
-
###############################################################################
|
4
|
-
#
|
5
|
-
# Example of how to use
|
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 =
|
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
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
|
3
|
+
###############################################################################
|
4
|
+
#
|
5
|
+
# Example of how to use 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 = 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
CHANGED
@@ -1,82 +1,82 @@
|
|
1
|
-
#!/usr/bin/ruby -w
|
2
|
-
|
3
|
-
###############################################################################
|
4
|
-
#
|
5
|
-
# Example of how to use the
|
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 =
|
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
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
|
3
|
+
###############################################################################
|
4
|
+
#
|
5
|
+
# Example of how to use the 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 = 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
|