writeexcel 0.1.0 → 0.3.0

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 (143) hide show
  1. data/README +26 -31
  2. data/examples/a_simple.rb +42 -42
  3. data/examples/{autofilters.rb → autofilter.rb} +264 -266
  4. data/examples/bigfile.rb +29 -0
  5. data/examples/chart_area.rb +120 -0
  6. data/examples/chart_bar.rb +119 -0
  7. data/examples/chart_column.rb +119 -0
  8. data/examples/chart_line.rb +119 -0
  9. data/examples/chart_pie.rb +107 -0
  10. data/examples/chart_scatter.rb +120 -0
  11. data/examples/chart_stock.rb +147 -0
  12. data/examples/copyformat.rb +51 -51
  13. data/examples/data_validate.rb +278 -278
  14. data/examples/date_time.rb +86 -86
  15. data/examples/defined_name.rb +31 -0
  16. data/examples/demo.rb +120 -118
  17. data/examples/diag_border.rb +35 -35
  18. data/examples/formats.rb +489 -489
  19. data/examples/header.rb +136 -136
  20. data/examples/hidden.rb +28 -28
  21. data/examples/hyperlink.rb +42 -42
  22. data/examples/images.rb +52 -52
  23. data/examples/merge1.rb +39 -39
  24. data/examples/merge2.rb +44 -44
  25. data/examples/merge3.rb +65 -65
  26. data/examples/merge4.rb +82 -82
  27. data/examples/merge5.rb +79 -79
  28. data/examples/properties.rb +33 -0
  29. data/examples/properties_jp.rb +32 -0
  30. data/examples/protection.rb +46 -46
  31. data/examples/regions.rb +52 -52
  32. data/examples/repeat.rb +42 -42
  33. data/examples/stats.rb +75 -75
  34. data/examples/stocks.rb +80 -80
  35. data/examples/tab_colors.rb +30 -30
  36. data/examples/write_arrays.rb +82 -0
  37. data/lib/writeexcel.rb +1134 -18
  38. data/lib/writeexcel/biffwriter.rb +273 -260
  39. data/lib/writeexcel/chart.rb +2306 -217
  40. data/lib/writeexcel/charts/area.rb +152 -0
  41. data/lib/writeexcel/charts/bar.rb +177 -0
  42. data/lib/writeexcel/charts/column.rb +156 -0
  43. data/lib/writeexcel/charts/external.rb +61 -0
  44. data/lib/writeexcel/charts/line.rb +152 -0
  45. data/lib/writeexcel/charts/pie.rb +169 -0
  46. data/lib/writeexcel/charts/scatter.rb +192 -0
  47. data/lib/writeexcel/charts/stock.rb +211 -0
  48. data/lib/writeexcel/excelformulaparser.rb +208 -195
  49. data/lib/writeexcel/format.rb +1697 -1108
  50. data/lib/writeexcel/formula.rb +1050 -986
  51. data/lib/writeexcel/olewriter.rb +322 -322
  52. data/lib/writeexcel/properties.rb +251 -250
  53. data/lib/writeexcel/storage_lite.rb +968 -0
  54. data/lib/writeexcel/workbook.rb +3294 -2630
  55. data/lib/writeexcel/worksheet.rb +9012 -6377
  56. data/test/excelfile/Chart1.xls +0 -0
  57. data/test/excelfile/Chart2.xls +0 -0
  58. data/test/excelfile/Chart3.xls +0 -0
  59. data/test/excelfile/Chart4.xls +0 -0
  60. data/test/excelfile/Chart5.xls +0 -0
  61. data/test/perl_output/Chart1.xls.data +0 -0
  62. data/test/perl_output/Chart2.xls.data +0 -0
  63. data/test/perl_output/Chart3.xls.data +0 -0
  64. data/test/perl_output/Chart4.xls.data +0 -0
  65. data/test/perl_output/Chart5.xls.data +0 -0
  66. data/test/perl_output/a_simple.xls +0 -0
  67. data/test/perl_output/autofilter.xls +0 -0
  68. data/test/perl_output/chart_area.xls +0 -0
  69. data/test/perl_output/chart_bar.xls +0 -0
  70. data/test/perl_output/chart_column.xls +0 -0
  71. data/test/perl_output/chart_line.xls +0 -0
  72. data/test/perl_output/data_validate.xls +0 -0
  73. data/test/perl_output/date_time.xls +0 -0
  74. data/test/perl_output/demo.xls +0 -0
  75. data/test/perl_output/demo101.bin +0 -0
  76. data/test/perl_output/demo201.bin +0 -0
  77. data/test/perl_output/demo301.bin +0 -0
  78. data/test/perl_output/demo401.bin +0 -0
  79. data/test/perl_output/demo501.bin +0 -0
  80. data/test/perl_output/diag_border.xls +0 -0
  81. data/test/perl_output/headers.xls +0 -0
  82. data/test/perl_output/hyperlink.xls +0 -0
  83. data/test/perl_output/images.xls +0 -0
  84. data/test/perl_output/merge1.xls +0 -0
  85. data/test/perl_output/merge2.xls +0 -0
  86. data/test/perl_output/merge3.xls +0 -0
  87. data/test/perl_output/merge4.xls +0 -0
  88. data/test/perl_output/merge5.xls +0 -0
  89. data/test/perl_output/protection.xls +0 -0
  90. data/test/perl_output/regions.xls +0 -0
  91. data/test/perl_output/stats.xls +0 -0
  92. data/test/perl_output/stocks.xls +0 -0
  93. data/test/perl_output/tab_colors.xls +0 -0
  94. data/test/perl_output/unicode_cyrillic.xls +0 -0
  95. data/test/perl_output/workbook1.xls +0 -0
  96. data/test/perl_output/workbook2.xls +0 -0
  97. data/test/tc_all.rb +32 -31
  98. data/test/tc_biff.rb +104 -104
  99. data/test/tc_chart.rb +22 -22
  100. data/test/tc_example_match.rb +1944 -1280
  101. data/test/tc_format.rb +1254 -1267
  102. data/test/tc_formula.rb +63 -63
  103. data/test/tc_ole.rb +110 -110
  104. data/test/tc_storage_lite.rb +149 -0
  105. data/test/tc_workbook.rb +140 -115
  106. data/test/tc_worksheet.rb +115 -115
  107. data/test/test_00_IEEE_double.rb +14 -14
  108. data/test/test_01_add_worksheet.rb +12 -12
  109. data/test/test_02_merge_formats.rb +58 -58
  110. data/test/test_04_dimensions.rb +397 -397
  111. data/test/test_05_rows.rb +182 -182
  112. data/test/test_06_extsst.rb +80 -80
  113. data/test/test_11_date_time.rb +484 -484
  114. data/test/test_12_date_only.rb +506 -506
  115. data/test/test_13_date_seconds.rb +486 -486
  116. data/test/test_21_escher.rb +642 -629
  117. data/test/test_22_mso_drawing_group.rb +750 -739
  118. data/test/test_23_note.rb +78 -78
  119. data/test/test_24_txo.rb +80 -80
  120. data/test/test_25_position_object.rb +82 -0
  121. data/test/test_26_autofilter.rb +327 -327
  122. data/test/test_27_autofilter.rb +144 -144
  123. data/test/test_28_autofilter.rb +174 -174
  124. data/test/test_29_process_jpg.rb +681 -131
  125. data/test/test_30_validation_dval.rb +82 -82
  126. data/test/test_31_validation_dv_strings.rb +131 -131
  127. data/test/test_32_validation_dv_formula.rb +211 -211
  128. data/test/test_40_property_types.rb +191 -191
  129. data/test/test_41_properties.rb +238 -238
  130. data/test/test_42_set_properties.rb +442 -419
  131. data/test/test_50_name_stored.rb +305 -0
  132. data/test/test_51_name_print_area.rb +363 -0
  133. data/test/test_52_name_print_titles.rb +460 -0
  134. data/test/test_53_autofilter.rb +209 -0
  135. data/test/test_60_chart_generic.rb +576 -0
  136. data/test/test_61_chart_subclasses.rb +97 -0
  137. data/test/test_62_chart_formats.rb +270 -0
  138. data/test/test_63_chart_area_formats.rb +647 -0
  139. data/test/test_chartex.rb +35 -0
  140. data/test/ts_all.rb +46 -34
  141. data/writeexcel.gemspec +18 -0
  142. data/writeexcel.rdoc +583 -0
  143. metadata +162 -108
data/examples/merge5.rb CHANGED
@@ -1,79 +1,79 @@
1
- #!/usr/bin/ruby -w
2
-
3
- ###############################################################################
4
- #
5
- # Example of how to use the Spreadsheet::WriteExcel merge_cells() workbook
6
- # method with complex formatting and rotation.
7
- #
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 = Spreadsheet::WriteExcel.new('merge5.xls')
20
- worksheet = workbook.add_worksheet
21
-
22
-
23
- # Increase the cell size of the merged cells to highlight the formatting.
24
- (3..8).each { |col| worksheet.set_row(col, 36) }
25
- [1, 3, 5].each { |n| worksheet.set_column(n, n, 15) }
26
-
27
-
28
- ###############################################################################
29
- #
30
- # Rotation 1, letters run from top to bottom
31
- #
32
- format1 = workbook.add_format(
33
- :border => 6,
34
- :bold => 1,
35
- :color => 'red',
36
- :valign => 'vcentre',
37
- :align => 'centre',
38
- :rotation => 270
39
- )
40
-
41
-
42
- worksheet.merge_range('B4:B9', 'Rotation 270', format1)
43
-
44
-
45
- ###############################################################################
46
- #
47
- # Rotation 2, 90° anticlockwise
48
- #
49
- format2 = workbook.add_format(
50
- :border => 6,
51
- :bold => 1,
52
- :color => 'red',
53
- :valign => 'vcentre',
54
- :align => 'centre',
55
- :rotation => 90
56
- )
57
-
58
-
59
- worksheet.merge_range('D4:D9', 'Rotation 90°', format2)
60
-
61
-
62
-
63
- ###############################################################################
64
- #
65
- # Rotation 3, 90° clockwise
66
- #
67
- format3 = workbook.add_format(
68
- :border => 6,
69
- :bold => 1,
70
- :color => 'red',
71
- :valign => 'vcentre',
72
- :align => 'centre',
73
- :rotation => -90
74
- )
75
-
76
-
77
- worksheet.merge_range('F4:F9', 'Rotation -90°', format3)
78
-
79
- workbook.close
1
+ #!/usr/bin/ruby -w
2
+
3
+ ###############################################################################
4
+ #
5
+ # Example of how to use the WriteExcel merge_cells() workbook
6
+ # method with complex formatting and rotation.
7
+ #
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('merge5.xls')
20
+ worksheet = workbook.add_worksheet
21
+
22
+
23
+ # Increase the cell size of the merged cells to highlight the formatting.
24
+ (3..8).each { |col| worksheet.set_row(col, 36) }
25
+ [1, 3, 5].each { |n| worksheet.set_column(n, n, 15) }
26
+
27
+
28
+ ###############################################################################
29
+ #
30
+ # Rotation 1, letters run from top to bottom
31
+ #
32
+ format1 = workbook.add_format(
33
+ :border => 6,
34
+ :bold => 1,
35
+ :color => 'red',
36
+ :valign => 'vcentre',
37
+ :align => 'centre',
38
+ :rotation => 270
39
+ )
40
+
41
+
42
+ worksheet.merge_range('B4:B9', 'Rotation 270', format1)
43
+
44
+
45
+ ###############################################################################
46
+ #
47
+ # Rotation 2, 90° anticlockwise
48
+ #
49
+ format2 = workbook.add_format(
50
+ :border => 6,
51
+ :bold => 1,
52
+ :color => 'red',
53
+ :valign => 'vcentre',
54
+ :align => 'centre',
55
+ :rotation => 90
56
+ )
57
+
58
+
59
+ worksheet.merge_range('D4:D9', 'Rotation 90°', format2)
60
+
61
+
62
+
63
+ ###############################################################################
64
+ #
65
+ # Rotation 3, 90° clockwise
66
+ #
67
+ format3 = workbook.add_format(
68
+ :border => 6,
69
+ :bold => 1,
70
+ :color => 'red',
71
+ :valign => 'vcentre',
72
+ :align => 'centre',
73
+ :rotation => -90
74
+ )
75
+
76
+
77
+ worksheet.merge_range('F4:F9', 'Rotation -90°', format3)
78
+
79
+ workbook.close
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/ruby -w
2
+
3
+ ##############################################################################
4
+ #
5
+ # An example of adding document properties to a WriteExcel file.
6
+ #
7
+ # reverse('©'), August 2008, John McNamara, jmcnamara@cpan.org
8
+ #
9
+ # original written in Perl by John McNamara
10
+ # converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
11
+ #
12
+ require 'rubygems'
13
+ require 'writeexcel'
14
+
15
+ workbook = WriteExcel.new('properties.xls')
16
+ worksheet = workbook.add_worksheet
17
+ bp =1
18
+ workbook.set_properties(
19
+ :title => 'This is an example spreadsheet',
20
+ :subject => 'With document properties',
21
+ :author => 'Hideo NAKAMURA',
22
+ :manager => 'John McNamara',
23
+ :company => 'Rubygem',
24
+ :category => 'Example spreadsheets',
25
+ :keywords => 'Sample, Example, Properties',
26
+ :comments => 'Created with Ruby and WriteExcel'
27
+ )
28
+
29
+
30
+ worksheet.set_column('A:A', 50)
31
+ worksheet.write('A1', 'Select File->Properties to see the file properties')
32
+
33
+ workbook.close
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/ruby -w
2
+
3
+ ##############################################################################
4
+ #
5
+ # An example of adding document properties to a WriteExcel file.
6
+ #
7
+ # reverse('©'), August 2008, John McNamara, jmcnamara@cpan.org
8
+ #
9
+ # original written in Perl by John McNamara
10
+ # converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
11
+ #
12
+ require 'rubygems'
13
+ require 'writeexcel'
14
+
15
+ workbook = WriteExcel.new('properties_jp.xls')
16
+ worksheet = workbook.add_worksheet
17
+ bp =1
18
+ workbook.set_properties(
19
+ :title => 'スプレッドシートの作成例',
20
+ :subject => 'ファイルのプロパティをセット',
21
+ :author => '中村英夫',
22
+ :manager => 'John McNamara',
23
+ :company => 'Rubygem',
24
+ :category => 'エクセルファイル',
25
+ :keywords => 'エクセル プロパティ UTF-8',
26
+ :comments => 'Rubygem writeexcelで作成'
27
+ )
28
+
29
+ worksheet.set_column('A:A', 50)
30
+ worksheet.write('A1', 'メニューのファイル(F)-プロパティ(I)を見てください。')
31
+
32
+ workbook.close
@@ -1,46 +1,46 @@
1
- #!/usr/bin/ruby -w
2
-
3
- ########################################################################
4
- #
5
- # Example of cell locking and formula hiding in an Excel worksheet via
6
- # the Spreadsheet::WriteExcel module.
7
- #
8
- # reverse('©'), August 2001, 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 = Spreadsheet::WriteExcel.new("protection.xls")
18
- worksheet = workbook.add_worksheet
19
-
20
- # Create some format objects
21
- locked = workbook.add_format(:locked => 1)
22
- unlocked = workbook.add_format(:locked => 0)
23
- hidden = workbook.add_format(:hidden => 1)
24
-
25
- # Format the columns
26
- worksheet.set_column('A:A', 42)
27
- worksheet.set_selection('B3:B3')
28
-
29
- # Protect the worksheet
30
- worksheet.protect
31
-
32
- # Examples of cell locking and hiding
33
- worksheet.write('A1', 'Cell B1 is locked. It cannot be edited.')
34
- worksheet.write('B1', '=1+2', locked)
35
-
36
- worksheet.write('A2', 'Cell B2 is unlocked. It can be edited.')
37
- worksheet.write('B2', '=1+2', unlocked)
38
-
39
- worksheet.write('A3', "Cell B3 is hidden. The formula isn't visible.")
40
- worksheet.write('B3', '=1+2', hidden)
41
-
42
- worksheet.write('A5', 'Use Menu->Tools->Protection->Unprotect Sheet')
43
- worksheet.write('A6', 'to remove the worksheet protection. ')
44
-
45
- workbook.close
46
-
1
+ #!/usr/bin/ruby -w
2
+
3
+ ########################################################################
4
+ #
5
+ # Example of cell locking and formula hiding in an Excel worksheet via
6
+ # the WriteExcel module.
7
+ #
8
+ # reverse('©'), August 2001, 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("protection.xls")
18
+ worksheet = workbook.add_worksheet
19
+
20
+ # Create some format objects
21
+ locked = workbook.add_format(:locked => 1)
22
+ unlocked = workbook.add_format(:locked => 0)
23
+ hidden = workbook.add_format(:hidden => 1)
24
+
25
+ # Format the columns
26
+ worksheet.set_column('A:A', 42)
27
+ worksheet.set_selection('B3:B3')
28
+
29
+ # Protect the worksheet
30
+ worksheet.protect
31
+
32
+ # Examples of cell locking and hiding
33
+ worksheet.write('A1', 'Cell B1 is locked. It cannot be edited.')
34
+ worksheet.write('B1', '=1+2', locked)
35
+
36
+ worksheet.write('A2', 'Cell B2 is unlocked. It can be edited.')
37
+ worksheet.write('B2', '=1+2', unlocked)
38
+
39
+ worksheet.write('A3', "Cell B3 is hidden. The formula isn't visible.")
40
+ worksheet.write('B3', '=1+2', hidden)
41
+
42
+ worksheet.write('A5', 'Use Menu->Tools->Protection->Unprotect Sheet')
43
+ worksheet.write('A6', 'to remove the worksheet protection. ')
44
+
45
+ workbook.close
46
+
data/examples/regions.rb CHANGED
@@ -1,52 +1,52 @@
1
- #!/usr/bin/ruby -w
2
-
3
- ###############################################################################
4
- #
5
- # Example of how to use the WriteExcel module to write a basic multiple
6
- # worksheet Excel file.
7
- #
8
- # reverse('©'), March 2001, 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 = Spreadsheet::WriteExcel.new("regions.xls")
18
-
19
- # Add some worksheets
20
- north = workbook.add_worksheet("North")
21
- south = workbook.add_worksheet("South")
22
- east = workbook.add_worksheet("East")
23
- west = workbook.add_worksheet("West")
24
-
25
- # Add a Format
26
- format = workbook.add_format()
27
- format.set_bold()
28
- format.set_color('blue')
29
-
30
- # Add a caption to each worksheet
31
- workbook.sheets.each do |worksheet|
32
- worksheet.write(0, 0, "Sales", format)
33
- end
34
-
35
- # Write some data
36
- north.write(0, 1, 200000)
37
- south.write(0, 1, 100000)
38
- east.write(0, 1, 150000)
39
- west.write(0, 1, 100000)
40
-
41
- # Set the active worksheet
42
- bp=1
43
- south.activate()
44
-
45
- # Set the width of the first column
46
- south.set_column(0, 0, 20)
47
-
48
- # Set the active cell
49
- south.set_selection(0, 1)
50
-
51
- workbook.close
52
-
1
+ #!/usr/bin/ruby -w
2
+
3
+ ###############################################################################
4
+ #
5
+ # Example of how to use the WriteExcel module to write a basic multiple
6
+ # worksheet Excel file.
7
+ #
8
+ # reverse('©'), March 2001, 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("regions.xls")
18
+
19
+ # Add some worksheets
20
+ north = workbook.add_worksheet("North")
21
+ south = workbook.add_worksheet("South")
22
+ east = workbook.add_worksheet("East")
23
+ west = workbook.add_worksheet("West")
24
+
25
+ # Add a Format
26
+ format = workbook.add_format()
27
+ format.set_bold()
28
+ format.set_color('blue')
29
+
30
+ # Add a caption to each worksheet
31
+ workbook.sheets.each do |worksheet|
32
+ worksheet.write(0, 0, "Sales", format)
33
+ end
34
+
35
+ # Write some data
36
+ north.write(0, 1, 200000)
37
+ south.write(0, 1, 100000)
38
+ east.write(0, 1, 150000)
39
+ west.write(0, 1, 100000)
40
+
41
+ # Set the active worksheet
42
+ bp=1
43
+ south.activate()
44
+
45
+ # Set the width of the first column
46
+ south.set_column(0, 0, 20)
47
+
48
+ # Set the active cell
49
+ south.set_selection(0, 1)
50
+
51
+ workbook.close
52
+
data/examples/repeat.rb CHANGED
@@ -1,42 +1,42 @@
1
- #!/usr/bin/ruby -w
2
-
3
- ######################################################################
4
- #
5
- # Example of writing repeated formulas.
6
- #
7
- # reverse('©'), August 2002, John McNamara, jmcnamara@cpan.org
8
- #
9
- # original written in Perl by John McNamara
10
- # converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
11
- #
12
-
13
- require 'rubygems'
14
- require 'writeexcel'
15
-
16
- workbook = Spreadsheet::WriteExcel.new("repeat.xls")
17
- worksheet = workbook.add_worksheet
18
-
19
- limit = 1000
20
-
21
- # Write a column of numbers
22
- 0.upto(limit) do |row|
23
- worksheet.write(row, 0, row)
24
- end
25
-
26
- # Store a formula
27
- formula = worksheet.store_formula('=A1*5+4')
28
-
29
- # Write a column of formulas based on the stored formula
30
- 0.upto(limit) do |row|
31
- worksheet.repeat_formula(row, 1, formula, nil,
32
- /A1/, 'A'+(row+1).to_s)
33
- end
34
-
35
- # Direct formula writing. As a speed comparison uncomment the
36
- # following and run the program again
37
-
38
- #for row (0..limit) {
39
- # worksheet.write_formula(row, 2, '=A'.(row+1).'*5+4')
40
- #}
41
-
42
- workbook.close
1
+ #!/usr/bin/ruby -w
2
+
3
+ ######################################################################
4
+ #
5
+ # Example of writing repeated formulas.
6
+ #
7
+ # reverse('©'), August 2002, John McNamara, jmcnamara@cpan.org
8
+ #
9
+ # original written in Perl by John McNamara
10
+ # converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
11
+ #
12
+
13
+ require 'rubygems'
14
+ require 'writeexcel'
15
+
16
+ workbook = WriteExcel.new("repeat.xls")
17
+ worksheet = workbook.add_worksheet
18
+
19
+ limit = 1000
20
+
21
+ # Write a column of numbers
22
+ 0.upto(limit) do |row|
23
+ worksheet.write(row, 0, row)
24
+ end
25
+
26
+ # Store a formula
27
+ formula = worksheet.store_formula('=A1*5+4')
28
+
29
+ # Write a column of formulas based on the stored formula
30
+ 0.upto(limit) do |row|
31
+ worksheet.repeat_formula(row, 1, formula, nil,
32
+ /A1/, 'A'+(row+1).to_s)
33
+ end
34
+
35
+ # Direct formula writing. As a speed comparison uncomment the
36
+ # following and run the program again
37
+
38
+ #for row (0..limit) {
39
+ # worksheet.write_formula(row, 2, '=A'.(row+1).'*5+4')
40
+ #}
41
+
42
+ workbook.close