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,83 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- coding: utf-8 -*-
3
+
4
+ ###############################################################################
5
+ #
6
+ # Example of how to use the WriteExcel merge_range() workbook
7
+ # method with complex formatting.
8
+ #
9
+ # reverse('©'), September 2002, John McNamara, jmcnamara@cpan.org
10
+ #
11
+ # original written in Perl by John McNamara
12
+ # converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
13
+ #
14
+
15
+ require 'rubygems'
16
+ require 'writeexcel'
17
+
18
+ # Create a new workbook and add a worksheet
19
+ workbook = WriteExcel.new('merge4.xls')
20
+ worksheet = workbook.add_worksheet
21
+
22
+ # Increase the cell size of the merged cells to highlight the formatting.
23
+ (1..11).each { |row| worksheet.set_row(row, 30) }
24
+ worksheet.set_column('B:D', 20)
25
+
26
+ ###############################################################################
27
+ #
28
+ # Example 1: Text centered vertically and horizontally
29
+ #
30
+ format1 = workbook.add_format(
31
+ :border => 6,
32
+ :bold => 1,
33
+ :color => 'red',
34
+ :valign => 'vcenter',
35
+ :align => 'center'
36
+ )
37
+
38
+ worksheet.merge_range('B2:D3', 'Vertical and horizontal', format1)
39
+
40
+
41
+ ###############################################################################
42
+ #
43
+ # Example 2: Text aligned to the top and left
44
+ #
45
+ format2 = workbook.add_format(
46
+ :border => 6,
47
+ :bold => 1,
48
+ :color => 'red',
49
+ :valign => 'top',
50
+ :align => 'left'
51
+ )
52
+
53
+ worksheet.merge_range('B5:D6', 'Aligned to the top and left', format2)
54
+
55
+ ###############################################################################
56
+ #
57
+ # Example 3: Text aligned to the bottom and right
58
+ #
59
+ format3 = workbook.add_format(
60
+ :border => 6,
61
+ :bold => 1,
62
+ :color => 'red',
63
+ :valign => 'bottom',
64
+ :align => 'right'
65
+ )
66
+
67
+ worksheet.merge_range('B8:D9', 'Aligned to the bottom and right', format3)
68
+
69
+ ###############################################################################
70
+ #
71
+ # Example 4: Text justified (i.e. wrapped) in the cell
72
+ #
73
+ format4 = workbook.add_format(
74
+ :border => 6,
75
+ :bold => 1,
76
+ :color => 'red',
77
+ :valign => 'top',
78
+ :align => 'justify'
79
+ )
80
+
81
+ worksheet.merge_range('B11:D12', 'Justified: '+'so on and '*18, format4)
82
+
83
+ workbook.close
@@ -0,0 +1,80 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- coding: utf-8 -*-
3
+
4
+ ###############################################################################
5
+ #
6
+ # Example of how to use the WriteExcel merge_cells() workbook
7
+ # method with complex formatting and rotation.
8
+ #
9
+ #
10
+ # reverse('©'), September 2002, 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 'rubygems'
17
+ require 'writeexcel'
18
+
19
+ # Create a new workbook and add a worksheet
20
+ workbook = WriteExcel.new('merge5.xls')
21
+ worksheet = workbook.add_worksheet
22
+
23
+
24
+ # Increase the cell size of the merged cells to highlight the formatting.
25
+ (3..8).each { |col| worksheet.set_row(col, 36) }
26
+ [1, 3, 5].each { |n| worksheet.set_column(n, n, 15) }
27
+
28
+
29
+ ###############################################################################
30
+ #
31
+ # Rotation 1, letters run from top to bottom
32
+ #
33
+ format1 = workbook.add_format(
34
+ :border => 6,
35
+ :bold => 1,
36
+ :color => 'red',
37
+ :valign => 'vcentre',
38
+ :align => 'centre',
39
+ :rotation => 270
40
+ )
41
+
42
+
43
+ worksheet.merge_range('B4:B9', 'Rotation 270', format1)
44
+
45
+
46
+ ###############################################################################
47
+ #
48
+ # Rotation 2, 90° anticlockwise
49
+ #
50
+ format2 = workbook.add_format(
51
+ :border => 6,
52
+ :bold => 1,
53
+ :color => 'red',
54
+ :valign => 'vcentre',
55
+ :align => 'centre',
56
+ :rotation => 90
57
+ )
58
+
59
+
60
+ worksheet.merge_range('D4:D9', 'Rotation 90°', format2)
61
+
62
+
63
+
64
+ ###############################################################################
65
+ #
66
+ # Rotation 3, 90° clockwise
67
+ #
68
+ format3 = workbook.add_format(
69
+ :border => 6,
70
+ :bold => 1,
71
+ :color => 'red',
72
+ :valign => 'vcentre',
73
+ :align => 'centre',
74
+ :rotation => -90
75
+ )
76
+
77
+
78
+ worksheet.merge_range('F4:F9', 'Rotation -90°', format3)
79
+
80
+ workbook.close
@@ -0,0 +1,67 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- coding: utf-8 -*-
3
+
4
+ ###############################################################################
5
+ #
6
+ # Example of how to use the Spreadsheet::WriteExcel merge_cells() workbook
7
+ # method with Unicode strings.
8
+ #
9
+ #
10
+ # reverse('©'), December 2005, 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
+ # Create a new workbook and add a worksheet
19
+ workbook = WriteExcel.new('merge6.xls')
20
+ worksheet = workbook.add_worksheet
21
+
22
+ # Increase the cell size of the merged cells to highlight the formatting.
23
+ (2..9).each { |i| worksheet.set_row(i, 36) }
24
+ worksheet.set_column('B:D', 25)
25
+
26
+ # Format for the merged cells.
27
+ format = workbook.add_format(
28
+ :border => 6,
29
+ :bold => 1,
30
+ :color => 'red',
31
+ :size => 20,
32
+ :valign => 'vcentre',
33
+ :align => 'left',
34
+ :indent => 1
35
+ )
36
+
37
+ ###############################################################################
38
+ #
39
+ # Write an Ascii string.
40
+ #
41
+
42
+ worksheet.merge_range('B3:D4', 'ASCII: A simple string', format)
43
+
44
+ ###############################################################################
45
+ #
46
+ # Write a UTF-16 Unicode string.
47
+ #
48
+
49
+ # A phrase in Cyrillic encoded as UTF-16BE.
50
+ utf16_str = [
51
+ '005500540046002d00310036003a0020' <<
52
+ '042d0442043e002004440440043004370430002004' <<
53
+ '3d043000200440044304410441043a043e043c0021'
54
+ ].pack("H*")
55
+
56
+ # Note the extra parameter at the end to indicate UTF-16 encoding.
57
+ worksheet.merge_range('B6:D7', utf16_str, format, 1)
58
+
59
+ ###############################################################################
60
+ #
61
+ # Write a UTF-8 Unicode string.
62
+ #
63
+
64
+ smiley = '☺' # chr 0x263a in perl
65
+ worksheet.merge_range('B9:D10', "UTF-8: A Unicode smiley #{smiley}", format)
66
+
67
+ workbook.close
@@ -0,0 +1,255 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- coding: utf-8 -*-
3
+
4
+ ###############################################################################
5
+ #
6
+ # Example of how use Spreadsheet::WriteExcel to generate Excel outlines and
7
+ # grouping.
8
+ #
9
+ #
10
+ # Excel allows you to group rows or columns so that they can be hidden or
11
+ # displayed with a single mouse click. This feature is referred to as outlines.
12
+ #
13
+ # Outlines can reduce complex data down to a few salient sub-totals or
14
+ # summaries.
15
+ #
16
+ # This feature is best viewed in Excel but the following is an ASCII
17
+ # representation of what a worksheet with three outlines might look like.
18
+ # Rows 3-4 and rows 7-8 are grouped at level 2. Rows 2-9 are grouped at
19
+ # level 1. The lines at the left hand side are called outline level bars.
20
+ #
21
+ #
22
+ # ------------------------------------------
23
+ # 1 2 3 | | A | B | C | D | ...
24
+ # ------------------------------------------
25
+ # _ | 1 | A | | | | ...
26
+ # | _ | 2 | B | | | | ...
27
+ # | | | 3 | (C) | | | | ...
28
+ # | | | 4 | (D) | | | | ...
29
+ # | - | 5 | E | | | | ...
30
+ # | _ | 6 | F | | | | ...
31
+ # | | | 7 | (G) | | | | ...
32
+ # | | | 8 | (H) | | | | ...
33
+ # | - | 9 | I | | | | ...
34
+ # - | . | ... | ... | ... | ... | ...
35
+ #
36
+ #
37
+ # Clicking the minus sign on each of the level 2 outlines will collapse and
38
+ # hide the data as shown in the next figure. The minus sign changes to a plus
39
+ # sign to indicate that the data in the outline is hidden.
40
+ #
41
+ # ------------------------------------------
42
+ # 1 2 3 | | A | B | C | D | ...
43
+ # ------------------------------------------
44
+ # _ | 1 | A | | | | ...
45
+ # | | 2 | B | | | | ...
46
+ # | + | 5 | E | | | | ...
47
+ # | | 6 | F | | | | ...
48
+ # | + | 9 | I | | | | ...
49
+ # - | . | ... | ... | ... | ... | ...
50
+ #
51
+ #
52
+ # Clicking on the minus sign on the level 1 outline will collapse the remaining
53
+ # rows as follows:
54
+ #
55
+ # ------------------------------------------
56
+ # 1 2 3 | | A | B | C | D | ...
57
+ # ------------------------------------------
58
+ # | 1 | A | | | | ...
59
+ # + | . | ... | ... | ... | ... | ...
60
+ #
61
+ # See the main Spreadsheet::WriteExcel documentation for more information.
62
+ #
63
+ # reverse('©'), April 2003, John McNamara, jmcnamara@cpan.org
64
+ #
65
+ # original written in Perl by John McNamara
66
+ # converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
67
+ #
68
+
69
+ require 'writeexcel'
70
+
71
+ # Create a new workbook and add some worksheets
72
+ workbook = WriteExcel.new('outline.xls')
73
+ worksheet1 = workbook.add_worksheet('Outlined Rows')
74
+ worksheet2 = workbook.add_worksheet('Collapsed Rows')
75
+ worksheet3 = workbook.add_worksheet('Outline Columns')
76
+ worksheet4 = workbook.add_worksheet('Outline levels')
77
+
78
+ # Add a general format
79
+ bold = workbook.add_format(:bold => 1)
80
+
81
+
82
+
83
+ ###############################################################################
84
+ #
85
+ # Example 1: Create a worksheet with outlined rows. It also includes SUBTOTAL()
86
+ # functions so that it looks like the type of automatic outlines that are
87
+ # generated when you use the Excel Data->SubTotals menu item.
88
+ #
89
+
90
+
91
+ # For outlines the important parameters are $hidden and $level. Rows with the
92
+ # same $level are grouped together. The group will be collapsed if $hidden is
93
+ # non-zero. $height and $XF are assigned default values if they are undef.
94
+ #
95
+ # The syntax is: set_row($row, $height, $XF, $hidden, $level, $collapsed)
96
+ #
97
+ worksheet1.set_row(1, nil, nil, 0, 2)
98
+ worksheet1.set_row(2, nil, nil, 0, 2)
99
+ worksheet1.set_row(3, nil, nil, 0, 2)
100
+ worksheet1.set_row(4, nil, nil, 0, 2)
101
+ worksheet1.set_row(5, nil, nil, 0, 1)
102
+
103
+ worksheet1.set_row(6, nil, nil, 0, 2)
104
+ worksheet1.set_row(7, nil, nil, 0, 2)
105
+ worksheet1.set_row(8, nil, nil, 0, 2)
106
+ worksheet1.set_row(9, nil, nil, 0, 2)
107
+ worksheet1.set_row(10, nil, nil, 0, 1)
108
+
109
+
110
+ # Add a column format for clarity
111
+ worksheet1.set_column('A:A', 20)
112
+
113
+ # Add the data, labels and formulas
114
+ worksheet1.write('A1', 'Region', bold)
115
+ worksheet1.write('A2', 'North')
116
+ worksheet1.write('A3', 'North')
117
+ worksheet1.write('A4', 'North')
118
+ worksheet1.write('A5', 'North')
119
+ worksheet1.write('A6', 'North Total', bold)
120
+
121
+ worksheet1.write('B1', 'Sales', bold)
122
+ worksheet1.write('B2', 1000)
123
+ worksheet1.write('B3', 1200)
124
+ worksheet1.write('B4', 900)
125
+ worksheet1.write('B5', 1200)
126
+ worksheet1.write('B6', '=SUBTOTAL(9,B2:B5)', bold)
127
+
128
+ worksheet1.write('A7', 'South')
129
+ worksheet1.write('A8', 'South')
130
+ worksheet1.write('A9', 'South')
131
+ worksheet1.write('A10', 'South')
132
+ worksheet1.write('A11', 'South Total', bold)
133
+
134
+ worksheet1.write('B7', 400)
135
+ worksheet1.write('B8', 600)
136
+ worksheet1.write('B9', 500)
137
+ worksheet1.write('B10', 600)
138
+ worksheet1.write('B11', '=SUBTOTAL(9,B7:B10)', bold)
139
+
140
+ worksheet1.write('A12', 'Grand Total', bold)
141
+ worksheet1.write('B12', '=SUBTOTAL(9,B2:B10)', bold)
142
+
143
+
144
+ ###############################################################################
145
+ #
146
+ # Example 2: Create a worksheet with outlined rows. This is the same as the
147
+ # previous example except that the rows are collapsed.
148
+ # Note: We need to indicate the row that contains the collapsed symbol '+'
149
+ # with the optional parameter, $collapsed.
150
+
151
+ # The group will be collapsed if $hidden is non-zero.
152
+ # The syntax is: set_row($row, $height, $XF, $hidden, $level, $collapsed)
153
+ #
154
+ worksheet2.set_row(1, nil, nil, 1, 2)
155
+ worksheet2.set_row(2, nil, nil, 1, 2)
156
+ worksheet2.set_row(3, nil, nil, 1, 2)
157
+ worksheet2.set_row(4, nil, nil, 1, 2)
158
+ worksheet2.set_row(5, nil, nil, 1, 1)
159
+
160
+ worksheet2.set_row(6, nil, nil, 1, 2)
161
+ worksheet2.set_row(7, nil, nil, 1, 2)
162
+ worksheet2.set_row(8, nil, nil, 1, 2)
163
+ worksheet2.set_row(9, nil, nil, 1, 2)
164
+ worksheet2.set_row(10, nil, nil, 1, 1)
165
+ worksheet2.set_row(11, nil, nil, 0, 0, 1)
166
+
167
+
168
+ # Add a column format for clarity
169
+ worksheet2.set_column('A:A', 20)
170
+
171
+ # Add the data, labels and formulas
172
+ worksheet2.write('A1', 'Region', bold)
173
+ worksheet2.write('A2', 'North')
174
+ worksheet2.write('A3', 'North')
175
+ worksheet2.write('A4', 'North')
176
+ worksheet2.write('A5', 'North')
177
+ worksheet2.write('A6', 'North Total', bold)
178
+
179
+ worksheet2.write('B1', 'Sales', bold)
180
+ worksheet2.write('B2', 1000)
181
+ worksheet2.write('B3', 1200)
182
+ worksheet2.write('B4', 900)
183
+ worksheet2.write('B5', 1200)
184
+ worksheet2.write('B6', '=SUBTOTAL(9,B2:B5)', bold)
185
+
186
+ worksheet2.write('A7', 'South')
187
+ worksheet2.write('A8', 'South')
188
+ worksheet2.write('A9', 'South')
189
+ worksheet2.write('A10', 'South')
190
+ worksheet2.write('A11', 'South Total', bold)
191
+
192
+ worksheet2.write('B7', 400)
193
+ worksheet2.write('B8', 600)
194
+ worksheet2.write('B9', 500)
195
+ worksheet2.write('B10', 600)
196
+ worksheet2.write('B11', '=SUBTOTAL(9,B7:B10)', bold)
197
+
198
+ worksheet2.write('A12', 'Grand Total', bold)
199
+ worksheet2.write('B12', '=SUBTOTAL(9,B2:B10)', bold)
200
+
201
+
202
+
203
+ ###############################################################################
204
+ #
205
+ # Example 3: Create a worksheet with outlined columns.
206
+ #
207
+ data = [
208
+ ['Month', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', ' Total'],
209
+ ['North', 50, 20, 15, 25, 65, 80, '=SUM(B2:G2)'],
210
+ ['South', 10, 20, 30, 50, 50, 50, '=SUM(B3:G3)'],
211
+ ['East', 45, 75, 50, 15, 75, 100, '=SUM(B4:G4)'],
212
+ ['West', 15, 15, 55, 35, 20, 50, '=SUM(B5:G6)']
213
+ ]
214
+
215
+ # Add bold format to the first row
216
+ worksheet3.set_row(0, nil, bold)
217
+
218
+ # Syntax: set_column(col1, col2, width, XF, hidden, level, collapsed)
219
+ worksheet3.set_column('A:A', 10, bold )
220
+ worksheet3.set_column('B:G', 5, nil, 0, 1)
221
+ worksheet3.set_column('H:H', 10)
222
+
223
+ # Write the data and a formula
224
+ worksheet3.write_col('A1', data)
225
+ worksheet3.write('H6', '=SUM(H2:H5)', bold)
226
+
227
+
228
+
229
+ ###############################################################################
230
+ #
231
+ # Example 4: Show all possible outline levels.
232
+ #
233
+ levels = [
234
+ "Level 1", "Level 2", "Level 3", "Level 4",
235
+ "Level 5", "Level 6", "Level 7", "Level 6",
236
+ "Level 5", "Level 4", "Level 3", "Level 2", "Level 1"
237
+ ]
238
+
239
+ worksheet4.write_col('A1', levels)
240
+
241
+ worksheet4.set_row(0, nil, nil, nil, 1)
242
+ worksheet4.set_row(1, nil, nil, nil, 2)
243
+ worksheet4.set_row(2, nil, nil, nil, 3)
244
+ worksheet4.set_row(3, nil, nil, nil, 4)
245
+ worksheet4.set_row(4, nil, nil, nil, 5)
246
+ worksheet4.set_row(5, nil, nil, nil, 6)
247
+ worksheet4.set_row(6, nil, nil, nil, 7)
248
+ worksheet4.set_row(7, nil, nil, nil, 6)
249
+ worksheet4.set_row(8, nil, nil, nil, 5)
250
+ worksheet4.set_row(9, nil, nil, nil, 4)
251
+ worksheet4.set_row(10, nil, nil, nil, 3)
252
+ worksheet4.set_row(11, nil, nil, nil, 2)
253
+ worksheet4.set_row(12, nil, nil, nil, 1)
254
+
255
+ workbook.close