ricardoo27-writeexcel 0.6.12.1

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.
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,53 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- coding: utf-8 -*-
3
+
4
+ ###############################################################################
5
+ #
6
+ # Example of how to use the WriteExcel module to write a basic multiple
7
+ # worksheet Excel file.
8
+ #
9
+ # reverse('©'), March 2001, 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
+ workbook = WriteExcel.new("regions.xls")
19
+
20
+ # Add some worksheets
21
+ north = workbook.add_worksheet("North")
22
+ south = workbook.add_worksheet("South")
23
+ east = workbook.add_worksheet("East")
24
+ west = workbook.add_worksheet("West")
25
+
26
+ # Add a Format
27
+ format = workbook.add_format()
28
+ format.set_bold()
29
+ format.set_color('blue')
30
+
31
+ # Add a caption to each worksheet
32
+ workbook.sheets.each do |worksheet|
33
+ worksheet.write(0, 0, "Sales", format)
34
+ end
35
+
36
+ # Write some data
37
+ north.write(0, 1, 200000)
38
+ south.write(0, 1, 100000)
39
+ east.write(0, 1, 150000)
40
+ west.write(0, 1, 100000)
41
+
42
+ # Set the active worksheet
43
+ bp=1
44
+ south.activate()
45
+
46
+ # Set the width of the first column
47
+ south.set_column(0, 0, 20)
48
+
49
+ # Set the active cell
50
+ south.set_selection(0, 1)
51
+
52
+ workbook.close
53
+
@@ -0,0 +1,43 @@
1
+ # -*- coding: utf-8 -*-
2
+ #!/usr/bin/ruby -w
3
+
4
+ ######################################################################
5
+ #
6
+ # Example of writing repeated formulas.
7
+ #
8
+ # reverse('©'), August 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
+ workbook = WriteExcel.new("repeat.xls")
18
+ worksheet = workbook.add_worksheet
19
+
20
+ limit = 1000
21
+
22
+ # Write a column of numbers
23
+ 0.upto(limit) do |row|
24
+ worksheet.write(row, 0, row)
25
+ end
26
+
27
+ # Store a formula
28
+ formula = worksheet.store_formula('=A1*5+4')
29
+
30
+ # Write a column of formulas based on the stored formula
31
+ 0.upto(limit) do |row|
32
+ worksheet.repeat_formula(row, 1, formula, nil,
33
+ /A1/, 'A'+(row+1).to_s)
34
+ end
35
+
36
+ # Direct formula writing. As a speed comparison uncomment the
37
+ # following and run the program again
38
+
39
+ #for row (0..limit) {
40
+ # worksheet.write_formula(row, 2, '=A'.(row+1).'*5+4')
41
+ #}
42
+
43
+ workbook.close
Binary file
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- coding: utf-8 -*-
3
+
4
+ #######################################################################
5
+ #
6
+ # Example of how to change the default worksheet direction from
7
+ # left-to-right to right-to-left as required by some eastern verions
8
+ # of Excel.
9
+ #
10
+ # reverse('©'), January 2006, John McNamara, jmcnamara@cpan.org
11
+ #
12
+ # original written in Perl by John McNamara
13
+ # converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
14
+ #
15
+
16
+ require 'writeexcel'
17
+
18
+ workbook = WriteExcel.new("right_to_left.xls")
19
+ worksheet1 = workbook.add_worksheet
20
+ worksheet2 = workbook.add_worksheet
21
+
22
+ worksheet2.right_to_left
23
+
24
+ worksheet1.write(0, 0, 'Hello') # A1, B1, C1, ...
25
+ worksheet2.write(0, 0, 'Hello') # ..., C1, B1, A1
26
+
27
+ workbook.close
@@ -0,0 +1,53 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- coding: utf-8 -*-
3
+
4
+ ##############################################################################
5
+ #
6
+ # Demonstrates how to wrap data from one worksheet onto another.
7
+ #
8
+ # Excel has a row limit of 65536 rows. Sometimes the amount of row data to be
9
+ # written to a file is greater than this limit. In this case it is a useful
10
+ # technique to wrap the data from one worksheet onto the next so that we get
11
+ # something like the following:
12
+ #
13
+ # Sheet1 Row 1 - 65536
14
+ # Sheet2 Row 65537 - 131072
15
+ # Sheet3 Row 131073 - ...
16
+ #
17
+ # In order to achieve this we use a single worksheet reference and
18
+ # reinitialise it to point to a new worksheet when required.
19
+ #
20
+ # reverse('©'), May 2006, John McNamara, jmcnamara@cpan.org
21
+ #
22
+ # original written in Perl by John McNamara
23
+ # converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
24
+ #
25
+
26
+ require 'writeexcel'
27
+
28
+ workbook = WriteExcel.new('row_wrap.xls')
29
+ worksheet = workbook.add_worksheet
30
+
31
+ # Worksheet formatting.
32
+ worksheet.set_column('A:A', 20)
33
+
34
+ # For the sake of this example we will use a small row limit. In order to use
35
+ # the entire row range set the row_limit to 65536.
36
+ row_limit = 10
37
+ row = 0
38
+
39
+ (1 .. 2 * row_limit + 10).each do |count|
40
+ # When we hit the row limit we redirect the output
41
+ # to a new worksheet and reset the row number.
42
+ if row == row_limit
43
+ worksheet = workbook.add_worksheet
44
+ row = 0
45
+
46
+ # Repeat any worksheet formatting.
47
+ worksheet.set_column('A:A', 20)
48
+ end
49
+ worksheet.write(row, 0, "This is row #{count}")
50
+ row += 1
51
+ end
52
+
53
+ workbook.close
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- coding:utf-8 -*-
3
+
4
+ require 'rubygems'
5
+ require 'writeexcel'
6
+
7
+ workbook = WriteExcel.new('set_first_sheet.xls')
8
+ 20.times { workbook.add_worksheet }
9
+ worksheet21 = workbook.add_worksheet
10
+ worksheet22 = workbook.add_worksheet
11
+
12
+ worksheet21.set_first_sheet
13
+ worksheet22.activate
14
+ workbook.close
@@ -0,0 +1,74 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- coding: utf-8 -*-
3
+
4
+ ###############################################################################
5
+ #
6
+ # This is a simple example of how to use functions with the
7
+ # WriteExcel module.
8
+ #
9
+ # reverse('©'), March 2001, 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 'writeexcel'
16
+ xlsfile = 'stats.xls'
17
+
18
+ workbook = WriteExcel.new(xlsfile)
19
+ worksheet = workbook.add_worksheet('Test data')
20
+
21
+ # Set the column width for columns 1
22
+ worksheet.set_column(0, 0, 20)
23
+
24
+
25
+ # Create a format for the headings
26
+ format = workbook.add_format
27
+ format.set_bold
28
+
29
+
30
+ # Write the sample data
31
+ worksheet.write(0, 0, 'Sample', format)
32
+ worksheet.write(0, 1, 1)
33
+ worksheet.write(0, 2, 2)
34
+ worksheet.write(0, 3, 3)
35
+ worksheet.write(0, 4, 4)
36
+ worksheet.write(0, 5, 5)
37
+ worksheet.write(0, 6, 6)
38
+ worksheet.write(0, 7, 7)
39
+ worksheet.write(0, 8, 8)
40
+
41
+ worksheet.write(1, 0, 'Length', format)
42
+ worksheet.write(1, 1, 25.4)
43
+ worksheet.write(1, 2, 25.4)
44
+ worksheet.write(1, 3, 24.8)
45
+ worksheet.write(1, 4, 25.0)
46
+ worksheet.write(1, 5, 25.3)
47
+ worksheet.write(1, 6, 24.9)
48
+ worksheet.write(1, 7, 25.2)
49
+ worksheet.write(1, 8, 24.8)
50
+
51
+ # Write some statistical functions
52
+ worksheet.write(4, 0, 'Count', format)
53
+ worksheet.write(4, 1, '=COUNT(B1:I1)')
54
+
55
+ worksheet.write(5, 0, 'Sum', format)
56
+ worksheet.write(5, 1, '=SUM(B2:I2)')
57
+
58
+ worksheet.write(6, 0, 'Average', format)
59
+ worksheet.write(6, 1, '=AVERAGE(B2:I2)')
60
+
61
+ worksheet.write(7, 0, 'Min', format)
62
+ worksheet.write(7, 1, '=MIN(B2:I2)')
63
+
64
+ worksheet.write(8, 0, 'Max', format)
65
+ worksheet.write(8, 1, '=MAX(B2:I2)')
66
+
67
+ worksheet.write(9, 0, 'Standard Deviation', format)
68
+ worksheet.write(9, 1, '=STDEV(B2:I2)')
69
+
70
+ worksheet.write(10, 0, 'Kurtosis', format)
71
+ worksheet.write(10, 1, '=KURT(B2:I2)')
72
+
73
+ workbook.close
74
+
@@ -0,0 +1,81 @@
1
+ # -*- coding: utf-8 -*-
2
+ #!/usr/bin/ruby -w
3
+
4
+ ###############################################################################
5
+ #
6
+ # Example of formatting using the WriteExcel module
7
+ #
8
+ # This example shows how to use a conditional numerical format
9
+ # with colours to indicate if a share price has gone up or down.
10
+ #
11
+ # reverse('©'), March 2001, 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("stocks.xls")
22
+ worksheet = workbook.add_worksheet
23
+
24
+ # Set the column width for columns 1, 2, 3 and 4
25
+ worksheet.set_column(0, 3, 15)
26
+
27
+
28
+ # Create a format for the column headings
29
+ header = workbook.add_format
30
+ header.set_bold
31
+ header.set_size(12)
32
+ header.set_color('blue')
33
+
34
+
35
+ # Create a format for the stock price
36
+ f_price = workbook.add_format
37
+ f_price.set_align('left')
38
+ f_price.set_num_format('$0.00')
39
+
40
+
41
+ # Create a format for the stock volume
42
+ f_volume = workbook.add_format
43
+ f_volume.set_align('left')
44
+ f_volume.set_num_format('#,##0')
45
+
46
+
47
+ # Create a format for the price change. This is an example of a conditional
48
+ # format. The number is formatted as a percentage. If it is positive it is
49
+ # formatted in green, if it is negative it is formatted in red and if it is
50
+ # zero it is formatted as the default font colour (in this case black).
51
+ # Note: the [Green] format produces an unappealing lime green. Try
52
+ # [Color 10] instead for a dark green.
53
+ #
54
+ f_change = workbook.add_format
55
+ f_change.set_align('left')
56
+ f_change.set_num_format('[Green]0.0%;[Red]-0.0%;0.0%')
57
+
58
+
59
+ # Write out the data
60
+ worksheet.write(0, 0, 'Company', header)
61
+ worksheet.write(0, 1, 'Price', header)
62
+ worksheet.write(0, 2, 'Volume', header)
63
+ worksheet.write(0, 3, 'Change', header)
64
+
65
+ worksheet.write(1, 0, 'Damage Inc.' )
66
+ worksheet.write(1, 1, 30.25, f_price) # $30.25
67
+ worksheet.write(1, 2, 1234567, f_volume) # 1,234,567
68
+ worksheet.write(1, 3, 0.085, f_change) # 8.5% in green
69
+
70
+ worksheet.write(2, 0, 'Dump Corp.' )
71
+ worksheet.write(2, 1, 1.56, f_price) # $1.56
72
+ worksheet.write(2, 2, 7564, f_volume) # 7,564
73
+ worksheet.write(2, 3, -0.015, f_change) # -1.5% in red
74
+
75
+ worksheet.write(3, 0, 'Rev Ltd.' )
76
+ worksheet.write(3, 1, 0.13, f_price) # $0.13
77
+ worksheet.write(3, 2, 321, f_volume) # 321
78
+ worksheet.write(3, 3, 0, f_change) # 0 in the font color (black)
79
+
80
+
81
+ workbook.close
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'writeexcel'
5
+
6
+ # Create a new workbook called simple.xls and add a worksheet
7
+ workbook = WriteExcel.new('store_formula.xls')
8
+ worksheet = workbook.add_worksheet()
9
+
10
+ formula = worksheet.store_formula('=A1 * 3 + 50')
11
+ (0 .. 999).each do |row|
12
+ worksheet.repeat_formula(row, 1, formula, nil, 'A1', "A#{row + 1}")
13
+ end
14
+
15
+ workbook.close
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- coding: utf-8 -*-
3
+
4
+ #######################################################################
5
+ #
6
+ # Example of how to set Excel worksheet tab colours.
7
+ #
8
+ # reverse('©'), May 2006, 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
+ workbook = WriteExcel.new('tab_colors.xls')
18
+
19
+ worksheet1 = workbook.add_worksheet
20
+ worksheet2 = workbook.add_worksheet
21
+ worksheet3 = workbook.add_worksheet
22
+ worksheet4 = workbook.add_worksheet
23
+
24
+ # Worsheet1 will have the default tab colour.
25
+ worksheet2.set_tab_color('red')
26
+ worksheet3.set_tab_color('green')
27
+ worksheet4.set_tab_color(0x35) # Orange
28
+
29
+ workbook.close
30
+
31
+ workbook.close
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- coding: utf-8 -*-
3
+
4
+ $debug = true
5
+
6
+ require 'writeexcel'
7
+
8
+ workbook = WriteExcel.new('utf8.xls')
9
+ worksheet = workbook.add_worksheet('シート1')
10
+ format = workbook.add_format(:font => 'MS 明朝')
11
+ worksheet.set_footer('フッター')
12
+ worksheet.set_header('ヘッダー')
13
+ worksheet.write('A1', 'UTF8文字列', format)
14
+ worksheet.write('A2', '=CONCATENATE(A1,"の連結")', format)
15
+ workbook.close
@@ -0,0 +1,83 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- coding: utf-8 -*-
3
+
4
+ #######################################################################
5
+ #
6
+ # Example of how to use the WriteExcel module to
7
+ # write 1D and 2D arrays of data.
8
+ #
9
+ require 'rubygems'
10
+ require 'writeexcel'
11
+
12
+ workbook = WriteExcel.new("write_arrays.xls")
13
+ worksheet1 = workbook.add_worksheet('Example 1')
14
+ worksheet2 = workbook.add_worksheet('Example 2')
15
+ worksheet3 = workbook.add_worksheet('Example 3')
16
+ worksheet4 = workbook.add_worksheet('Example 4')
17
+ worksheet5 = workbook.add_worksheet('Example 5')
18
+ worksheet6 = workbook.add_worksheet('Example 6')
19
+ worksheet7 = workbook.add_worksheet('Example 7')
20
+ worksheet8 = workbook.add_worksheet('Example 8')
21
+
22
+ format = workbook.add_format(:color => 'red', :bold => 1)
23
+ format_cmd = workbook.add_format(:color => 'blue', :bold => 1)
24
+ # Data arrays used in the following examples.
25
+ # undef values are written as blank cells (with format if specified).
26
+ #
27
+ array = [ 'one', 'two', nil, 'four' ]
28
+
29
+ array2d = [
30
+ ['maggie', 'milly', 'molly', 'may' ],
31
+ [13, 14, 15, 16 ],
32
+ ['shell', 'star', 'crab', 'stone'],
33
+ ]
34
+
35
+ # 1. Write a row of data using an array.
36
+ #
37
+ # array[0] array[1] array[2]
38
+ worksheet1.write('A1', "worksheet1.write('A3', array)", format_cmd)
39
+ worksheet1.write('A3', array)
40
+
41
+ # 2. Write a data using an array of array.
42
+ #
43
+ # array[0]
44
+ # array[1]
45
+ # array[2]
46
+ worksheet2.write('A1', "worksheet2.write('A3', [ array ])", format_cmd)
47
+ worksheet2.write('A3', [ array ])
48
+
49
+ # 3. Write a row of data using an explicit write_row() method call.
50
+ # This is the same as calling write() in Ex. 1 above.
51
+ #
52
+ worksheet3.write('A1', "worksheet3.write_row('A3', array)", format_cmd)
53
+ worksheet3.write_row('A3', array)
54
+
55
+ # 4. Write a column of data using the write_col() method call.
56
+ # This is same as Ex. 2 above.
57
+ worksheet4.write('A1', "worksheet4.write_col('A3', array)", format_cmd)
58
+ worksheet4.write_col('A3', array)
59
+
60
+ # 5. Write a 2D array in col-row order.
61
+ # array[0][0] array[1][0] ...
62
+ # array[0][1] array[1][1] ...
63
+ # array[0][2] array[1][2] ...
64
+ worksheet5.write('A1', "worksheet5.write('A3', array2d)", format_cmd)
65
+ worksheet5.write('A3', array2d)
66
+
67
+ # 6. Write a 2D array in row-col order using array of 2D array.
68
+ # array[0][0] array[0][1] ...
69
+ # array[1][0] array[1][1] ...
70
+ # array[2][0] array[2][1] ...
71
+ worksheet6.write('A1', "worksheet6.write('A3', [ array2d ] )", format_cmd)
72
+ worksheet6.write('A3', [ array2d ] )
73
+
74
+ # 7. Write a 2D array in row-col order using write_col().
75
+ # This is same as Ex. 6 above.
76
+ worksheet7.write('A1', "worksheet7.write_col('A3', array2d)", format_cmd)
77
+ worksheet7.write_col('A3', array2d)
78
+
79
+ # 8. Write a row of data with formatting. The blank cell is also formatted.
80
+ worksheet8.write('A1', "worksheet8.write('A3', array, format)", format_cmd)
81
+ worksheet8.write('A3', array, format)
82
+
83
+ workbook.close