writeexcel 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. data/.gitattributes +1 -1
  2. data/.gitignore +24 -24
  3. data/README.rdoc +34 -55
  4. data/VERSION +1 -1
  5. data/charts/chartex.rb +316 -316
  6. data/charts/demo1.rb +46 -46
  7. data/charts/demo2.rb +65 -65
  8. data/charts/demo3.rb +117 -117
  9. data/charts/demo4.rb +119 -119
  10. data/charts/demo5.rb +48 -48
  11. data/examples/a_simple.rb +43 -43
  12. data/examples/autofilter.rb +265 -265
  13. data/examples/bigfile.rb +30 -30
  14. data/examples/chart_area.rb +121 -121
  15. data/examples/chart_bar.rb +120 -120
  16. data/examples/chart_column.rb +120 -120
  17. data/examples/chart_line.rb +120 -120
  18. data/examples/chart_pie.rb +108 -108
  19. data/examples/chart_scatter.rb +121 -121
  20. data/examples/chart_stock.rb +148 -148
  21. data/examples/chess.rb +142 -142
  22. data/examples/colors.rb +129 -129
  23. data/examples/comments1.rb +27 -27
  24. data/examples/comments2.rb +352 -352
  25. data/examples/copyformat.rb +52 -52
  26. data/examples/data_validate.rb +279 -279
  27. data/examples/date_time.rb +87 -87
  28. data/examples/defined_name.rb +32 -32
  29. data/examples/demo.rb +124 -124
  30. data/examples/diag_border.rb +36 -36
  31. data/examples/formats.rb +490 -490
  32. data/examples/formula_result.rb +30 -30
  33. data/examples/header.rb +137 -137
  34. data/examples/hide_sheet.rb +29 -29
  35. data/examples/hyperlink.rb +43 -43
  36. data/examples/images.rb +63 -63
  37. data/examples/indent.rb +31 -31
  38. data/examples/merge1.rb +40 -40
  39. data/examples/merge2.rb +45 -45
  40. data/examples/merge3.rb +66 -66
  41. data/examples/merge4.rb +83 -83
  42. data/examples/merge5.rb +80 -80
  43. data/examples/merge6.rb +67 -67
  44. data/examples/outline.rb +255 -255
  45. data/examples/outline_collapsed.rb +209 -209
  46. data/examples/panes.rb +113 -113
  47. data/examples/properties.rb +34 -34
  48. data/examples/properties_jp.rb +33 -33
  49. data/examples/protection.rb +47 -47
  50. data/examples/regions.rb +53 -53
  51. data/examples/repeat.rb +43 -43
  52. data/examples/right_to_left.rb +27 -27
  53. data/examples/row_wrap.rb +53 -53
  54. data/examples/stats.rb +74 -74
  55. data/examples/stocks.rb +81 -81
  56. data/examples/tab_colors.rb +31 -31
  57. data/examples/utf8.rb +15 -15
  58. data/examples/write_arrays.rb +83 -83
  59. data/lib/writeexcel/biffwriter.rb +232 -232
  60. data/lib/writeexcel/caller_info.rb +12 -12
  61. data/lib/writeexcel/chart.rb +2190 -2177
  62. data/lib/writeexcel/charts/area.rb +154 -154
  63. data/lib/writeexcel/charts/bar.rb +177 -177
  64. data/lib/writeexcel/charts/column.rb +156 -156
  65. data/lib/writeexcel/charts/external.rb +66 -66
  66. data/lib/writeexcel/charts/line.rb +154 -154
  67. data/lib/writeexcel/charts/pie.rb +169 -169
  68. data/lib/writeexcel/charts/scatter.rb +192 -192
  69. data/lib/writeexcel/charts/stock.rb +213 -213
  70. data/lib/writeexcel/colors.rb +64 -64
  71. data/lib/writeexcel/compatibility.rb +0 -255
  72. data/lib/writeexcel/debug_info.rb +37 -33
  73. data/lib/writeexcel/excelformulaparser.rb +587 -587
  74. data/lib/writeexcel/format.rb +13 -4
  75. data/lib/writeexcel/formula.rb +26 -9
  76. data/lib/writeexcel/helper.rb +68 -64
  77. data/lib/writeexcel/olewriter.rb +311 -311
  78. data/lib/writeexcel/properties.rb +242 -240
  79. data/lib/writeexcel/storage_lite.rb +984 -978
  80. data/lib/writeexcel/workbook.rb +3210 -3192
  81. data/lib/writeexcel/worksheet.rb +143 -51
  82. data/lib/writeexcel/write_file.rb +44 -40
  83. data/lib/writeexcel.rb +1159 -1159
  84. data/test/helper.rb +31 -28
  85. data/test/perl_output/README +31 -31
  86. data/test/test_00_IEEE_double.rb +13 -13
  87. data/test/test_01_add_worksheet.rb +10 -10
  88. data/test/test_02_merge_formats.rb +53 -53
  89. data/test/test_04_dimensions.rb +392 -392
  90. data/test/test_05_rows.rb +179 -179
  91. data/test/test_06_extsst.rb +77 -77
  92. data/test/test_11_date_time.rb +479 -479
  93. data/test/test_12_date_only.rb +501 -501
  94. data/test/test_13_date_seconds.rb +481 -481
  95. data/test/test_21_escher.rb +637 -637
  96. data/test/test_22_mso_drawing_group.rb +745 -745
  97. data/test/test_23_note.rb +73 -73
  98. data/test/test_24_txo.rb +75 -75
  99. data/test/test_25_position_object.rb +84 -84
  100. data/test/test_26_autofilter.rb +314 -314
  101. data/test/test_27_autofilter.rb +131 -131
  102. data/test/test_28_autofilter.rb +161 -161
  103. data/test/test_29_process_jpg.rb +683 -683
  104. data/test/test_30_validation_dval.rb +77 -77
  105. data/test/test_31_validation_dv_strings.rb +126 -126
  106. data/test/test_32_validation_dv_formula.rb +206 -206
  107. data/test/test_40_property_types.rb +188 -188
  108. data/test/test_41_properties.rb +235 -235
  109. data/test/test_42_set_properties.rb +437 -437
  110. data/test/test_50_name_stored.rb +299 -299
  111. data/test/test_51_name_print_area.rb +357 -357
  112. data/test/test_52_name_print_titles.rb +454 -454
  113. data/test/test_53_autofilter.rb +203 -203
  114. data/test/test_60_chart_generic.rb +578 -578
  115. data/test/test_61_chart_subclasses.rb +95 -95
  116. data/test/test_62_chart_formats.rb +272 -272
  117. data/test/test_63_chart_area_formats.rb +649 -649
  118. data/test/test_biff.rb +75 -75
  119. data/test/test_compatibility.rb +12 -627
  120. data/test/test_example_match.rb +3144 -3144
  121. data/test/test_formula.rb +61 -61
  122. data/test/test_ole.rb +106 -106
  123. data/test/test_storage_lite.rb +125 -125
  124. data/test/test_workbook.rb +139 -139
  125. data/test/test_worksheet.rb +110 -110
  126. data/utils/add_magic_comment.rb +80 -80
  127. data/writeexcel.gemspec +4 -6
  128. data/writeexcel.rdoc +58 -15
  129. metadata +9 -6
  130. data/test/test_new_encoding.rb +0 -205
@@ -1,148 +1,148 @@
1
- #!/usr/bin/ruby -w
2
- # -*- coding: utf-8 -*-
3
- #
4
- ###############################################################################
5
- #
6
- # A simple demo of Stock charts in Spreadsheet::WriteExcel.
7
- #
8
- # reverse('©'), January 2010, 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 'writeexcel'
14
-
15
- workbook = WriteExcel.new('chart_stock.xls')
16
- worksheet = workbook.add_worksheet
17
-
18
- ###############################################################################
19
- #
20
- # Set up the data worksheet that the charts will refer to. We read the example
21
- # data from the __DATA__ section at the end of the file. This simulates
22
- # reading the data from a database or other source.
23
- #
24
- # The default Excel Stock chart is an Open-High-Low-Close chart. Therefore
25
- # we will need data for each of those series.
26
- #
27
- # The layout of the __DATA__ section is similar to the layout of the worksheet.
28
- #
29
-
30
- # Add some formats.
31
- bold = workbook.add_format(:bold => 1)
32
- date_format = workbook.add_format(:num_format => 'dd/mm/yyyy')
33
-
34
- # Increase the width of the column used for date to make it clearer.
35
- worksheet.set_column('A:A', 12)
36
-
37
- stock_data = [
38
- %w(Date Open High Low Close),
39
- ['2009-08-19', 100.00, 104.06, 95.96, 100.34],
40
- ['2009-08-20', 101.01, 109.08, 100.50, 108.31],
41
- ['2009-08-23', 110.75, 113.48, 109.05, 109.40],
42
- ['2009-08-24', 111.24, 111.60, 103.57, 104.87],
43
- ['2009-08-25', 104.96, 108.00, 103.88, 106.00],
44
- ['2009-08-26', 104.95, 107.95, 104.66, 107.91],
45
- ['2009-08-27', 108.10, 108.62, 105.69, 106.15],
46
- ['2009-08-30', 105.28, 105.49, 102.01, 102.01],
47
- ['2009-08-31', 102.30, 103.71, 102.16, 102.37]
48
- ]
49
-
50
- # Write the data to the worksheet.
51
- row = 0
52
- col = 0
53
-
54
- headers = stock_data.shift
55
- worksheet.write(row, col, headers, bold)
56
- row += 1
57
-
58
- stock_data.each do |data|
59
- date = data.shift
60
- worksheet.write(row, col, date, date_format)
61
- worksheet.write(row, col + 1, data)
62
- row += 1
63
- end
64
-
65
- ###############################################################################
66
- #
67
- # Example 1. A default Open-High-Low-Close chart with series names, axes labels
68
- # and a title.
69
- #
70
-
71
- chart1 = workbook.add_chart(:type => 'Chart::Stock')
72
-
73
- # Add a series for each of the Open-High-Low-Close columns. The categories are
74
- # the dates in the first column.
75
-
76
- chart1.add_series(
77
- :categories => '=Sheet1!$A$2:$A$10',
78
- :values => '=Sheet1!$B$2:$B$10',
79
- :name => 'Open'
80
- )
81
-
82
- chart1.add_series(
83
- :categories => '=Sheet1!$A$2:$A$10',
84
- :values => '=Sheet1!$C$2:$C$10',
85
- :name => 'High'
86
- )
87
-
88
- chart1.add_series(
89
- :categories => '=Sheet1!$A$2:$A$10',
90
- :values => '=Sheet1!$D$2:$D$10',
91
- :name => 'Low'
92
- )
93
-
94
- chart1.add_series(
95
- :categories => '=Sheet1!$A$2:$A$10',
96
- :values => '=Sheet1!$E$2:$E$10',
97
- :name => 'Close'
98
- )
99
-
100
- # Add a chart title and axes labels.
101
- chart1.set_title(:name => 'Open-High-Low-Close')
102
- chart1.set_x_axis(:name => 'Date')
103
- chart1.set_y_axis(:name => 'Share price')
104
-
105
- ###############################################################################
106
- #
107
- # Example 2. Same as the previous as an embedded chart.
108
- #
109
-
110
- chart2 = workbook.add_chart(:type => 'Chart::Stock', :embedded => 1)
111
-
112
- # Add a series for each of the Open-High-Low-Close columns. The categories are
113
- # the dates in the first column.
114
-
115
- chart2.add_series(
116
- :categories => '=Sheet1!$A$2:$A$10',
117
- :values => '=Sheet1!$B$2:$B$10',
118
- :name => 'Open'
119
- )
120
-
121
- chart2.add_series(
122
- :categories => '=Sheet1!$A$2:$A$10',
123
- :values => '=Sheet1!$C$2:$C$10',
124
- :name => 'High'
125
- )
126
-
127
- chart2.add_series(
128
- :categories => '=Sheet1!$A$2:$A$10',
129
- :values => '=Sheet1!$D$2:$D$10',
130
- :name => 'Low'
131
- )
132
-
133
- chart2.add_series(
134
- :categories => '=Sheet1!$A$2:$A$10',
135
- :values => '=Sheet1!$E$2:$E$10',
136
- :name => 'Close'
137
- )
138
-
139
- # Add a chart title and axes labels.
140
- chart2.set_title(:name => 'Open-High-Low-Close')
141
- chart2.set_x_axis(:name => 'Date')
142
- chart2.set_y_axis(:name => 'Share price')
143
-
144
- # Insert the chart into the main worksheet.
145
- worksheet.insert_chart('G2', chart2)
146
-
147
- # File save
148
- workbook.close
1
+ #!/usr/bin/ruby -w
2
+ # -*- coding: utf-8 -*-
3
+ #
4
+ ###############################################################################
5
+ #
6
+ # A simple demo of Stock charts in Spreadsheet::WriteExcel.
7
+ #
8
+ # reverse('©'), January 2010, 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 'writeexcel'
14
+
15
+ workbook = WriteExcel.new('chart_stock.xls')
16
+ worksheet = workbook.add_worksheet
17
+
18
+ ###############################################################################
19
+ #
20
+ # Set up the data worksheet that the charts will refer to. We read the example
21
+ # data from the __DATA__ section at the end of the file. This simulates
22
+ # reading the data from a database or other source.
23
+ #
24
+ # The default Excel Stock chart is an Open-High-Low-Close chart. Therefore
25
+ # we will need data for each of those series.
26
+ #
27
+ # The layout of the __DATA__ section is similar to the layout of the worksheet.
28
+ #
29
+
30
+ # Add some formats.
31
+ bold = workbook.add_format(:bold => 1)
32
+ date_format = workbook.add_format(:num_format => 'dd/mm/yyyy')
33
+
34
+ # Increase the width of the column used for date to make it clearer.
35
+ worksheet.set_column('A:A', 12)
36
+
37
+ stock_data = [
38
+ %w(Date Open High Low Close),
39
+ ['2009-08-19', 100.00, 104.06, 95.96, 100.34],
40
+ ['2009-08-20', 101.01, 109.08, 100.50, 108.31],
41
+ ['2009-08-23', 110.75, 113.48, 109.05, 109.40],
42
+ ['2009-08-24', 111.24, 111.60, 103.57, 104.87],
43
+ ['2009-08-25', 104.96, 108.00, 103.88, 106.00],
44
+ ['2009-08-26', 104.95, 107.95, 104.66, 107.91],
45
+ ['2009-08-27', 108.10, 108.62, 105.69, 106.15],
46
+ ['2009-08-30', 105.28, 105.49, 102.01, 102.01],
47
+ ['2009-08-31', 102.30, 103.71, 102.16, 102.37]
48
+ ]
49
+
50
+ # Write the data to the worksheet.
51
+ row = 0
52
+ col = 0
53
+
54
+ headers = stock_data.shift
55
+ worksheet.write(row, col, headers, bold)
56
+ row += 1
57
+
58
+ stock_data.each do |data|
59
+ date = data.shift
60
+ worksheet.write(row, col, date, date_format)
61
+ worksheet.write(row, col + 1, data)
62
+ row += 1
63
+ end
64
+
65
+ ###############################################################################
66
+ #
67
+ # Example 1. A default Open-High-Low-Close chart with series names, axes labels
68
+ # and a title.
69
+ #
70
+
71
+ chart1 = workbook.add_chart(:type => 'Chart::Stock')
72
+
73
+ # Add a series for each of the Open-High-Low-Close columns. The categories are
74
+ # the dates in the first column.
75
+
76
+ chart1.add_series(
77
+ :categories => '=Sheet1!$A$2:$A$10',
78
+ :values => '=Sheet1!$B$2:$B$10',
79
+ :name => 'Open'
80
+ )
81
+
82
+ chart1.add_series(
83
+ :categories => '=Sheet1!$A$2:$A$10',
84
+ :values => '=Sheet1!$C$2:$C$10',
85
+ :name => 'High'
86
+ )
87
+
88
+ chart1.add_series(
89
+ :categories => '=Sheet1!$A$2:$A$10',
90
+ :values => '=Sheet1!$D$2:$D$10',
91
+ :name => 'Low'
92
+ )
93
+
94
+ chart1.add_series(
95
+ :categories => '=Sheet1!$A$2:$A$10',
96
+ :values => '=Sheet1!$E$2:$E$10',
97
+ :name => 'Close'
98
+ )
99
+
100
+ # Add a chart title and axes labels.
101
+ chart1.set_title(:name => 'Open-High-Low-Close')
102
+ chart1.set_x_axis(:name => 'Date')
103
+ chart1.set_y_axis(:name => 'Share price')
104
+
105
+ ###############################################################################
106
+ #
107
+ # Example 2. Same as the previous as an embedded chart.
108
+ #
109
+
110
+ chart2 = workbook.add_chart(:type => 'Chart::Stock', :embedded => 1)
111
+
112
+ # Add a series for each of the Open-High-Low-Close columns. The categories are
113
+ # the dates in the first column.
114
+
115
+ chart2.add_series(
116
+ :categories => '=Sheet1!$A$2:$A$10',
117
+ :values => '=Sheet1!$B$2:$B$10',
118
+ :name => 'Open'
119
+ )
120
+
121
+ chart2.add_series(
122
+ :categories => '=Sheet1!$A$2:$A$10',
123
+ :values => '=Sheet1!$C$2:$C$10',
124
+ :name => 'High'
125
+ )
126
+
127
+ chart2.add_series(
128
+ :categories => '=Sheet1!$A$2:$A$10',
129
+ :values => '=Sheet1!$D$2:$D$10',
130
+ :name => 'Low'
131
+ )
132
+
133
+ chart2.add_series(
134
+ :categories => '=Sheet1!$A$2:$A$10',
135
+ :values => '=Sheet1!$E$2:$E$10',
136
+ :name => 'Close'
137
+ )
138
+
139
+ # Add a chart title and axes labels.
140
+ chart2.set_title(:name => 'Open-High-Low-Close')
141
+ chart2.set_x_axis(:name => 'Date')
142
+ chart2.set_y_axis(:name => 'Share price')
143
+
144
+ # Insert the chart into the main worksheet.
145
+ worksheet.insert_chart('G2', chart2)
146
+
147
+ # File save
148
+ workbook.close
data/examples/chess.rb CHANGED
@@ -1,142 +1,142 @@
1
- #!/usr/bin/ruby -w
2
- # -*- coding: utf-8 -*-
3
-
4
- ########################################################################
5
- #
6
- # Example of formatting using the Spreadsheet::WriteExcel module via
7
- # property hashes.
8
- #
9
- # Setting format properties via hashes of values is useful when you have
10
- # to deal with a large number of similar formats. Consider for example a
11
- # chess board pattern with black squares, white unformatted squares and
12
- # a border.
13
- #
14
- # This relatively simple example requires 14 separate Format
15
- # objects although there are only 5 different properties: black
16
- # background, top border, bottom border, left border and right border.
17
- #
18
- # Using property hashes it is possible to define these 5 sets of
19
- # properties and then add them together to create the 14 Format
20
- # configurations.
21
- #
22
- # reverse('©'), July 2001, John McNamara, jmcnamara@cpan.org
23
- #
24
- # original written in Perl by John McNamara
25
- # converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
26
- #
27
- require 'writeexcel'
28
-
29
- workbook = WriteExcel.new("chess.xls")
30
- worksheet = workbook.add_worksheet()
31
-
32
- # Some row and column formatting
33
- worksheet.set_column('B:I', 10)
34
-
35
- (1..8).each { |i| worksheet.set_row(i, 50) }
36
-
37
- # Define the property hashes
38
- #
39
- black = {
40
- 'fg_color' => 'black',
41
- 'pattern' => 1,
42
- }
43
-
44
- top = { 'top' => 6 }
45
- bottom = { 'bottom' => 6 }
46
- left = { 'left' => 6 }
47
- right = { 'right' => 6 }
48
-
49
- # Define the formats
50
- #
51
- format01 = workbook.add_format(top.merge(left))
52
- format02 = workbook.add_format(top.merge(black))
53
- format03 = workbook.add_format(top)
54
- format04 = workbook.add_format(top.merge(right).merge(black))
55
-
56
- format05 = workbook.add_format(left)
57
- format06 = workbook.add_format(black)
58
- format07 = workbook.add_format
59
- format08 = workbook.add_format(right.merge(black))
60
- format09 = workbook.add_format(right)
61
- format10 = workbook.add_format(left.merge(black))
62
-
63
- format11 = workbook.add_format(bottom.merge(left).merge(black))
64
- format12 = workbook.add_format(bottom)
65
- format13 = workbook.add_format(bottom.merge(black))
66
- format14 = workbook.add_format(bottom.merge(right))
67
-
68
-
69
- # Draw the pattern
70
- worksheet.write('B2', '', format01)
71
- worksheet.write('C2', '', format02)
72
- worksheet.write('D2', '', format03)
73
- worksheet.write('E2', '', format02)
74
- worksheet.write('F2', '', format03)
75
- worksheet.write('G2', '', format02)
76
- worksheet.write('H2', '', format03)
77
- worksheet.write('I2', '', format04)
78
-
79
- worksheet.write('B3', '', format10)
80
- worksheet.write('C3', '', format07)
81
- worksheet.write('D3', '', format06)
82
- worksheet.write('E3', '', format07)
83
- worksheet.write('F3', '', format06)
84
- worksheet.write('G3', '', format07)
85
- worksheet.write('H3', '', format06)
86
- worksheet.write('I3', '', format09)
87
-
88
- worksheet.write('B4', '', format05)
89
- worksheet.write('C4', '', format06)
90
- worksheet.write('D4', '', format07)
91
- worksheet.write('E4', '', format06)
92
- worksheet.write('F4', '', format07)
93
- worksheet.write('G4', '', format06)
94
- worksheet.write('H4', '', format07)
95
- worksheet.write('I4', '', format08)
96
-
97
- worksheet.write('B5', '', format10)
98
- worksheet.write('C5', '', format07)
99
- worksheet.write('D5', '', format06)
100
- worksheet.write('E5', '', format07)
101
- worksheet.write('F5', '', format06)
102
- worksheet.write('G5', '', format07)
103
- worksheet.write('H5', '', format06)
104
- worksheet.write('I5', '', format09)
105
-
106
- worksheet.write('B6', '', format05)
107
- worksheet.write('C6', '', format06)
108
- worksheet.write('D6', '', format07)
109
- worksheet.write('E6', '', format06)
110
- worksheet.write('F6', '', format07)
111
- worksheet.write('G6', '', format06)
112
- worksheet.write('H6', '', format07)
113
- worksheet.write('I6', '', format08)
114
-
115
- worksheet.write('B7', '', format10)
116
- worksheet.write('C7', '', format07)
117
- worksheet.write('D7', '', format06)
118
- worksheet.write('E7', '', format07)
119
- worksheet.write('F7', '', format06)
120
- worksheet.write('G7', '', format07)
121
- worksheet.write('H7', '', format06)
122
- worksheet.write('I7', '', format09)
123
-
124
- worksheet.write('B8', '', format05)
125
- worksheet.write('C8', '', format06)
126
- worksheet.write('D8', '', format07)
127
- worksheet.write('E8', '', format06)
128
- worksheet.write('F8', '', format07)
129
- worksheet.write('G8', '', format06)
130
- worksheet.write('H8', '', format07)
131
- worksheet.write('I8', '', format08)
132
-
133
- worksheet.write('B9', '', format11)
134
- worksheet.write('C9', '', format12)
135
- worksheet.write('D9', '', format13)
136
- worksheet.write('E9', '', format12)
137
- worksheet.write('F9', '', format13)
138
- worksheet.write('G9', '', format12)
139
- worksheet.write('H9', '', format13)
140
- worksheet.write('I9', '', format14)
141
-
142
- workbook.close
1
+ #!/usr/bin/ruby -w
2
+ # -*- coding: utf-8 -*-
3
+
4
+ ########################################################################
5
+ #
6
+ # Example of formatting using the Spreadsheet::WriteExcel module via
7
+ # property hashes.
8
+ #
9
+ # Setting format properties via hashes of values is useful when you have
10
+ # to deal with a large number of similar formats. Consider for example a
11
+ # chess board pattern with black squares, white unformatted squares and
12
+ # a border.
13
+ #
14
+ # This relatively simple example requires 14 separate Format
15
+ # objects although there are only 5 different properties: black
16
+ # background, top border, bottom border, left border and right border.
17
+ #
18
+ # Using property hashes it is possible to define these 5 sets of
19
+ # properties and then add them together to create the 14 Format
20
+ # configurations.
21
+ #
22
+ # reverse('©'), July 2001, John McNamara, jmcnamara@cpan.org
23
+ #
24
+ # original written in Perl by John McNamara
25
+ # converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
26
+ #
27
+ require 'writeexcel'
28
+
29
+ workbook = WriteExcel.new("chess.xls")
30
+ worksheet = workbook.add_worksheet()
31
+
32
+ # Some row and column formatting
33
+ worksheet.set_column('B:I', 10)
34
+
35
+ (1..8).each { |i| worksheet.set_row(i, 50) }
36
+
37
+ # Define the property hashes
38
+ #
39
+ black = {
40
+ 'fg_color' => 'black',
41
+ 'pattern' => 1,
42
+ }
43
+
44
+ top = { 'top' => 6 }
45
+ bottom = { 'bottom' => 6 }
46
+ left = { 'left' => 6 }
47
+ right = { 'right' => 6 }
48
+
49
+ # Define the formats
50
+ #
51
+ format01 = workbook.add_format(top.merge(left))
52
+ format02 = workbook.add_format(top.merge(black))
53
+ format03 = workbook.add_format(top)
54
+ format04 = workbook.add_format(top.merge(right).merge(black))
55
+
56
+ format05 = workbook.add_format(left)
57
+ format06 = workbook.add_format(black)
58
+ format07 = workbook.add_format
59
+ format08 = workbook.add_format(right.merge(black))
60
+ format09 = workbook.add_format(right)
61
+ format10 = workbook.add_format(left.merge(black))
62
+
63
+ format11 = workbook.add_format(bottom.merge(left).merge(black))
64
+ format12 = workbook.add_format(bottom)
65
+ format13 = workbook.add_format(bottom.merge(black))
66
+ format14 = workbook.add_format(bottom.merge(right))
67
+
68
+
69
+ # Draw the pattern
70
+ worksheet.write('B2', '', format01)
71
+ worksheet.write('C2', '', format02)
72
+ worksheet.write('D2', '', format03)
73
+ worksheet.write('E2', '', format02)
74
+ worksheet.write('F2', '', format03)
75
+ worksheet.write('G2', '', format02)
76
+ worksheet.write('H2', '', format03)
77
+ worksheet.write('I2', '', format04)
78
+
79
+ worksheet.write('B3', '', format10)
80
+ worksheet.write('C3', '', format07)
81
+ worksheet.write('D3', '', format06)
82
+ worksheet.write('E3', '', format07)
83
+ worksheet.write('F3', '', format06)
84
+ worksheet.write('G3', '', format07)
85
+ worksheet.write('H3', '', format06)
86
+ worksheet.write('I3', '', format09)
87
+
88
+ worksheet.write('B4', '', format05)
89
+ worksheet.write('C4', '', format06)
90
+ worksheet.write('D4', '', format07)
91
+ worksheet.write('E4', '', format06)
92
+ worksheet.write('F4', '', format07)
93
+ worksheet.write('G4', '', format06)
94
+ worksheet.write('H4', '', format07)
95
+ worksheet.write('I4', '', format08)
96
+
97
+ worksheet.write('B5', '', format10)
98
+ worksheet.write('C5', '', format07)
99
+ worksheet.write('D5', '', format06)
100
+ worksheet.write('E5', '', format07)
101
+ worksheet.write('F5', '', format06)
102
+ worksheet.write('G5', '', format07)
103
+ worksheet.write('H5', '', format06)
104
+ worksheet.write('I5', '', format09)
105
+
106
+ worksheet.write('B6', '', format05)
107
+ worksheet.write('C6', '', format06)
108
+ worksheet.write('D6', '', format07)
109
+ worksheet.write('E6', '', format06)
110
+ worksheet.write('F6', '', format07)
111
+ worksheet.write('G6', '', format06)
112
+ worksheet.write('H6', '', format07)
113
+ worksheet.write('I6', '', format08)
114
+
115
+ worksheet.write('B7', '', format10)
116
+ worksheet.write('C7', '', format07)
117
+ worksheet.write('D7', '', format06)
118
+ worksheet.write('E7', '', format07)
119
+ worksheet.write('F7', '', format06)
120
+ worksheet.write('G7', '', format07)
121
+ worksheet.write('H7', '', format06)
122
+ worksheet.write('I7', '', format09)
123
+
124
+ worksheet.write('B8', '', format05)
125
+ worksheet.write('C8', '', format06)
126
+ worksheet.write('D8', '', format07)
127
+ worksheet.write('E8', '', format06)
128
+ worksheet.write('F8', '', format07)
129
+ worksheet.write('G8', '', format06)
130
+ worksheet.write('H8', '', format07)
131
+ worksheet.write('I8', '', format08)
132
+
133
+ worksheet.write('B9', '', format11)
134
+ worksheet.write('C9', '', format12)
135
+ worksheet.write('D9', '', format13)
136
+ worksheet.write('E9', '', format12)
137
+ worksheet.write('F9', '', format13)
138
+ worksheet.write('G9', '', format12)
139
+ worksheet.write('H9', '', format13)
140
+ worksheet.write('I9', '', format14)
141
+
142
+ workbook.close