writeexcel 0.1.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (143) hide show
  1. data/README +26 -31
  2. data/examples/a_simple.rb +42 -42
  3. data/examples/{autofilters.rb → autofilter.rb} +264 -266
  4. data/examples/bigfile.rb +29 -0
  5. data/examples/chart_area.rb +120 -0
  6. data/examples/chart_bar.rb +119 -0
  7. data/examples/chart_column.rb +119 -0
  8. data/examples/chart_line.rb +119 -0
  9. data/examples/chart_pie.rb +107 -0
  10. data/examples/chart_scatter.rb +120 -0
  11. data/examples/chart_stock.rb +147 -0
  12. data/examples/copyformat.rb +51 -51
  13. data/examples/data_validate.rb +278 -278
  14. data/examples/date_time.rb +86 -86
  15. data/examples/defined_name.rb +31 -0
  16. data/examples/demo.rb +120 -118
  17. data/examples/diag_border.rb +35 -35
  18. data/examples/formats.rb +489 -489
  19. data/examples/header.rb +136 -136
  20. data/examples/hidden.rb +28 -28
  21. data/examples/hyperlink.rb +42 -42
  22. data/examples/images.rb +52 -52
  23. data/examples/merge1.rb +39 -39
  24. data/examples/merge2.rb +44 -44
  25. data/examples/merge3.rb +65 -65
  26. data/examples/merge4.rb +82 -82
  27. data/examples/merge5.rb +79 -79
  28. data/examples/properties.rb +33 -0
  29. data/examples/properties_jp.rb +32 -0
  30. data/examples/protection.rb +46 -46
  31. data/examples/regions.rb +52 -52
  32. data/examples/repeat.rb +42 -42
  33. data/examples/stats.rb +75 -75
  34. data/examples/stocks.rb +80 -80
  35. data/examples/tab_colors.rb +30 -30
  36. data/examples/write_arrays.rb +82 -0
  37. data/lib/writeexcel.rb +1134 -18
  38. data/lib/writeexcel/biffwriter.rb +273 -260
  39. data/lib/writeexcel/chart.rb +2306 -217
  40. data/lib/writeexcel/charts/area.rb +152 -0
  41. data/lib/writeexcel/charts/bar.rb +177 -0
  42. data/lib/writeexcel/charts/column.rb +156 -0
  43. data/lib/writeexcel/charts/external.rb +61 -0
  44. data/lib/writeexcel/charts/line.rb +152 -0
  45. data/lib/writeexcel/charts/pie.rb +169 -0
  46. data/lib/writeexcel/charts/scatter.rb +192 -0
  47. data/lib/writeexcel/charts/stock.rb +211 -0
  48. data/lib/writeexcel/excelformulaparser.rb +208 -195
  49. data/lib/writeexcel/format.rb +1697 -1108
  50. data/lib/writeexcel/formula.rb +1050 -986
  51. data/lib/writeexcel/olewriter.rb +322 -322
  52. data/lib/writeexcel/properties.rb +251 -250
  53. data/lib/writeexcel/storage_lite.rb +968 -0
  54. data/lib/writeexcel/workbook.rb +3294 -2630
  55. data/lib/writeexcel/worksheet.rb +9012 -6377
  56. data/test/excelfile/Chart1.xls +0 -0
  57. data/test/excelfile/Chart2.xls +0 -0
  58. data/test/excelfile/Chart3.xls +0 -0
  59. data/test/excelfile/Chart4.xls +0 -0
  60. data/test/excelfile/Chart5.xls +0 -0
  61. data/test/perl_output/Chart1.xls.data +0 -0
  62. data/test/perl_output/Chart2.xls.data +0 -0
  63. data/test/perl_output/Chart3.xls.data +0 -0
  64. data/test/perl_output/Chart4.xls.data +0 -0
  65. data/test/perl_output/Chart5.xls.data +0 -0
  66. data/test/perl_output/a_simple.xls +0 -0
  67. data/test/perl_output/autofilter.xls +0 -0
  68. data/test/perl_output/chart_area.xls +0 -0
  69. data/test/perl_output/chart_bar.xls +0 -0
  70. data/test/perl_output/chart_column.xls +0 -0
  71. data/test/perl_output/chart_line.xls +0 -0
  72. data/test/perl_output/data_validate.xls +0 -0
  73. data/test/perl_output/date_time.xls +0 -0
  74. data/test/perl_output/demo.xls +0 -0
  75. data/test/perl_output/demo101.bin +0 -0
  76. data/test/perl_output/demo201.bin +0 -0
  77. data/test/perl_output/demo301.bin +0 -0
  78. data/test/perl_output/demo401.bin +0 -0
  79. data/test/perl_output/demo501.bin +0 -0
  80. data/test/perl_output/diag_border.xls +0 -0
  81. data/test/perl_output/headers.xls +0 -0
  82. data/test/perl_output/hyperlink.xls +0 -0
  83. data/test/perl_output/images.xls +0 -0
  84. data/test/perl_output/merge1.xls +0 -0
  85. data/test/perl_output/merge2.xls +0 -0
  86. data/test/perl_output/merge3.xls +0 -0
  87. data/test/perl_output/merge4.xls +0 -0
  88. data/test/perl_output/merge5.xls +0 -0
  89. data/test/perl_output/protection.xls +0 -0
  90. data/test/perl_output/regions.xls +0 -0
  91. data/test/perl_output/stats.xls +0 -0
  92. data/test/perl_output/stocks.xls +0 -0
  93. data/test/perl_output/tab_colors.xls +0 -0
  94. data/test/perl_output/unicode_cyrillic.xls +0 -0
  95. data/test/perl_output/workbook1.xls +0 -0
  96. data/test/perl_output/workbook2.xls +0 -0
  97. data/test/tc_all.rb +32 -31
  98. data/test/tc_biff.rb +104 -104
  99. data/test/tc_chart.rb +22 -22
  100. data/test/tc_example_match.rb +1944 -1280
  101. data/test/tc_format.rb +1254 -1267
  102. data/test/tc_formula.rb +63 -63
  103. data/test/tc_ole.rb +110 -110
  104. data/test/tc_storage_lite.rb +149 -0
  105. data/test/tc_workbook.rb +140 -115
  106. data/test/tc_worksheet.rb +115 -115
  107. data/test/test_00_IEEE_double.rb +14 -14
  108. data/test/test_01_add_worksheet.rb +12 -12
  109. data/test/test_02_merge_formats.rb +58 -58
  110. data/test/test_04_dimensions.rb +397 -397
  111. data/test/test_05_rows.rb +182 -182
  112. data/test/test_06_extsst.rb +80 -80
  113. data/test/test_11_date_time.rb +484 -484
  114. data/test/test_12_date_only.rb +506 -506
  115. data/test/test_13_date_seconds.rb +486 -486
  116. data/test/test_21_escher.rb +642 -629
  117. data/test/test_22_mso_drawing_group.rb +750 -739
  118. data/test/test_23_note.rb +78 -78
  119. data/test/test_24_txo.rb +80 -80
  120. data/test/test_25_position_object.rb +82 -0
  121. data/test/test_26_autofilter.rb +327 -327
  122. data/test/test_27_autofilter.rb +144 -144
  123. data/test/test_28_autofilter.rb +174 -174
  124. data/test/test_29_process_jpg.rb +681 -131
  125. data/test/test_30_validation_dval.rb +82 -82
  126. data/test/test_31_validation_dv_strings.rb +131 -131
  127. data/test/test_32_validation_dv_formula.rb +211 -211
  128. data/test/test_40_property_types.rb +191 -191
  129. data/test/test_41_properties.rb +238 -238
  130. data/test/test_42_set_properties.rb +442 -419
  131. data/test/test_50_name_stored.rb +305 -0
  132. data/test/test_51_name_print_area.rb +363 -0
  133. data/test/test_52_name_print_titles.rb +460 -0
  134. data/test/test_53_autofilter.rb +209 -0
  135. data/test/test_60_chart_generic.rb +576 -0
  136. data/test/test_61_chart_subclasses.rb +97 -0
  137. data/test/test_62_chart_formats.rb +270 -0
  138. data/test/test_63_chart_area_formats.rb +647 -0
  139. data/test/test_chartex.rb +35 -0
  140. data/test/ts_all.rb +46 -34
  141. data/writeexcel.gemspec +18 -0
  142. data/writeexcel.rdoc +583 -0
  143. metadata +162 -108
@@ -0,0 +1,107 @@
1
+ #!/usr/bin/ruby -w
2
+ #
3
+ ###############################################################################
4
+ #
5
+ # A simple demo of Pie chart in Spreadsheet::WriteExcel.
6
+ #
7
+ # reverse('ゥ'), December 2009, 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 'writeexcel'
13
+
14
+ # Create a new workbook called simple.xls and add a worksheet
15
+ workbook = WriteExcel.new('chart_pie.xls')
16
+ worksheet = workbook.add_worksheet
17
+ bold = workbook.add_format(:bold => 1)
18
+
19
+ # Add the worksheet data that the charts will refer to.
20
+ headings = ['Category', 'Values']
21
+ data = [
22
+ [ 'Apple', 'Cherry', 'Pecan' ],
23
+ [ 60, 30, 10 ]
24
+ ]
25
+
26
+ worksheet.write('A1', headings, bold)
27
+ worksheet.write('A2', data)
28
+
29
+
30
+ ###############################################################################
31
+ #
32
+ # Example 1. A minimal chart.
33
+ #
34
+ chart1 = workbook.add_chart(:type => Chart::Pie)
35
+
36
+ # Add values only. Use the default categories.
37
+ chart1.add_series(:values => '=Sheet1!$B$2:$B$4')
38
+
39
+ ###############################################################################
40
+ #
41
+ # Example 2. A minimal chart with user specified categories and a series name.
42
+ #
43
+ chart2 = workbook.add_chart(:type => Chart::Pie)
44
+
45
+ # Configure the series.
46
+ chart2.add_series(
47
+ :categories => '=Sheet1!$A$2:$A$4',
48
+ :values => '=Sheet1!$B$2:$B$4',
49
+ :name => 'Pie sales data'
50
+ )
51
+
52
+ ###############################################################################
53
+ #
54
+ # Example 3. Same as previous chart but with an added title.
55
+ #
56
+ chart3 = workbook.add_chart(:type => Chart::Pie)
57
+
58
+ # Configure the series.
59
+ chart3.add_series(
60
+ :categories => '=Sheet1!$A$2:$A$4',
61
+ :values => '=Sheet1!$B$2:$B$4',
62
+ :name => 'Pie sales data'
63
+ )
64
+
65
+ # Add a title.
66
+ chart3.set_title(:name => 'Popular Pie Types')
67
+
68
+ ###############################################################################
69
+ #
70
+ # Example 4. Same as previous chart with a user specified chart sheet name.
71
+ #
72
+ chart4 = workbook.add_chart(:name => 'Results Chart', :type => Chart::Pie)
73
+
74
+ # Configure the series.
75
+ chart4.add_series(
76
+ :categories => '=Sheet1!$A$2:$A$4',
77
+ :values => '=Sheet1!$B$2:$B$4',
78
+ :name => 'Pie sales data'
79
+ )
80
+
81
+ # The other chart_*.rb examples add a second series in example 4 but additional
82
+ # series aren't plotted in a pie chart.
83
+
84
+ # Add a title.
85
+ chart4.set_title(:name => 'Popular Pie Types')
86
+
87
+ ###############################################################################
88
+ #
89
+ # Example 5. Same as Example 3 but as an embedded chart.
90
+ #
91
+ chart5 = workbook.add_chart(:type => Chart::Pie, :embedded => 1)
92
+
93
+ # Configure the series.
94
+ chart5.add_series(
95
+ :categories => '=Sheet1!$A$2:$A$4',
96
+ :values => '=Sheet1!$B$2:$B$4',
97
+ :name => 'Pie sales data'
98
+ )
99
+
100
+ # Add a title.
101
+ chart5.set_title(:name => 'Popular Pie Types')
102
+
103
+ # Insert the chart into the main worksheet.
104
+ worksheet.insert_chart('D2', chart5)
105
+
106
+ # File save
107
+ workbook.close
@@ -0,0 +1,120 @@
1
+ #!/usr/bin/ruby -w
2
+ #
3
+ ###############################################################################
4
+ #
5
+ # A simple demo of Scatter charts in Spreadsheet::WriteExcel.
6
+ #
7
+ # reverse('ゥ'), December 2009, 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 'writeexcel'
13
+
14
+ # Create a new workbook called simple.xls and add a worksheet
15
+ workbook = WriteExcel.new('chart_scatter.xls')
16
+ worksheet = workbook.add_worksheet
17
+ bold = workbook.add_format(:bold => 1)
18
+
19
+ # Add the worksheet data that the charts will refer to.
20
+ headings = ['Category', 'Values 1', 'Values 2']
21
+ data = [
22
+ [ 2, 3, 4, 5, 6, 7 ],
23
+ [ 1, 4, 5, 2, 1, 5 ],
24
+ [ 3, 6, 7, 5, 4, 3 ]
25
+ ]
26
+
27
+ worksheet.write('A1', headings, bold)
28
+ worksheet.write('A2', data)
29
+
30
+
31
+ ###############################################################################
32
+ #
33
+ # Example 1. A minimal chart.
34
+ #
35
+ chart1 = workbook.add_chart(:type => Chart::Scatter)
36
+
37
+ # Add values only. Use the default categories.
38
+ chart1.add_series(:values => '=Sheet1!$B$2:$B$7')
39
+
40
+ ###############################################################################
41
+ #
42
+ # Example 2. A minimal chart with user specified categories (X axis)
43
+ # and a series name.
44
+ #
45
+ chart2 = workbook.add_chart(:type => Chart::Scatter)
46
+
47
+ # Configure the series.
48
+ chart2.add_series(
49
+ :categories => '=Sheet1!$A$2:$A$7',
50
+ :values => '=Sheet1!$B$2:$B$7',
51
+ :name => 'Test data series 1'
52
+ )
53
+
54
+ ###############################################################################
55
+ #
56
+ # Example 3. Same as previous chart but with added title and axes labels.
57
+ #
58
+ chart3 = workbook.add_chart(:type => Chart::Scatter)
59
+
60
+ # Configure the series.
61
+ chart3.add_series(
62
+ :categories => '=Sheet1!$A$2:$A$7',
63
+ :values => '=Sheet1!$B$2:$B$7',
64
+ :name => 'Test data series 1'
65
+ )
66
+
67
+ # Add some labels.
68
+ chart3.set_title(:name => 'Results of sample analysis')
69
+ chart3.set_x_axis(:name => 'Sample number')
70
+ chart3.set_y_axis(:name => 'Sample length (cm)')
71
+
72
+ ###############################################################################
73
+ #
74
+ # Example 4. Same as previous chart but with an added series and with a
75
+ # user specified chart sheet name.
76
+ #
77
+ chart4 = workbook.add_chart(:name => 'Results Chart', :type => Chart::Scatter)
78
+
79
+ # Configure the series.
80
+ chart4.add_series(
81
+ :categories => '=Sheet1!$A$2:$A$7',
82
+ :values => '=Sheet1!$B$2:$B$7',
83
+ :name => 'Test data series 1'
84
+ )
85
+
86
+ # Add another series.
87
+ chart4.add_series(
88
+ :categories => '=Sheet1!$A$2:$A$7',
89
+ :values => '=Sheet1!$C$2:$C$7',
90
+ :name => 'Test data series 2'
91
+ )
92
+
93
+ # Add some labels.
94
+ chart4.set_title(:name => 'Results of sample analysis')
95
+ chart4.set_x_axis(:name => 'Sample number')
96
+ chart4.set_y_axis(:name => 'Sample length (cm)')
97
+
98
+ ###############################################################################
99
+ #
100
+ # Example 5. Same as Example 3 but as an embedded chart.
101
+ #
102
+ chart5 = workbook.add_chart(:type => Chart::Scatter, :embedded => 1)
103
+
104
+ # Configure the series.
105
+ chart5.add_series(
106
+ :categories => '=Sheet1!$A$2:$A$7',
107
+ :values => '=Sheet1!$B$2:$B$7',
108
+ :name => 'Test data series 1'
109
+ )
110
+
111
+ # Add some labels.
112
+ chart5.set_title(:name => 'Results of sample analysis')
113
+ chart5.set_x_axis(:name => 'Sample number')
114
+ chart5.set_y_axis(:name => 'Sample length (cm)')
115
+
116
+ # Insert the chart into the main worksheet.
117
+ worksheet.insert_chart('E2', chart5)
118
+
119
+ # File save
120
+ workbook.close
@@ -0,0 +1,147 @@
1
+ #!/usr/bin/ruby -w
2
+ #
3
+ ###############################################################################
4
+ #
5
+ # A simple demo of Stock charts in Spreadsheet::WriteExcel.
6
+ #
7
+ # reverse('©'), January 2010, 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 'writeexcel'
13
+
14
+ workbook = WriteExcel.new('chart_stock.xls')
15
+ worksheet = workbook.add_worksheet
16
+
17
+ ###############################################################################
18
+ #
19
+ # Set up the data worksheet that the charts will refer to. We read the example
20
+ # data from the __DATA__ section at the end of the file. This simulates
21
+ # reading the data from a database or other source.
22
+ #
23
+ # The default Excel Stock chart is an Open-High-Low-Close chart. Therefore
24
+ # we will need data for each of those series.
25
+ #
26
+ # The layout of the __DATA__ section is similar to the layout of the worksheet.
27
+ #
28
+
29
+ # Add some formats.
30
+ bold = workbook.add_format(:bold => 1)
31
+ date_format = workbook.add_format(:num_format => 'dd/mm/yyyy')
32
+
33
+ # Increase the width of the column used for date to make it clearer.
34
+ worksheet.set_column('A:A', 12)
35
+
36
+ stock_data = [
37
+ %w(Date Open High Low Close),
38
+ ['2009-08-19', 100.00, 104.06, 95.96, 100.34],
39
+ ['2009-08-20', 101.01, 109.08, 100.50, 108.31],
40
+ ['2009-08-23', 110.75, 113.48, 109.05, 109.40],
41
+ ['2009-08-24', 111.24, 111.60, 103.57, 104.87],
42
+ ['2009-08-25', 104.96, 108.00, 103.88, 106.00],
43
+ ['2009-08-26', 104.95, 107.95, 104.66, 107.91],
44
+ ['2009-08-27', 108.10, 108.62, 105.69, 106.15],
45
+ ['2009-08-30', 105.28, 105.49, 102.01, 102.01],
46
+ ['2009-08-31', 102.30, 103.71, 102.16, 102.37]
47
+ ]
48
+
49
+ # Write the data to the worksheet.
50
+ row = 0
51
+ col = 0
52
+
53
+ headers = stock_data.shift
54
+ worksheet.write(row, col, headers, bold)
55
+ row += 1
56
+
57
+ stock_data.each do |data|
58
+ date = data.shift
59
+ worksheet.write(row, col, date, date_format)
60
+ worksheet.write(row, col + 1, data)
61
+ row += 1
62
+ end
63
+
64
+ ###############################################################################
65
+ #
66
+ # Example 1. A default Open-High-Low-Close chart with series names, axes labels
67
+ # and a title.
68
+ #
69
+
70
+ chart1 = workbook.add_chart(:type => Chart::Stock)
71
+
72
+ # Add a series for each of the Open-High-Low-Close columns. The categories are
73
+ # the dates in the first column.
74
+
75
+ chart1.add_series(
76
+ :categories => '=Sheet1!$A$2:$A$10',
77
+ :values => '=Sheet1!$B$2:$B$10',
78
+ :name => 'Open'
79
+ )
80
+
81
+ chart1.add_series(
82
+ :categories => '=Sheet1!$A$2:$A$10',
83
+ :values => '=Sheet1!$C$2:$C$10',
84
+ :name => 'High'
85
+ )
86
+
87
+ chart1.add_series(
88
+ :categories => '=Sheet1!$A$2:$A$10',
89
+ :values => '=Sheet1!$D$2:$D$10',
90
+ :name => 'Low'
91
+ )
92
+
93
+ chart1.add_series(
94
+ :categories => '=Sheet1!$A$2:$A$10',
95
+ :values => '=Sheet1!$E$2:$E$10',
96
+ :name => 'Close'
97
+ )
98
+
99
+ # Add a chart title and axes labels.
100
+ chart1.set_title(:name => 'Open-High-Low-Close')
101
+ chart1.set_x_axis(:name => 'Date')
102
+ chart1.set_y_axis(:name => 'Share price')
103
+
104
+ ###############################################################################
105
+ #
106
+ # Example 2. Same as the previous as an embedded chart.
107
+ #
108
+
109
+ chart2 = workbook.add_chart(:type => Chart::Stock, :embedded => 1)
110
+
111
+ # Add a series for each of the Open-High-Low-Close columns. The categories are
112
+ # the dates in the first column.
113
+
114
+ chart2.add_series(
115
+ :categories => '=Sheet1!$A$2:$A$10',
116
+ :values => '=Sheet1!$B$2:$B$10',
117
+ :name => 'Open'
118
+ )
119
+
120
+ chart2.add_series(
121
+ :categories => '=Sheet1!$A$2:$A$10',
122
+ :values => '=Sheet1!$C$2:$C$10',
123
+ :name => 'High'
124
+ )
125
+
126
+ chart2.add_series(
127
+ :categories => '=Sheet1!$A$2:$A$10',
128
+ :values => '=Sheet1!$D$2:$D$10',
129
+ :name => 'Low'
130
+ )
131
+
132
+ chart2.add_series(
133
+ :categories => '=Sheet1!$A$2:$A$10',
134
+ :values => '=Sheet1!$E$2:$E$10',
135
+ :name => 'Close'
136
+ )
137
+
138
+ # Add a chart title and axes labels.
139
+ chart2.set_title(:name => 'Open-High-Low-Close')
140
+ chart2.set_x_axis(:name => 'Date')
141
+ chart2.set_y_axis(:name => 'Share price')
142
+
143
+ # Insert the chart into the main worksheet.
144
+ worksheet.insert_chart('G2', chart2)
145
+
146
+ # File save
147
+ workbook.close
@@ -1,51 +1,51 @@
1
- #!/usr/bin/ruby -w
2
-
3
- ###############################################################################
4
- #
5
- # Example of how to use the format copying method with Spreadsheet::WriteExcel #
6
- # reverse('©'), March 2001, John McNamara, jmcnamara@cpan.org
7
- #
8
- # original written in Perl by John McNamara
9
- # converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
10
- #
11
- require 'rubygems'
12
- require 'writeexcel'
13
-
14
- # Create workbook1
15
- workbook1 = Spreadsheet::WriteExcel.new("workbook1.xls")
16
- worksheet1 = workbook1.add_worksheet
17
- format1a = workbook1.add_format
18
- format1b = workbook1.add_format
19
-
20
- # Create workbook2
21
- workbook2 = Spreadsheet::WriteExcel.new("workbook2.xls")
22
- worksheet2 = workbook2.add_worksheet
23
- format2a = workbook2.add_format
24
- format2b = workbook2.add_format
25
-
26
- # Create a global format object that isn't tied to a workbook
27
- global_format = Format.new
28
-
29
- # Set the formatting
30
- global_format.set_color('blue')
31
- global_format.set_bold
32
- global_format.set_italic
33
-
34
- # Create another example format
35
- format1b.set_color('red')
36
-
37
- # Copy the global format properties to the worksheet formats
38
- format1a.copy(global_format)
39
- format2a.copy(global_format)
40
-
41
- # Copy a format from worksheet1 to worksheet2
42
- format2b.copy(format1b)
43
-
44
- # Write some output
45
- worksheet1.write(0, 0, "Ciao", format1a)
46
- worksheet1.write(1, 0, "Ciao", format1b)
47
-
48
- worksheet2.write(0, 0, "Hello", format2a)
49
- worksheet2.write(1, 0, "Hello", format2b)
50
- workbook1.close
51
- workbook2.close
1
+ #!/usr/bin/ruby -w
2
+
3
+ ###############################################################################
4
+ #
5
+ # Example of how to use the format copying method with WriteExcel #
6
+ # reverse('©'), March 2001, John McNamara, jmcnamara@cpan.org
7
+ #
8
+ # original written in Perl by John McNamara
9
+ # converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
10
+ #
11
+ require 'rubygems'
12
+ require 'writeexcel'
13
+
14
+ # Create workbook1
15
+ workbook1 = WriteExcel.new("workbook1.xls")
16
+ worksheet1 = workbook1.add_worksheet
17
+ format1a = workbook1.add_format
18
+ format1b = workbook1.add_format
19
+
20
+ # Create workbook2
21
+ workbook2 = WriteExcel.new("workbook2.xls")
22
+ worksheet2 = workbook2.add_worksheet
23
+ format2a = workbook2.add_format
24
+ format2b = workbook2.add_format
25
+
26
+ # Create a global format object that isn't tied to a workbook
27
+ global_format = Format.new
28
+
29
+ # Set the formatting
30
+ global_format.set_color('blue')
31
+ global_format.set_bold
32
+ global_format.set_italic
33
+
34
+ # Create another example format
35
+ format1b.set_color('red')
36
+
37
+ # Copy the global format properties to the worksheet formats
38
+ format1a.copy(global_format)
39
+ format2a.copy(global_format)
40
+
41
+ # Copy a format from worksheet1 to worksheet2
42
+ format2b.copy(format1b)
43
+
44
+ # Write some output
45
+ worksheet1.write(0, 0, "Ciao", format1a)
46
+ worksheet1.write(1, 0, "Ciao", format1b)
47
+
48
+ worksheet2.write(0, 0, "Hello", format2a)
49
+ worksheet2.write(1, 0, "Hello", format2b)
50
+ workbook1.close
51
+ workbook2.close