writeexcel 0.3.5 → 0.4.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 (122) hide show
  1. data/.gitattributes +1 -0
  2. data/README.rdoc +12 -6
  3. data/VERSION +1 -1
  4. data/charts/chartex.rb +316 -315
  5. data/charts/demo1.rb +1 -0
  6. data/charts/demo2.rb +1 -0
  7. data/charts/demo3.rb +117 -116
  8. data/charts/demo4.rb +119 -118
  9. data/charts/demo5.rb +48 -47
  10. data/examples/a_simple.rb +1 -0
  11. data/examples/autofilter.rb +1 -0
  12. data/examples/bigfile.rb +30 -29
  13. data/examples/chart_area.rb +121 -120
  14. data/examples/chart_bar.rb +120 -119
  15. data/examples/chart_column.rb +120 -119
  16. data/examples/chart_line.rb +120 -119
  17. data/examples/chart_pie.rb +108 -107
  18. data/examples/chart_scatter.rb +121 -120
  19. data/examples/chart_stock.rb +148 -147
  20. data/examples/chess.rb +1 -0
  21. data/examples/colors.rb +1 -0
  22. data/examples/comments1.rb +1 -0
  23. data/examples/comments2.rb +3 -2
  24. data/examples/copyformat.rb +1 -0
  25. data/examples/data_validate.rb +1 -0
  26. data/examples/date_time.rb +1 -0
  27. data/examples/defined_name.rb +1 -0
  28. data/examples/demo.rb +1 -0
  29. data/examples/diag_border.rb +1 -0
  30. data/examples/formats.rb +1 -0
  31. data/examples/formula_result.rb +1 -0
  32. data/examples/header.rb +1 -0
  33. data/examples/hide_sheet.rb +1 -0
  34. data/examples/hyperlink.rb +1 -0
  35. data/examples/images.rb +1 -0
  36. data/examples/indent.rb +1 -0
  37. data/examples/merge1.rb +1 -0
  38. data/examples/merge2.rb +1 -0
  39. data/examples/merge3.rb +1 -0
  40. data/examples/merge4.rb +1 -0
  41. data/examples/merge5.rb +1 -0
  42. data/examples/merge6.rb +67 -66
  43. data/examples/outline.rb +1 -0
  44. data/examples/outline_collapsed.rb +1 -0
  45. data/examples/panes.rb +1 -0
  46. data/examples/properties.rb +1 -0
  47. data/examples/properties_jp.rb +1 -0
  48. data/examples/protection.rb +1 -0
  49. data/examples/regions.rb +1 -0
  50. data/examples/repeat.rb +1 -0
  51. data/examples/right_to_left.rb +1 -0
  52. data/examples/row_wrap.rb +1 -0
  53. data/examples/stats.rb +1 -0
  54. data/examples/stocks.rb +1 -0
  55. data/examples/tab_colors.rb +1 -0
  56. data/examples/write_arrays.rb +1 -0
  57. data/lib/writeexcel.rb +6 -1
  58. data/lib/writeexcel/biffwriter.rb +21 -20
  59. data/lib/writeexcel/chart.rb +25 -12
  60. data/lib/writeexcel/charts/area.rb +153 -152
  61. data/lib/writeexcel/charts/bar.rb +178 -177
  62. data/lib/writeexcel/charts/column.rb +157 -156
  63. data/lib/writeexcel/charts/external.rb +62 -61
  64. data/lib/writeexcel/charts/line.rb +153 -152
  65. data/lib/writeexcel/charts/pie.rb +170 -169
  66. data/lib/writeexcel/charts/scatter.rb +4 -3
  67. data/lib/writeexcel/charts/stock.rb +212 -211
  68. data/lib/writeexcel/compatibility.rb +320 -0
  69. data/lib/writeexcel/excelformulaparser.rb +587 -586
  70. data/lib/writeexcel/format.rb +12 -13
  71. data/lib/writeexcel/formula.rb +30 -28
  72. data/lib/writeexcel/helper.rb +23 -0
  73. data/lib/writeexcel/olewriter.rb +5 -16
  74. data/lib/writeexcel/properties.rb +43 -54
  75. data/lib/writeexcel/storage_lite.rb +981 -968
  76. data/lib/writeexcel/workbook.rb +94 -73
  77. data/lib/writeexcel/worksheet.rb +230 -210
  78. data/test/helper.rb +19 -0
  79. data/test/test_00_IEEE_double.rb +1 -0
  80. data/test/test_01_add_worksheet.rb +1 -0
  81. data/test/test_02_merge_formats.rb +3 -5
  82. data/test/test_04_dimensions.rb +3 -5
  83. data/test/test_05_rows.rb +6 -6
  84. data/test/test_06_extsst.rb +8 -8
  85. data/test/test_11_date_time.rb +3 -5
  86. data/test/test_12_date_only.rb +3 -5
  87. data/test/test_13_date_seconds.rb +4 -6
  88. data/test/test_21_escher.rb +3 -5
  89. data/test/test_22_mso_drawing_group.rb +20 -22
  90. data/test/test_23_note.rb +5 -7
  91. data/test/test_24_txo.rb +3 -5
  92. data/test/test_25_position_object.rb +84 -79
  93. data/test/test_26_autofilter.rb +3 -13
  94. data/test/test_27_autofilter.rb +3 -13
  95. data/test/test_28_autofilter.rb +3 -13
  96. data/test/test_29_process_jpg.rb +5 -0
  97. data/test/test_30_validation_dval.rb +3 -5
  98. data/test/test_31_validation_dv_strings.rb +3 -5
  99. data/test/test_32_validation_dv_formula.rb +3 -5
  100. data/test/test_40_property_types.rb +10 -9
  101. data/test/test_41_properties.rb +1 -0
  102. data/test/test_42_set_properties.rb +14 -15
  103. data/test/test_50_name_stored.rb +299 -302
  104. data/test/test_51_name_print_area.rb +357 -360
  105. data/test/test_52_name_print_titles.rb +454 -457
  106. data/test/test_53_autofilter.rb +203 -206
  107. data/test/test_60_chart_generic.rb +5 -0
  108. data/test/test_61_chart_subclasses.rb +95 -94
  109. data/test/test_62_chart_formats.rb +272 -267
  110. data/test/test_63_chart_area_formats.rb +649 -644
  111. data/test/test_biff.rb +12 -38
  112. data/test/test_compatibility.rb +627 -0
  113. data/test/test_example_match.rb +3 -18
  114. data/test/test_format.rb +46 -105
  115. data/test/test_formula.rb +1 -0
  116. data/test/test_ole.rb +3 -4
  117. data/test/test_storage_lite.rb +125 -146
  118. data/test/test_workbook.rb +2 -23
  119. data/test/test_worksheet.rb +4 -5
  120. data/utils/add_magic_comment.rb +80 -0
  121. data/writeexcel.gemspec +8 -2
  122. metadata +10 -4
@@ -1,147 +1,148 @@
1
- #!/usr/bin/ruby -w
2
- #
3
- ###############################################################################
4
- #
5
- # A simple demo of Stock charts in Spreadsheet::WriteExcel.
6
- #
7
- # reverse('©'), January 2010, 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 'writeexcel'
13
-
14
- workbook = WriteExcel.new('chart_stock.xls')
15
- worksheet = workbook.add_worksheet
16
-
17
- ###############################################################################
18
- #
19
- # Set up the data worksheet that the charts will refer to. We read the example
20
- # data from the __DATA__ section at the end of the file. This simulates
21
- # reading the data from a database or other source.
22
- #
23
- # The default Excel Stock chart is an Open-High-Low-Close chart. Therefore
24
- # we will need data for each of those series.
25
- #
26
- # The layout of the __DATA__ section is similar to the layout of the worksheet.
27
- #
28
-
29
- # Add some formats.
30
- bold = workbook.add_format(:bold => 1)
31
- date_format = workbook.add_format(:num_format => 'dd/mm/yyyy')
32
-
33
- # Increase the width of the column used for date to make it clearer.
34
- worksheet.set_column('A:A', 12)
35
-
36
- stock_data = [
37
- %w(Date Open High Low Close),
38
- ['2009-08-19', 100.00, 104.06, 95.96, 100.34],
39
- ['2009-08-20', 101.01, 109.08, 100.50, 108.31],
40
- ['2009-08-23', 110.75, 113.48, 109.05, 109.40],
41
- ['2009-08-24', 111.24, 111.60, 103.57, 104.87],
42
- ['2009-08-25', 104.96, 108.00, 103.88, 106.00],
43
- ['2009-08-26', 104.95, 107.95, 104.66, 107.91],
44
- ['2009-08-27', 108.10, 108.62, 105.69, 106.15],
45
- ['2009-08-30', 105.28, 105.49, 102.01, 102.01],
46
- ['2009-08-31', 102.30, 103.71, 102.16, 102.37]
47
- ]
48
-
49
- # Write the data to the worksheet.
50
- row = 0
51
- col = 0
52
-
53
- headers = stock_data.shift
54
- worksheet.write(row, col, headers, bold)
55
- row += 1
56
-
57
- stock_data.each do |data|
58
- date = data.shift
59
- worksheet.write(row, col, date, date_format)
60
- worksheet.write(row, col + 1, data)
61
- row += 1
62
- end
63
-
64
- ###############################################################################
65
- #
66
- # Example 1. A default Open-High-Low-Close chart with series names, axes labels
67
- # and a title.
68
- #
69
-
70
- chart1 = workbook.add_chart(:type => Chart::Stock)
71
-
72
- # Add a series for each of the Open-High-Low-Close columns. The categories are
73
- # the dates in the first column.
74
-
75
- chart1.add_series(
76
- :categories => '=Sheet1!$A$2:$A$10',
77
- :values => '=Sheet1!$B$2:$B$10',
78
- :name => 'Open'
79
- )
80
-
81
- chart1.add_series(
82
- :categories => '=Sheet1!$A$2:$A$10',
83
- :values => '=Sheet1!$C$2:$C$10',
84
- :name => 'High'
85
- )
86
-
87
- chart1.add_series(
88
- :categories => '=Sheet1!$A$2:$A$10',
89
- :values => '=Sheet1!$D$2:$D$10',
90
- :name => 'Low'
91
- )
92
-
93
- chart1.add_series(
94
- :categories => '=Sheet1!$A$2:$A$10',
95
- :values => '=Sheet1!$E$2:$E$10',
96
- :name => 'Close'
97
- )
98
-
99
- # Add a chart title and axes labels.
100
- chart1.set_title(:name => 'Open-High-Low-Close')
101
- chart1.set_x_axis(:name => 'Date')
102
- chart1.set_y_axis(:name => 'Share price')
103
-
104
- ###############################################################################
105
- #
106
- # Example 2. Same as the previous as an embedded chart.
107
- #
108
-
109
- chart2 = workbook.add_chart(:type => Chart::Stock, :embedded => 1)
110
-
111
- # Add a series for each of the Open-High-Low-Close columns. The categories are
112
- # the dates in the first column.
113
-
114
- chart2.add_series(
115
- :categories => '=Sheet1!$A$2:$A$10',
116
- :values => '=Sheet1!$B$2:$B$10',
117
- :name => 'Open'
118
- )
119
-
120
- chart2.add_series(
121
- :categories => '=Sheet1!$A$2:$A$10',
122
- :values => '=Sheet1!$C$2:$C$10',
123
- :name => 'High'
124
- )
125
-
126
- chart2.add_series(
127
- :categories => '=Sheet1!$A$2:$A$10',
128
- :values => '=Sheet1!$D$2:$D$10',
129
- :name => 'Low'
130
- )
131
-
132
- chart2.add_series(
133
- :categories => '=Sheet1!$A$2:$A$10',
134
- :values => '=Sheet1!$E$2:$E$10',
135
- :name => 'Close'
136
- )
137
-
138
- # Add a chart title and axes labels.
139
- chart2.set_title(:name => 'Open-High-Low-Close')
140
- chart2.set_x_axis(:name => 'Date')
141
- chart2.set_y_axis(:name => 'Share price')
142
-
143
- # Insert the chart into the main worksheet.
144
- worksheet.insert_chart('G2', chart2)
145
-
146
- # File save
147
- workbook.close
1
+ #!/usr/bin/ruby -w
2
+ # -*- coding: utf-8 -*-
3
+ #
4
+ ###############################################################################
5
+ #
6
+ # A simple demo of Stock charts in Spreadsheet::WriteExcel.
7
+ #
8
+ # reverse('©'), January 2010, John McNamara, jmcnamara@cpan.org
9
+ #
10
+ # original written in Perl by John McNamara
11
+ # converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
12
+ #
13
+ require 'writeexcel'
14
+
15
+ workbook = WriteExcel.new('chart_stock.xls')
16
+ worksheet = workbook.add_worksheet
17
+
18
+ ###############################################################################
19
+ #
20
+ # Set up the data worksheet that the charts will refer to. We read the example
21
+ # data from the __DATA__ section at the end of the file. This simulates
22
+ # reading the data from a database or other source.
23
+ #
24
+ # The default Excel Stock chart is an Open-High-Low-Close chart. Therefore
25
+ # we will need data for each of those series.
26
+ #
27
+ # The layout of the __DATA__ section is similar to the layout of the worksheet.
28
+ #
29
+
30
+ # Add some formats.
31
+ bold = workbook.add_format(:bold => 1)
32
+ date_format = workbook.add_format(:num_format => 'dd/mm/yyyy')
33
+
34
+ # Increase the width of the column used for date to make it clearer.
35
+ worksheet.set_column('A:A', 12)
36
+
37
+ stock_data = [
38
+ %w(Date Open High Low Close),
39
+ ['2009-08-19', 100.00, 104.06, 95.96, 100.34],
40
+ ['2009-08-20', 101.01, 109.08, 100.50, 108.31],
41
+ ['2009-08-23', 110.75, 113.48, 109.05, 109.40],
42
+ ['2009-08-24', 111.24, 111.60, 103.57, 104.87],
43
+ ['2009-08-25', 104.96, 108.00, 103.88, 106.00],
44
+ ['2009-08-26', 104.95, 107.95, 104.66, 107.91],
45
+ ['2009-08-27', 108.10, 108.62, 105.69, 106.15],
46
+ ['2009-08-30', 105.28, 105.49, 102.01, 102.01],
47
+ ['2009-08-31', 102.30, 103.71, 102.16, 102.37]
48
+ ]
49
+
50
+ # Write the data to the worksheet.
51
+ row = 0
52
+ col = 0
53
+
54
+ headers = stock_data.shift
55
+ worksheet.write(row, col, headers, bold)
56
+ row += 1
57
+
58
+ stock_data.each do |data|
59
+ date = data.shift
60
+ worksheet.write(row, col, date, date_format)
61
+ worksheet.write(row, col + 1, data)
62
+ row += 1
63
+ end
64
+
65
+ ###############################################################################
66
+ #
67
+ # Example 1. A default Open-High-Low-Close chart with series names, axes labels
68
+ # and a title.
69
+ #
70
+
71
+ chart1 = workbook.add_chart(:type => Chart::Stock)
72
+
73
+ # Add a series for each of the Open-High-Low-Close columns. The categories are
74
+ # the dates in the first column.
75
+
76
+ chart1.add_series(
77
+ :categories => '=Sheet1!$A$2:$A$10',
78
+ :values => '=Sheet1!$B$2:$B$10',
79
+ :name => 'Open'
80
+ )
81
+
82
+ chart1.add_series(
83
+ :categories => '=Sheet1!$A$2:$A$10',
84
+ :values => '=Sheet1!$C$2:$C$10',
85
+ :name => 'High'
86
+ )
87
+
88
+ chart1.add_series(
89
+ :categories => '=Sheet1!$A$2:$A$10',
90
+ :values => '=Sheet1!$D$2:$D$10',
91
+ :name => 'Low'
92
+ )
93
+
94
+ chart1.add_series(
95
+ :categories => '=Sheet1!$A$2:$A$10',
96
+ :values => '=Sheet1!$E$2:$E$10',
97
+ :name => 'Close'
98
+ )
99
+
100
+ # Add a chart title and axes labels.
101
+ chart1.set_title(:name => 'Open-High-Low-Close')
102
+ chart1.set_x_axis(:name => 'Date')
103
+ chart1.set_y_axis(:name => 'Share price')
104
+
105
+ ###############################################################################
106
+ #
107
+ # Example 2. Same as the previous as an embedded chart.
108
+ #
109
+
110
+ chart2 = workbook.add_chart(:type => Chart::Stock, :embedded => 1)
111
+
112
+ # Add a series for each of the Open-High-Low-Close columns. The categories are
113
+ # the dates in the first column.
114
+
115
+ chart2.add_series(
116
+ :categories => '=Sheet1!$A$2:$A$10',
117
+ :values => '=Sheet1!$B$2:$B$10',
118
+ :name => 'Open'
119
+ )
120
+
121
+ chart2.add_series(
122
+ :categories => '=Sheet1!$A$2:$A$10',
123
+ :values => '=Sheet1!$C$2:$C$10',
124
+ :name => 'High'
125
+ )
126
+
127
+ chart2.add_series(
128
+ :categories => '=Sheet1!$A$2:$A$10',
129
+ :values => '=Sheet1!$D$2:$D$10',
130
+ :name => 'Low'
131
+ )
132
+
133
+ chart2.add_series(
134
+ :categories => '=Sheet1!$A$2:$A$10',
135
+ :values => '=Sheet1!$E$2:$E$10',
136
+ :name => 'Close'
137
+ )
138
+
139
+ # Add a chart title and axes labels.
140
+ chart2.set_title(:name => 'Open-High-Low-Close')
141
+ chart2.set_x_axis(:name => 'Date')
142
+ chart2.set_y_axis(:name => 'Share price')
143
+
144
+ # Insert the chart into the main worksheet.
145
+ worksheet.insert_chart('G2', chart2)
146
+
147
+ # File save
148
+ workbook.close
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/ruby -w
2
+ # -*- coding: utf-8 -*-
2
3
 
3
4
  ########################################################################
4
5
  #
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/ruby -w
2
+ # -*- coding: utf-8 -*-
2
3
 
3
4
  ################################################################################
4
5
  #
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/ruby -w
2
+ # -*- coding: utf-8 -*-
2
3
 
3
4
  ###############################################################################
4
5
  #
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/ruby -w
2
+ # -*- coding: utf-8 -*-
2
3
 
3
4
  ###############################################################################
4
5
  #
@@ -59,7 +60,7 @@
59
60
  worksheet1.write('C6', cell_text, text_wrap)
60
61
  worksheet1.write_comment('C6', comment, :encoding => 1)
61
62
 
62
- # UTF-8 string in perl 5.8.
63
+ # UTF-8 string.
63
64
  worksheet1.set_row(8, 50)
64
65
  cell_text = 'This is a UTF-8 string.'
65
66
  comment = '☺' # chr 0x263a in perl.
@@ -306,7 +307,7 @@
306
307
  worksheet7.write_comment(cell, comment, :author => author,
307
308
  :author_encoding => 1)
308
309
 
309
- # UTF-8 string in perl 5.8.
310
+ # UTF-8 string.
310
311
  author = '☺' # smiley
311
312
  cell = 'C12'
312
313
  cell_text = "Move the mouse over this cell and you will see 'Cell commented " +
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/ruby -w
2
+ # -*- coding: utf-8 -*-
2
3
 
3
4
  ###############################################################################
4
5
  #
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/ruby -w
2
+ # -*- coding: utf-8 -*-
2
3
 
3
4
  ###############################################################################
4
5
  #
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/ruby -w
2
+ # -*- coding: utf-8 -*-
2
3
 
3
4
  ###############################################################################
4
5
  #
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/ruby -w
2
+ # -*- coding: utf-8 -*-
2
3
 
3
4
  ###############################################################################
4
5
  #
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/ruby -w
2
+ # -*- coding: utf-8 -*-
2
3
 
3
4
  #######################################################################
4
5
  #
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/ruby -w
2
+ # -*- coding: utf-8 -*-
2
3
 
3
4
  ##############################################################################
4
5
  #
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/ruby -w
2
+ # -*- coding: utf-8 -*-
2
3
 
3
4
  ######################################################################
4
5
  #
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/ruby -w
2
+ # -*- coding: utf-8 -*-
2
3
 
3
4
  #######################################################################
4
5
  #
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/ruby -w
2
+ # -*- coding: utf-8 -*-
2
3
 
3
4
  ######################################################################
4
5
  #
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/ruby -w
2
+ # -*- coding: utf-8 -*-
2
3
 
3
4
  #######################################################################
4
5
  #
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/ruby -w
2
+ # -*- coding: utf-8 -*-
2
3
  ###############################################################################
3
4
  #
4
5
  # Example of how to use the WriteExcel module to write hyperlinks
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/ruby -w
2
+ # -*- coding: utf-8 -*-
2
3
 
3
4
  #######################################################################
4
5
  #
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/ruby -w
2
+ # -*- coding: utf-8 -*-
2
3
 
3
4
  ##############################################################################
4
5
  #
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/ruby -w
2
+ # -*- coding: utf-8 -*-
2
3
 
3
4
  ###############################################################################
4
5
  #
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/ruby -w
2
+ # -*- coding: utf-8 -*-
2
3
 
3
4
  ###############################################################################
4
5
  #
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/ruby -w
2
+ # -*- coding: utf-8 -*-
2
3
 
3
4
  ###############################################################################
4
5
  #