ricardoo27-writeexcel 0.6.12.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (245) hide show
  1. data/.document +5 -0
  2. data/.gitattributes +1 -0
  3. data/README.rdoc +136 -0
  4. data/Rakefile +52 -0
  5. data/VERSION +1 -0
  6. data/charts/chartex.rb +316 -0
  7. data/charts/demo1.rb +46 -0
  8. data/charts/demo101.bin +0 -0
  9. data/charts/demo2.rb +65 -0
  10. data/charts/demo201.bin +0 -0
  11. data/charts/demo3.rb +117 -0
  12. data/charts/demo301.bin +0 -0
  13. data/charts/demo4.rb +119 -0
  14. data/charts/demo401.bin +0 -0
  15. data/charts/demo5.rb +48 -0
  16. data/charts/demo501.bin +0 -0
  17. data/examples/a_simple.rb +43 -0
  18. data/examples/autofilter.rb +265 -0
  19. data/examples/bigfile.rb +30 -0
  20. data/examples/chart_area.rb +121 -0
  21. data/examples/chart_bar.rb +120 -0
  22. data/examples/chart_column.rb +120 -0
  23. data/examples/chart_line.rb +120 -0
  24. data/examples/chart_pie.rb +108 -0
  25. data/examples/chart_scatter.rb +121 -0
  26. data/examples/chart_stock.rb +148 -0
  27. data/examples/chess.rb +142 -0
  28. data/examples/colors.rb +129 -0
  29. data/examples/comments1.rb +27 -0
  30. data/examples/comments2.rb +352 -0
  31. data/examples/copyformat.rb +52 -0
  32. data/examples/data_validate.rb +279 -0
  33. data/examples/date_time.rb +87 -0
  34. data/examples/defined_name.rb +32 -0
  35. data/examples/demo.rb +124 -0
  36. data/examples/diag_border.rb +36 -0
  37. data/examples/formats.rb +490 -0
  38. data/examples/formula_result.rb +30 -0
  39. data/examples/header.rb +137 -0
  40. data/examples/hide_sheet.rb +29 -0
  41. data/examples/hyperlink.rb +43 -0
  42. data/examples/images.rb +63 -0
  43. data/examples/indent.rb +31 -0
  44. data/examples/merge1.rb +40 -0
  45. data/examples/merge2.rb +45 -0
  46. data/examples/merge3.rb +66 -0
  47. data/examples/merge4.rb +83 -0
  48. data/examples/merge5.rb +80 -0
  49. data/examples/merge6.rb +67 -0
  50. data/examples/outline.rb +255 -0
  51. data/examples/outline_collapsed.rb +209 -0
  52. data/examples/panes.rb +113 -0
  53. data/examples/password_protection.rb +33 -0
  54. data/examples/properties.rb +34 -0
  55. data/examples/properties_jp.rb +33 -0
  56. data/examples/protection.rb +47 -0
  57. data/examples/regions.rb +53 -0
  58. data/examples/repeat.rb +43 -0
  59. data/examples/republic.png +0 -0
  60. data/examples/right_to_left.rb +27 -0
  61. data/examples/row_wrap.rb +53 -0
  62. data/examples/set_first_sheet.rb +14 -0
  63. data/examples/stats.rb +74 -0
  64. data/examples/stocks.rb +81 -0
  65. data/examples/store_formula.rb +15 -0
  66. data/examples/tab_colors.rb +31 -0
  67. data/examples/utf8.rb +15 -0
  68. data/examples/write_arrays.rb +83 -0
  69. data/html/en/doc_en.html +5946 -0
  70. data/html/images/a_simple.jpg +0 -0
  71. data/html/images/area1.jpg +0 -0
  72. data/html/images/bar1.jpg +0 -0
  73. data/html/images/chart_area.xls +0 -0
  74. data/html/images/column1.jpg +0 -0
  75. data/html/images/data_validation.jpg +0 -0
  76. data/html/images/line1.jpg +0 -0
  77. data/html/images/pie1.jpg +0 -0
  78. data/html/images/regions.jpg +0 -0
  79. data/html/images/scatter1.jpg +0 -0
  80. data/html/images/stats.jpg +0 -0
  81. data/html/images/stock1.jpg +0 -0
  82. data/html/images/stocks.jpg +0 -0
  83. data/html/index.html +16 -0
  84. data/html/style.css +433 -0
  85. data/lib/writeexcel.rb +1159 -0
  86. data/lib/writeexcel/biffwriter.rb +223 -0
  87. data/lib/writeexcel/caller_info.rb +12 -0
  88. data/lib/writeexcel/cell_range.rb +332 -0
  89. data/lib/writeexcel/chart.rb +1968 -0
  90. data/lib/writeexcel/charts/area.rb +154 -0
  91. data/lib/writeexcel/charts/bar.rb +177 -0
  92. data/lib/writeexcel/charts/column.rb +156 -0
  93. data/lib/writeexcel/charts/external.rb +66 -0
  94. data/lib/writeexcel/charts/line.rb +154 -0
  95. data/lib/writeexcel/charts/pie.rb +169 -0
  96. data/lib/writeexcel/charts/scatter.rb +192 -0
  97. data/lib/writeexcel/charts/stock.rb +213 -0
  98. data/lib/writeexcel/col_info.rb +87 -0
  99. data/lib/writeexcel/colors.rb +68 -0
  100. data/lib/writeexcel/comments.rb +460 -0
  101. data/lib/writeexcel/compatibility.rb +65 -0
  102. data/lib/writeexcel/convert_date_time.rb +117 -0
  103. data/lib/writeexcel/data_validations.rb +370 -0
  104. data/lib/writeexcel/debug_info.rb +41 -0
  105. data/lib/writeexcel/embedded_chart.rb +35 -0
  106. data/lib/writeexcel/excelformula.y +139 -0
  107. data/lib/writeexcel/excelformulaparser.rb +587 -0
  108. data/lib/writeexcel/format.rb +1575 -0
  109. data/lib/writeexcel/formula.rb +987 -0
  110. data/lib/writeexcel/helper.rb +78 -0
  111. data/lib/writeexcel/image.rb +218 -0
  112. data/lib/writeexcel/olewriter.rb +305 -0
  113. data/lib/writeexcel/outline.rb +24 -0
  114. data/lib/writeexcel/properties.rb +242 -0
  115. data/lib/writeexcel/shared_string_table.rb +153 -0
  116. data/lib/writeexcel/storage_lite.rb +984 -0
  117. data/lib/writeexcel/workbook.rb +2478 -0
  118. data/lib/writeexcel/worksheet.rb +6925 -0
  119. data/lib/writeexcel/worksheets.rb +25 -0
  120. data/lib/writeexcel/write_file.rb +63 -0
  121. data/test/excelfile/Chart1.xls +0 -0
  122. data/test/excelfile/Chart2.xls +0 -0
  123. data/test/excelfile/Chart3.xls +0 -0
  124. data/test/excelfile/Chart4.xls +0 -0
  125. data/test/excelfile/Chart5.xls +0 -0
  126. data/test/helper.rb +31 -0
  127. data/test/perl_output/Chart1.xls.data +0 -0
  128. data/test/perl_output/Chart2.xls.data +0 -0
  129. data/test/perl_output/Chart3.xls.data +0 -0
  130. data/test/perl_output/Chart4.xls.data +0 -0
  131. data/test/perl_output/Chart5.xls.data +0 -0
  132. data/test/perl_output/README +31 -0
  133. data/test/perl_output/a_simple.xls +0 -0
  134. data/test/perl_output/autofilter.xls +0 -0
  135. data/test/perl_output/biff_add_continue_testdata +0 -0
  136. data/test/perl_output/chart_area.xls +0 -0
  137. data/test/perl_output/chart_bar.xls +0 -0
  138. data/test/perl_output/chart_column.xls +0 -0
  139. data/test/perl_output/chart_line.xls +0 -0
  140. data/test/perl_output/chess.xls +0 -0
  141. data/test/perl_output/colors.xls +0 -0
  142. data/test/perl_output/comments0.xls +0 -0
  143. data/test/perl_output/comments1.xls +0 -0
  144. data/test/perl_output/comments2.xls +0 -0
  145. data/test/perl_output/data_validate.xls +0 -0
  146. data/test/perl_output/date_time.xls +0 -0
  147. data/test/perl_output/defined_name.xls +0 -0
  148. data/test/perl_output/demo.xls +0 -0
  149. data/test/perl_output/demo101.bin +0 -0
  150. data/test/perl_output/demo201.bin +0 -0
  151. data/test/perl_output/demo301.bin +0 -0
  152. data/test/perl_output/demo401.bin +0 -0
  153. data/test/perl_output/demo501.bin +0 -0
  154. data/test/perl_output/diag_border.xls +0 -0
  155. data/test/perl_output/f_font_biff +0 -0
  156. data/test/perl_output/f_font_key +1 -0
  157. data/test/perl_output/f_xf_biff +0 -0
  158. data/test/perl_output/file_font_biff +0 -0
  159. data/test/perl_output/file_font_key +1 -0
  160. data/test/perl_output/file_xf_biff +0 -0
  161. data/test/perl_output/formula_result.xls +0 -0
  162. data/test/perl_output/headers.xls +0 -0
  163. data/test/perl_output/hidden.xls +0 -0
  164. data/test/perl_output/hide_zero.xls +0 -0
  165. data/test/perl_output/hyperlink.xls +0 -0
  166. data/test/perl_output/images.xls +0 -0
  167. data/test/perl_output/indent.xls +0 -0
  168. data/test/perl_output/merge1.xls +0 -0
  169. data/test/perl_output/merge2.xls +0 -0
  170. data/test/perl_output/merge3.xls +0 -0
  171. data/test/perl_output/merge4.xls +0 -0
  172. data/test/perl_output/merge5.xls +0 -0
  173. data/test/perl_output/merge6.xls +0 -0
  174. data/test/perl_output/ole_write_header +0 -0
  175. data/test/perl_output/outline.xls +0 -0
  176. data/test/perl_output/outline_collapsed.xls +0 -0
  177. data/test/perl_output/panes.xls +0 -0
  178. data/test/perl_output/password_protection.xls +0 -0
  179. data/test/perl_output/protection.xls +0 -0
  180. data/test/perl_output/regions.xls +0 -0
  181. data/test/perl_output/right_to_left.xls +0 -0
  182. data/test/perl_output/set_first_sheet.xls +0 -0
  183. data/test/perl_output/stats.xls +0 -0
  184. data/test/perl_output/stocks.xls +0 -0
  185. data/test/perl_output/store_formula.xls +0 -0
  186. data/test/perl_output/tab_colors.xls +0 -0
  187. data/test/perl_output/unicode_cyrillic.xls +0 -0
  188. data/test/perl_output/utf8.xls +0 -0
  189. data/test/perl_output/workbook1.xls +0 -0
  190. data/test/perl_output/workbook2.xls +0 -0
  191. data/test/perl_output/ws_colinfo +1 -0
  192. data/test/perl_output/ws_store_colinfo +0 -0
  193. data/test/perl_output/ws_store_dimensions +0 -0
  194. data/test/perl_output/ws_store_filtermode +0 -0
  195. data/test/perl_output/ws_store_filtermode_off +0 -0
  196. data/test/perl_output/ws_store_filtermode_on +0 -0
  197. data/test/perl_output/ws_store_selection +0 -0
  198. data/test/perl_output/ws_store_window2 +1 -0
  199. data/test/republic.png +0 -0
  200. data/test/test_00_IEEE_double.rb +13 -0
  201. data/test/test_01_add_worksheet.rb +10 -0
  202. data/test/test_02_merge_formats.rb +49 -0
  203. data/test/test_04_dimensions.rb +388 -0
  204. data/test/test_05_rows.rb +175 -0
  205. data/test/test_06_extsst.rb +74 -0
  206. data/test/test_11_date_time.rb +475 -0
  207. data/test/test_12_date_only.rb +525 -0
  208. data/test/test_13_date_seconds.rb +477 -0
  209. data/test/test_21_escher.rb +624 -0
  210. data/test/test_22_mso_drawing_group.rb +741 -0
  211. data/test/test_23_note.rb +57 -0
  212. data/test/test_24_txo.rb +74 -0
  213. data/test/test_25_position_object.rb +80 -0
  214. data/test/test_26_autofilter.rb +309 -0
  215. data/test/test_27_autofilter.rb +126 -0
  216. data/test/test_28_autofilter.rb +156 -0
  217. data/test/test_29_process_jpg.rb +670 -0
  218. data/test/test_30_validation_dval.rb +74 -0
  219. data/test/test_31_validation_dv_strings.rb +123 -0
  220. data/test/test_32_validation_dv_formula.rb +203 -0
  221. data/test/test_40_property_types.rb +188 -0
  222. data/test/test_41_properties.rb +235 -0
  223. data/test/test_42_set_properties.rb +434 -0
  224. data/test/test_50_name_stored.rb +295 -0
  225. data/test/test_51_name_print_area.rb +353 -0
  226. data/test/test_52_name_print_titles.rb +450 -0
  227. data/test/test_53_autofilter.rb +199 -0
  228. data/test/test_60_chart_generic.rb +574 -0
  229. data/test/test_61_chart_subclasses.rb +84 -0
  230. data/test/test_62_chart_formats.rb +268 -0
  231. data/test/test_63_chart_area_formats.rb +645 -0
  232. data/test/test_biff.rb +71 -0
  233. data/test/test_big_workbook.rb +17 -0
  234. data/test/test_compatibility.rb +12 -0
  235. data/test/test_example_match.rb +3246 -0
  236. data/test/test_format.rb +1189 -0
  237. data/test/test_formula.rb +61 -0
  238. data/test/test_ole.rb +102 -0
  239. data/test/test_storage_lite.rb +116 -0
  240. data/test/test_workbook.rb +146 -0
  241. data/test/test_worksheet.rb +106 -0
  242. data/utils/add_magic_comment.rb +80 -0
  243. data/writeexcel.gemspec +278 -0
  244. data/writeexcel.rdoc +1425 -0
  245. metadata +292 -0
@@ -0,0 +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
@@ -0,0 +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
@@ -0,0 +1,129 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- coding: utf-8 -*-
3
+
4
+ ################################################################################
5
+ #
6
+ # Demonstrates Spreadsheet::WriteExcel's named colors and the Excel color
7
+ # palette.
8
+ #
9
+ # The set_custom_color() Worksheet method can be used to override one of the
10
+ # built-in palette values with a more suitable colour. See the main docs.
11
+ #
12
+ # reverse('©'), March 2002, John McNamara, jmcnamara@cpan.org
13
+ #
14
+ # original written in Perl by John McNamara
15
+ # converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
16
+ #
17
+
18
+ require 'writeexcel'
19
+
20
+ workbook = WriteExcel.new("colors.xls")
21
+
22
+ # Some common formats
23
+ center = workbook.add_format(:align => 'center')
24
+ heading = workbook.add_format(:align => 'center', :bold => 1)
25
+
26
+ ######################################################################
27
+ #
28
+ # Demonstrate the named colors.
29
+ #
30
+
31
+ order = [
32
+ 0x21,
33
+ 0x0B,
34
+ 0x35,
35
+ 0x11,
36
+ 0x16,
37
+ 0x12,
38
+ 0x0D,
39
+ 0x10,
40
+ 0x17,
41
+ 0x09,
42
+ 0x0C,
43
+ 0x0F,
44
+ 0x0E,
45
+ 0x14,
46
+ 0x08,
47
+ 0x0A
48
+ ]
49
+
50
+ colors = {
51
+ 0x08 => 'black',
52
+ 0x0C => 'blue',
53
+ 0x10 => 'brown',
54
+ 0x0F => 'cyan',
55
+ 0x17 => 'gray',
56
+ 0x11 => 'green',
57
+ 0x0B => 'lime',
58
+ 0x0E => 'magenta',
59
+ 0x12 => 'navy',
60
+ 0x35 => 'orange',
61
+ 0x21 => 'pink',
62
+ 0x14 => 'purple',
63
+ 0x0A => 'red',
64
+ 0x16 => 'silver',
65
+ 0x09 => 'white',
66
+ 0x0D => 'yellow',
67
+ }
68
+
69
+ worksheet1 = workbook.add_worksheet('Named colors')
70
+
71
+ worksheet1.set_column(0, 3, 15)
72
+
73
+ worksheet1.write(0, 0, "Index", heading)
74
+ worksheet1.write(0, 1, "Index", heading)
75
+ worksheet1.write(0, 2, "Name", heading)
76
+ worksheet1.write(0, 3, "Color", heading)
77
+
78
+ i = 1
79
+
80
+ # original was colors.each....
81
+ # order unmatch between perl and ruby (of cource, it's hash!)
82
+ # so i use order array to match perl's xls order.
83
+ #
84
+ order.each do |index|
85
+ format = workbook.add_format(
86
+ :fg_color => colors[index],
87
+ :pattern => 1,
88
+ :border => 1
89
+ )
90
+
91
+ worksheet1.write(i + 1, 0, index, center)
92
+ worksheet1.write(i + 1, 1, sprintf("0x%02X", index), center)
93
+ worksheet1.write(i + 1, 2, colors[index], center)
94
+ worksheet1.write(i + 1, 3, '', format)
95
+ i += 1
96
+ end
97
+
98
+ ######################################################################
99
+ #
100
+ # Demonstrate the standard Excel colors in the range 8..63.
101
+ #
102
+
103
+ worksheet2 = workbook.add_worksheet('Standard colors')
104
+
105
+ worksheet2.set_column(0, 3, 15)
106
+
107
+ worksheet2.write(0, 0, "Index", heading)
108
+ worksheet2.write(0, 1, "Index", heading)
109
+ worksheet2.write(0, 2, "Color", heading)
110
+ worksheet2.write(0, 3, "Name", heading)
111
+
112
+ (8..63).each do |i|
113
+ format = workbook.add_format(
114
+ :fg_color => i,
115
+ :pattern => 1,
116
+ :border => 1
117
+ )
118
+
119
+ worksheet2.write((i - 7), 0, i, center)
120
+ worksheet2.write((i - 7), 1, sprintf("0x%02X", i), center)
121
+ worksheet2.write((i - 7), 2, '', format)
122
+
123
+ # Add the color names
124
+ if colors.has_key?(i)
125
+ worksheet2.write((i - 7), 3, colors[i], center)
126
+ end
127
+ end
128
+
129
+ workbook.close
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- coding: utf-8 -*-
3
+
4
+ ###############################################################################
5
+ #
6
+ # This example demonstrates writing cell comments.
7
+ #
8
+ # A cell comment is indicated in Excel by a small red triangle in the upper
9
+ # right-hand corner of the cell.
10
+ #
11
+ # For more advanced comment options see comments2.pl.
12
+ #
13
+ # reverse('©'), November 2005, John McNamara, jmcnamara@cpan.org
14
+ #
15
+ # original written in Perl by John McNamara
16
+ # converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
17
+ #
18
+
19
+ require 'writeexcel'
20
+
21
+ workbook = WriteExcel.new("comments1.xls")
22
+ worksheet = workbook.add_worksheet
23
+
24
+ worksheet.write('A1', 'Hello')
25
+ worksheet.write_comment('A1', 'This is a comment')
26
+
27
+ workbook.close
@@ -0,0 +1,352 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- coding: utf-8 -*-
3
+
4
+ ###############################################################################
5
+ #
6
+ # This example demonstrates writing cell comments.
7
+ #
8
+ # A cell comment is indicated in Excel by a small red triangle in the upper
9
+ # right-hand corner of the cell.
10
+ #
11
+ # Each of the worksheets demonstrates different features of cell comments.
12
+ #
13
+ # reverse('©'), November 2005, John McNamara, jmcnamara@cpan.org
14
+ #
15
+ # original written in Perl by John McNamara
16
+ # converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
17
+ #
18
+
19
+ require 'writeexcel'
20
+
21
+ workbook = WriteExcel.new("comments2.xls")
22
+ text_wrap = workbook.add_format(:text_wrap => 1, :valign => 'top')
23
+ worksheet1 = workbook.add_worksheet
24
+ worksheet2 = workbook.add_worksheet
25
+ worksheet3 = workbook.add_worksheet
26
+ worksheet4 = workbook.add_worksheet
27
+ worksheet5 = workbook.add_worksheet
28
+ worksheet6 = workbook.add_worksheet
29
+ worksheet7 = workbook.add_worksheet
30
+ worksheet8 = workbook.add_worksheet
31
+
32
+ # Variables that we will use in each example.
33
+ cell_text = ''
34
+ comment = ''
35
+
36
+ ###############################################################################
37
+ #
38
+ # Example 1. Demonstrates a simple cell comment without formatting and Unicode
39
+ # comments encoded as UTF-16 and as UTF-8.
40
+ #
41
+
42
+ # Set up some formatting.
43
+ worksheet1.set_column('C:C', 25)
44
+ worksheet1.set_row(2, 50)
45
+ worksheet1.set_row(5, 50)
46
+
47
+ # Simple ascii string.
48
+ cell_text = 'Hold the mouse over this cell to see the comment.'
49
+
50
+ comment = 'This is a comment.'
51
+
52
+ worksheet1.write('C3', cell_text, text_wrap)
53
+ worksheet1.write_comment('C3', comment)
54
+
55
+ # UTF-16 string.
56
+ cell_text = 'This is a UTF-16 comment.'
57
+
58
+ comment = [0x263a].pack("n")
59
+
60
+ worksheet1.write('C6', cell_text, text_wrap)
61
+ worksheet1.write_comment('C6', comment, :encoding => 1)
62
+
63
+ # UTF-8 string.
64
+ worksheet1.set_row(8, 50)
65
+ cell_text = 'This is a UTF-8 string.'
66
+ comment = '☺' # chr 0x263a in perl.
67
+
68
+ worksheet1.write('C9', cell_text, text_wrap)
69
+ worksheet1.write_comment('C9', comment)
70
+
71
+ ###############################################################################
72
+ #
73
+ # Example 2. Demonstrates visible and hidden comments.
74
+ #
75
+
76
+ # Set up some formatting.
77
+ worksheet2.set_column('C:C', 25)
78
+ worksheet2.set_row(2, 50)
79
+ worksheet2.set_row(5, 50)
80
+
81
+
82
+ cell_text = 'This cell comment is visible.'
83
+
84
+ comment = 'Hello.'
85
+
86
+ worksheet2.write('C3', cell_text, text_wrap)
87
+ worksheet2.write_comment('C3', comment, :visible => 1)
88
+
89
+
90
+ cell_text = "This cell comment isn't visible (the default)."
91
+
92
+ comment = 'Hello.'
93
+
94
+ worksheet2.write('C6', cell_text, text_wrap)
95
+ worksheet2.write_comment('C6', comment)
96
+
97
+ ###############################################################################
98
+ #
99
+ # Example 3. Demonstrates visible and hidden comments set at the worksheet
100
+ # level.
101
+ #
102
+
103
+ # Set up some formatting.
104
+ worksheet3.set_column('C:C', 25)
105
+ worksheet3.set_row(2, 50)
106
+ worksheet3.set_row(5, 50)
107
+ worksheet3.set_row(8, 50)
108
+
109
+ # Make all comments on the worksheet visible.
110
+ worksheet3.show_comments
111
+
112
+ cell_text = 'This cell comment is visible, explicitly.'
113
+
114
+ comment = 'Hello.'
115
+
116
+ worksheet3.write('C3', cell_text, text_wrap)
117
+ worksheet3.write_comment('C3', comment, :visible => 1)
118
+
119
+
120
+ cell_text = 'This cell comment is also visible because ' +
121
+ 'we used show_comments().'
122
+
123
+ comment = 'Hello.'
124
+
125
+ worksheet3.write('C6', cell_text, text_wrap)
126
+ worksheet3.write_comment('C6', comment)
127
+
128
+
129
+ cell_text = 'However, we can still override it locally.'
130
+
131
+ comment = 'Hello.'
132
+
133
+ worksheet3.write('C9', cell_text, text_wrap)
134
+ worksheet3.write_comment('C9', comment, :visible => 0)
135
+
136
+ ###############################################################################
137
+ #
138
+ # Example 4. Demonstrates changes to the comment box dimensions.
139
+ #
140
+
141
+ # Set up some formatting.
142
+ worksheet4.set_column('C:C', 25)
143
+ worksheet4.set_row(2, 50)
144
+ worksheet4.set_row(5, 50)
145
+ worksheet4.set_row(8, 50)
146
+ worksheet4.set_row(15, 50)
147
+
148
+ worksheet4.show_comments
149
+
150
+ cell_text = 'This cell comment is default size.'
151
+
152
+ comment = 'Hello.'
153
+
154
+ worksheet4.write('C3', cell_text, text_wrap)
155
+ worksheet4.write_comment('C3', comment)
156
+
157
+
158
+ cell_text = 'This cell comment is twice as wide.'
159
+
160
+ comment = 'Hello.'
161
+
162
+ worksheet4.write('C6', cell_text, text_wrap)
163
+ worksheet4.write_comment('C6', comment, :x_scale => 2)
164
+
165
+
166
+ cell_text = 'This cell comment is twice as high.'
167
+
168
+ comment = 'Hello.'
169
+
170
+ worksheet4.write('C9', cell_text, text_wrap)
171
+ worksheet4.write_comment('C9', comment, :y_scale => 2)
172
+
173
+
174
+ cell_text = 'This cell comment is scaled in both directions.'
175
+
176
+ comment = 'Hello.'
177
+
178
+ worksheet4.write('C16', cell_text, text_wrap)
179
+ worksheet4.write_comment('C16', comment, :x_scale => 1.2, :y_scale => 0.8)
180
+
181
+
182
+ cell_text = 'This cell comment has width and height specified in pixels.'
183
+
184
+ comment = 'Hello.'
185
+
186
+ worksheet4.write('C19', cell_text, text_wrap)
187
+ worksheet4.write_comment('C19', comment, :width => 200, :height => 20)
188
+
189
+ ###############################################################################
190
+ #
191
+ # Example 5. Demonstrates changes to the cell comment position.
192
+ #
193
+
194
+ worksheet5.set_column('C:C', 25)
195
+ worksheet5.set_row(2, 50)
196
+ worksheet5.set_row(5, 50)
197
+ worksheet5.set_row(8, 50)
198
+ worksheet5.set_row(11, 50)
199
+
200
+ worksheet5.show_comments
201
+
202
+ cell_text = 'This cell comment is in the default position.'
203
+
204
+ comment = 'Hello.'
205
+
206
+ worksheet5.write('C3', cell_text, text_wrap)
207
+ worksheet5.write_comment('C3', comment)
208
+
209
+
210
+ cell_text = 'This cell comment has been moved to another cell.'
211
+
212
+ comment = 'Hello.'
213
+
214
+ worksheet5.write('C6', cell_text, text_wrap)
215
+ worksheet5.write_comment('C6', comment, :start_cell => 'E4')
216
+
217
+
218
+ cell_text = 'This cell comment has been moved to another cell.'
219
+
220
+ comment = 'Hello.'
221
+
222
+ worksheet5.write('C9', cell_text, text_wrap)
223
+ worksheet5.write_comment('C9', comment, :start_row => 8, :start_col => 4)
224
+
225
+
226
+ cell_text = 'This cell comment has been shifted within its default cell.'
227
+
228
+ comment = 'Hello.'
229
+
230
+ worksheet5.write('C12', cell_text, text_wrap)
231
+ worksheet5.write_comment('C12', comment, :x_offset => 30, :y_offset => 12)
232
+
233
+ ###############################################################################
234
+ #
235
+ # Example 6. Demonstrates changes to the comment background colour.
236
+ #
237
+
238
+ worksheet6.set_column('C:C', 25)
239
+ worksheet6.set_row(2, 50)
240
+ worksheet6.set_row(5, 50)
241
+ worksheet6.set_row(8, 50)
242
+
243
+ worksheet6.show_comments
244
+
245
+ cell_text = 'This cell comment has a different colour.'
246
+
247
+ comment = 'Hello.'
248
+
249
+ worksheet6.write('C3', cell_text, text_wrap)
250
+ worksheet6.write_comment('C3', comment, :color => 'green')
251
+
252
+
253
+ cell_text = 'This cell comment has the default colour.'
254
+
255
+ comment = 'Hello.'
256
+
257
+ worksheet6.write('C6', cell_text, text_wrap)
258
+ worksheet6.write_comment('C6', comment)
259
+
260
+ cell_text = 'This cell comment has a different colour.'
261
+
262
+ comment = 'Hello.'
263
+
264
+ worksheet6.write('C9', cell_text, text_wrap)
265
+ worksheet6.write_comment('C9', comment, :color => 0x35)
266
+
267
+ ###############################################################################
268
+ #
269
+ # Example 7. Demonstrates how to set the cell comment author.
270
+ #
271
+
272
+ worksheet7.set_column('C:C', 30)
273
+ worksheet7.set_row(2, 50)
274
+ worksheet7.set_row(5, 50)
275
+ worksheet7.set_row(8, 50)
276
+ worksheet7.set_row(11, 50)
277
+
278
+ author = ''
279
+ cell = 'C3'
280
+
281
+ cell_text = "Move the mouse over this cell and you will see 'Cell commented "+
282
+ "by #{author}' (blank) in the status bar at the bottom"
283
+
284
+ comment = 'Hello.'
285
+
286
+ worksheet7.write(cell, cell_text, text_wrap)
287
+ worksheet7.write_comment(cell, comment)
288
+
289
+ author = 'Perl'
290
+ cell = 'C6'
291
+ cell_text = "Move the mouse over this cell and you will see 'Cell commented " +
292
+ "by #{author}' in the status bar at the bottom"
293
+
294
+ comment = 'Hello.'
295
+
296
+ worksheet7.write(cell, cell_text, text_wrap)
297
+ worksheet7.write_comment(cell, comment, :author => author)
298
+
299
+ author = [0x20AC].pack("n") # UTF-16 Euro
300
+ cell = 'C9'
301
+ cell_text = "Move the mouse over this cell and you will see 'Cell commented " +
302
+ "by Euro' in the status bar at the bottom"
303
+
304
+ comment = 'Hello.'
305
+
306
+ worksheet7.write(cell, cell_text, text_wrap)
307
+ worksheet7.write_comment(cell, comment, :author => author,
308
+ :author_encoding => 1)
309
+
310
+ # UTF-8 string.
311
+ author = '☺' # smiley
312
+ cell = 'C12'
313
+ cell_text = "Move the mouse over this cell and you will see 'Cell commented " +
314
+ "by #{author}' in the status bar at the bottom"
315
+ comment = 'Hello.'
316
+
317
+ worksheet7.write(cell, cell_text, text_wrap)
318
+ worksheet7.write_comment(cell, comment, :author => author)
319
+
320
+ ###############################################################################
321
+ #
322
+ # Example 8. Demonstrates the need to explicitly set the row height.
323
+ #
324
+
325
+ # Set up some formatting.
326
+ worksheet8.set_column('C:C', 25)
327
+ worksheet8.set_row(2, 80)
328
+
329
+ worksheet8.show_comments
330
+
331
+ cell_text = 'The height of this row has been adjusted explicitly using ' +
332
+ 'set_row(). The size of the comment box is adjusted ' +
333
+ 'accordingly by WriteExcel.'
334
+
335
+ comment = 'Hello.'
336
+
337
+ worksheet8.write('C3', cell_text, text_wrap)
338
+ worksheet8.write_comment('C3', comment)
339
+
340
+ cell_text = 'The height of this row has been adjusted by Excel due to the ' +
341
+ 'text wrap property being set. Unfortunately this means that ' +
342
+ 'the height of the row is unknown to WriteExcel at run time ' +
343
+ "and thus the comment box is stretched as well.\n\n" +
344
+ 'Use set_row() to specify the row height explicitly to avoid ' +
345
+ 'this problem.'
346
+
347
+ comment = 'Hello.'
348
+
349
+ worksheet8.write('C6', cell_text, text_wrap)
350
+ worksheet8.write_comment('C6', comment)
351
+
352
+ workbook.close