writeexcel 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (109) hide show
  1. data/README +103 -0
  2. data/examples/a_simple.rb +42 -0
  3. data/examples/autofilters.rb +266 -0
  4. data/examples/copyformat.rb +51 -0
  5. data/examples/data_validate.rb +278 -0
  6. data/examples/date_time.rb +86 -0
  7. data/examples/demo.rb +118 -0
  8. data/examples/diag_border.rb +35 -0
  9. data/examples/formats.rb +489 -0
  10. data/examples/header.rb +136 -0
  11. data/examples/hidden.rb +28 -0
  12. data/examples/hyperlink.rb +42 -0
  13. data/examples/images.rb +52 -0
  14. data/examples/merge1.rb +39 -0
  15. data/examples/merge2.rb +44 -0
  16. data/examples/merge3.rb +65 -0
  17. data/examples/merge4.rb +82 -0
  18. data/examples/merge5.rb +79 -0
  19. data/examples/protection.rb +46 -0
  20. data/examples/regions.rb +52 -0
  21. data/examples/repeat.rb +42 -0
  22. data/examples/republic.png +0 -0
  23. data/examples/stats.rb +75 -0
  24. data/examples/stocks.rb +80 -0
  25. data/examples/tab_colors.rb +30 -0
  26. data/lib/writeexcel/biffwriter.rb +260 -0
  27. data/lib/writeexcel/chart.rb +217 -0
  28. data/lib/writeexcel/excelformulaparser.rb +573 -0
  29. data/lib/writeexcel/format.rb +1108 -0
  30. data/lib/writeexcel/formula.rb +986 -0
  31. data/lib/writeexcel/olewriter.rb +322 -0
  32. data/lib/writeexcel/properties.rb +250 -0
  33. data/lib/writeexcel/workbook.rb +2630 -0
  34. data/lib/writeexcel/worksheet.rb +6377 -0
  35. data/lib/writeexcel.rb +18 -0
  36. data/test/perl_output/README +31 -0
  37. data/test/perl_output/a_simple.xls +0 -0
  38. data/test/perl_output/biff_add_continue_testdata +0 -0
  39. data/test/perl_output/data_validate.xls +0 -0
  40. data/test/perl_output/date_time.xls +0 -0
  41. data/test/perl_output/demo.xls +0 -0
  42. data/test/perl_output/diag_border.xls +0 -0
  43. data/test/perl_output/f_font_biff +0 -0
  44. data/test/perl_output/f_font_key +1 -0
  45. data/test/perl_output/f_xf_biff +0 -0
  46. data/test/perl_output/file_font_biff +0 -0
  47. data/test/perl_output/file_font_key +1 -0
  48. data/test/perl_output/file_xf_biff +0 -0
  49. data/test/perl_output/headers.xls +0 -0
  50. data/test/perl_output/hidden.xls +0 -0
  51. data/test/perl_output/hyperlink.xls +0 -0
  52. data/test/perl_output/images.xls +0 -0
  53. data/test/perl_output/merge1.xls +0 -0
  54. data/test/perl_output/merge2.xls +0 -0
  55. data/test/perl_output/merge3.xls +0 -0
  56. data/test/perl_output/merge4.xls +0 -0
  57. data/test/perl_output/merge5.xls +0 -0
  58. data/test/perl_output/ole_write_header +0 -0
  59. data/test/perl_output/protection.xls +0 -0
  60. data/test/perl_output/regions.xls +0 -0
  61. data/test/perl_output/stats.xls +0 -0
  62. data/test/perl_output/stocks.xls +0 -0
  63. data/test/perl_output/tab_colors.xls +0 -0
  64. data/test/perl_output/unicode_cyrillic.xls +0 -0
  65. data/test/perl_output/workbook1.xls +0 -0
  66. data/test/perl_output/workbook2.xls +0 -0
  67. data/test/perl_output/ws_colinfo +1 -0
  68. data/test/perl_output/ws_store_colinfo +0 -0
  69. data/test/perl_output/ws_store_dimensions +0 -0
  70. data/test/perl_output/ws_store_filtermode +0 -0
  71. data/test/perl_output/ws_store_filtermode_off +0 -0
  72. data/test/perl_output/ws_store_filtermode_on +0 -0
  73. data/test/perl_output/ws_store_selection +0 -0
  74. data/test/perl_output/ws_store_window2 +1 -0
  75. data/test/republic.png +0 -0
  76. data/test/tc_all.rb +31 -0
  77. data/test/tc_biff.rb +104 -0
  78. data/test/tc_chart.rb +22 -0
  79. data/test/tc_example_match.rb +1280 -0
  80. data/test/tc_format.rb +1267 -0
  81. data/test/tc_formula.rb +63 -0
  82. data/test/tc_ole.rb +110 -0
  83. data/test/tc_workbook.rb +115 -0
  84. data/test/tc_worksheet.rb +115 -0
  85. data/test/test_00_IEEE_double.rb +14 -0
  86. data/test/test_01_add_worksheet.rb +12 -0
  87. data/test/test_02_merge_formats.rb +58 -0
  88. data/test/test_04_dimensions.rb +397 -0
  89. data/test/test_05_rows.rb +182 -0
  90. data/test/test_06_extsst.rb +80 -0
  91. data/test/test_11_date_time.rb +484 -0
  92. data/test/test_12_date_only.rb +506 -0
  93. data/test/test_13_date_seconds.rb +486 -0
  94. data/test/test_21_escher.rb +629 -0
  95. data/test/test_22_mso_drawing_group.rb +739 -0
  96. data/test/test_23_note.rb +78 -0
  97. data/test/test_24_txo.rb +80 -0
  98. data/test/test_26_autofilter.rb +327 -0
  99. data/test/test_27_autofilter.rb +144 -0
  100. data/test/test_28_autofilter.rb +174 -0
  101. data/test/test_29_process_jpg.rb +131 -0
  102. data/test/test_30_validation_dval.rb +82 -0
  103. data/test/test_31_validation_dv_strings.rb +131 -0
  104. data/test/test_32_validation_dv_formula.rb +211 -0
  105. data/test/test_40_property_types.rb +191 -0
  106. data/test/test_41_properties.rb +238 -0
  107. data/test/test_42_set_properties.rb +419 -0
  108. data/test/ts_all.rb +34 -0
  109. metadata +170 -0
@@ -0,0 +1,278 @@
1
+ #!/usr/bin/ruby -w
2
+
3
+ ###############################################################################
4
+ #
5
+ # Example of how to add data validation and dropdown lists to a
6
+ # Spreadsheet::WriteExcel file.
7
+ #
8
+ # reverse('©'), August 2008, 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('data_validate.xls')
18
+ worksheet = workbook.add_worksheet
19
+
20
+ # Add a format for the header cells.
21
+ header_format = workbook.add_format(
22
+ :border => 1,
23
+ :bg_color => 43,
24
+ :bold => 1,
25
+ :text_wrap => 1,
26
+ :valign => 'vcenter',
27
+ :indent => 1
28
+ )
29
+
30
+ # Set up layout of the worksheet.
31
+ worksheet.set_column('A:A', 64)
32
+ worksheet.set_column('B:B', 15)
33
+ worksheet.set_column('D:D', 15)
34
+ worksheet.set_row(0, 36)
35
+ worksheet.set_selection('B3')
36
+
37
+
38
+ # Write the header cells and some data that will be used in the examples.
39
+ row = 0
40
+ heading1 = 'Some examples of data validation in Spreadsheet::WriteExcel'
41
+ heading2 = 'Enter values in this column'
42
+ heading3 = 'Sample Data'
43
+
44
+ worksheet.write('A1', heading1, header_format)
45
+ worksheet.write('B1', heading2, header_format)
46
+ worksheet.write('D1', heading3, header_format)
47
+
48
+ worksheet.write('D3', ['Integers', 1, 10])
49
+ worksheet.write('D4', ['List data', 'open', 'high', 'close'])
50
+ worksheet.write('D5', ['Formula', '=AND(F5=50,G5=60)', 50, 60])
51
+
52
+
53
+ #
54
+ # Example 1. Limiting input to an integer in a fixed range.
55
+ #
56
+ txt = 'Enter an integer between 1 and 10'
57
+ row += 2
58
+
59
+ worksheet.write(row, 0, txt)
60
+ worksheet.data_validation(row, 1,
61
+ {
62
+ :validate => 'integer',
63
+ :criteria => 'between',
64
+ :minimum => 1,
65
+ :maximum => 10
66
+ })
67
+
68
+
69
+ #
70
+ # Example 2. Limiting input to an integer outside a fixed range.
71
+ #
72
+ txt = 'Enter an integer that is not between 1 and 10 (using cell references)'
73
+ row += 2
74
+
75
+ worksheet.write(row, 0, txt)
76
+ worksheet.data_validation(row, 1,
77
+ {
78
+ :validate => 'integer',
79
+ :criteria => 'not between',
80
+ :minimum => '=E3',
81
+ :maximum => '=F3'
82
+ })
83
+
84
+
85
+ #
86
+ # Example 3. Limiting input to an integer greater than a fixed value.
87
+ #
88
+ txt = 'Enter an integer greater than 0'
89
+ row += 2
90
+
91
+ worksheet.write(row, 0, txt)
92
+ worksheet.data_validation(row, 1,
93
+ {
94
+ :validate => 'integer',
95
+ :criteria => '>',
96
+ :value => 0
97
+ })
98
+
99
+
100
+ #
101
+ # Example 4. Limiting input to an integer less than a fixed value.
102
+ #
103
+ txt = 'Enter an integer less than 10'
104
+ row += 2
105
+
106
+ worksheet.write(row, 0, txt)
107
+ worksheet.data_validation(row, 1,
108
+ {
109
+ :validate => 'integer',
110
+ :criteria => '<',
111
+ :value => 10
112
+ })
113
+
114
+
115
+ #
116
+ # Example 5. Limiting input to a decimal in a fixed range.
117
+ #
118
+ txt = 'Enter a decimal between 0.1 and 0.5'
119
+ row += 2
120
+
121
+ worksheet.write(row, 0, txt)
122
+ worksheet.data_validation(row, 1,
123
+ {
124
+ :validate => 'decimal',
125
+ :criteria => 'between',
126
+ :minimum => 0.1,
127
+ :maximum => 0.5
128
+ })
129
+
130
+
131
+ #
132
+ # Example 6. Limiting input to a value in a dropdown list.
133
+ #
134
+ txt = 'Select a value from a drop down list'
135
+ row += 2
136
+ bp=1
137
+ worksheet.write(row, 0, txt)
138
+ worksheet.data_validation(row, 1,
139
+ {
140
+ :validate => 'list',
141
+ :source => ['open', 'high', 'close']
142
+ })
143
+
144
+
145
+ #
146
+ # Example 6. Limiting input to a value in a dropdown list.
147
+ #
148
+ txt = 'Select a value from a drop down list (using a cell range)'
149
+ row += 2
150
+
151
+ worksheet.write(row, 0, txt)
152
+ worksheet.data_validation(row, 1,
153
+ {
154
+ :validate => 'list',
155
+ :source => '=E4:G4'
156
+ })
157
+
158
+
159
+ #
160
+ # Example 7. Limiting input to a date in a fixed range.
161
+ #
162
+ txt = 'Enter a date between 1/1/2008 and 12/12/2008'
163
+ row += 2
164
+
165
+ worksheet.write(row, 0, txt)
166
+ worksheet.data_validation(row, 1,
167
+ {
168
+ :validate => 'date',
169
+ :criteria => 'between',
170
+ :minimum => '2008-01-01T',
171
+ :maximum => '2008-12-12T'
172
+ })
173
+
174
+
175
+ #
176
+ # Example 8. Limiting input to a time in a fixed range.
177
+ #
178
+ txt = 'Enter a time between 6:00 and 12:00'
179
+ row += 2
180
+
181
+ worksheet.write(row, 0, txt)
182
+ worksheet.data_validation(row, 1,
183
+ {
184
+ :validate => 'time',
185
+ :criteria => 'between',
186
+ :minimum => 'T06:00',
187
+ :maximum => 'T12:00'
188
+ })
189
+
190
+
191
+ #
192
+ # Example 9. Limiting input to a string greater than a fixed length.
193
+ #
194
+ txt = 'Enter a string longer than 3 characters'
195
+ row += 2
196
+
197
+ worksheet.write(row, 0, txt)
198
+ worksheet.data_validation(row, 1,
199
+ {
200
+ :validate => 'length',
201
+ :criteria => '>',
202
+ :value => 3
203
+ })
204
+
205
+
206
+ #
207
+ # Example 10. Limiting input based on a formula.
208
+ #
209
+ txt = 'Enter a value if the following is true "=AND(F5=50,G5=60)"'
210
+ row += 2
211
+
212
+ worksheet.write(row, 0, txt)
213
+ worksheet.data_validation(row, 1,
214
+ {
215
+ :validate => 'custom',
216
+ :value => '=AND(F5=50,G5=60)'
217
+ })
218
+
219
+
220
+ #
221
+ # Example 11. Displaying and modify data validation messages.
222
+ #
223
+ txt = 'Displays a message when you select the cell'
224
+ row += 2
225
+
226
+ worksheet.write(row, 0, txt)
227
+ worksheet.data_validation(row, 1,
228
+ {
229
+ :validate => 'integer',
230
+ :criteria => 'between',
231
+ :minimum => 1,
232
+ :maximum => 100,
233
+ :input_title => 'Enter an integer:',
234
+ :input_message => 'between 1 and 100'
235
+ })
236
+
237
+
238
+ #
239
+ # Example 12. Displaying and modify data validation messages.
240
+ #
241
+ txt = 'Display a custom error message when integer isn\'t between 1 and 100'
242
+ row += 2
243
+
244
+ worksheet.write(row, 0, txt)
245
+ worksheet.data_validation(row, 1,
246
+ {
247
+ :validate => 'integer',
248
+ :criteria => 'between',
249
+ :minimum => 1,
250
+ :maximum => 100,
251
+ :input_title => 'Enter an integer:',
252
+ :input_message => 'between 1 and 100',
253
+ :error_title => 'Input value is not valid!',
254
+ :error_message => 'It should be an integer between 1 and 100'
255
+ })
256
+
257
+
258
+ #
259
+ # Example 13. Displaying and modify data validation messages.
260
+ #
261
+ txt = 'Display a custom information message when integer isn\'t between 1 and 100'
262
+ row += 2
263
+
264
+ worksheet.write(row, 0, txt)
265
+ worksheet.data_validation(row, 1,
266
+ {
267
+ :validate => 'integer',
268
+ :criteria => 'between',
269
+ :minimum => 1,
270
+ :maximum => 100,
271
+ :input_title => 'Enter an integer:',
272
+ :input_message => 'between 1 and 100',
273
+ :error_title => 'Input value is not valid!',
274
+ :error_message => 'It should be an integer between 1 and 100',
275
+ :error_type => 'information'
276
+ })
277
+
278
+ workbook.close
@@ -0,0 +1,86 @@
1
+ #!/usr/bin/ruby -w
2
+
3
+ ###############################################################################
4
+ #
5
+ # Spreadsheet::WriteExcel example of writing dates and times using the
6
+ # write_date_time() Worksheet method.
7
+ #
8
+ # reverse('©'), August 2004, 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
+ # Create a new workbook and add a worksheet
18
+ workbook = Spreadsheet::WriteExcel.new("date_time.xls")
19
+ worksheet = workbook.add_worksheet
20
+ bold = workbook.add_format(:bold => 1)
21
+
22
+ # Expand the first column so that the date is visible.
23
+ worksheet.set_column("A:B", 30)
24
+
25
+ # Write the column headers
26
+ worksheet.write('A1', 'Formatted date', bold)
27
+ worksheet.write('B1', 'Format', bold)
28
+
29
+ # Examples date and time formats. In the output file compare how changing
30
+ # the format codes change the appearance of the date.
31
+ #
32
+ date_formats = [
33
+ 'dd/mm/yy',
34
+ 'mm/dd/yy',
35
+ '',
36
+ 'd mm yy',
37
+ 'dd mm yy',
38
+ '',
39
+ 'dd m yy',
40
+ 'dd mm yy',
41
+ 'dd mmm yy',
42
+ 'dd mmmm yy',
43
+ '',
44
+ 'dd mm y',
45
+ 'dd mm yyy',
46
+ 'dd mm yyyy',
47
+ '',
48
+ 'd mmmm yyyy',
49
+ '',
50
+ 'dd/mm/yy',
51
+ 'dd/mm/yy hh:mm',
52
+ 'dd/mm/yy hh:mm:ss',
53
+ 'dd/mm/yy hh:mm:ss.000',
54
+ '',
55
+ 'hh:mm',
56
+ 'hh:mm:ss',
57
+ 'hh:mm:ss.000',
58
+ ]
59
+
60
+ # Write the same date and time using each of the above formats. The empty
61
+ # string formats create a blank line to make the example clearer.
62
+ #
63
+ row = 0
64
+ date_formats.each do |date_format|
65
+ row += 1
66
+ next if date_format == ''
67
+
68
+ # Create a format for the date or time.
69
+ format = workbook.add_format(
70
+ :num_format => date_format,
71
+ :align => 'left'
72
+ )
73
+
74
+ # Write the same date using different formats.
75
+ worksheet.write_date_time(row, 0, '2004-08-01T12:30:45.123', format)
76
+ worksheet.write(row, 1, date_format)
77
+ end
78
+
79
+ # The following is an example of an invalid date. It is written as a string instead
80
+ # of a number. This is also Excel's default behaviour.
81
+ #
82
+ row += 2
83
+ worksheet.write_date_time(row, 0, '2004-13-01T12:30:45.123')
84
+ worksheet.write(row, 1, 'Invalid date. Written as string.', bold)
85
+
86
+ workbook.close
data/examples/demo.rb ADDED
@@ -0,0 +1,118 @@
1
+ #!/usr/bin/ruby -w
2
+
3
+ #######################################################################
4
+ #
5
+ # Demo of some of the features of Spreadsheet::WriteExcel.
6
+ # Used to create the project screenshot for Freshmeat.
7
+ #
8
+ #
9
+ # reverse('©'), October 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 = Spreadsheet::WriteExcel.new("demo.xls")
19
+ worksheet = workbook.add_worksheet('Demo')
20
+ worksheet2 = workbook.add_worksheet('Another sheet')
21
+ worksheet3 = workbook.add_worksheet('And another')
22
+
23
+ bold = workbook.add_format(:bold => 1)
24
+
25
+ #######################################################################
26
+ #
27
+ # Write a general heading
28
+ #
29
+ worksheet.set_column('A:A', 36, bold)
30
+ worksheet.set_column('B:B', 20 )
31
+ worksheet.set_row(0, 40 )
32
+
33
+ heading = workbook.add_format(
34
+ :bold => 1,
35
+ :color => 'blue',
36
+ :size => 16,
37
+ :merge => 1,
38
+ :align => 'vcenter'
39
+ )
40
+
41
+ headings = ['Features of Spreadsheet::WriteExcel', '']
42
+ worksheet.write_row('A1', headings, heading)
43
+
44
+
45
+ #######################################################################
46
+ #
47
+ # Some text examples
48
+ #
49
+ text_format = workbook.add_format(
50
+ :bold => 1,
51
+ :italic => 1,
52
+ :color => 'red',
53
+ :size => 18,
54
+ :font =>'Lucida Calligraphy'
55
+ )
56
+
57
+ # A phrase in Cyrillic
58
+ unicode = [
59
+ "042d0442043e002004440440043004370430002004"+
60
+ "3d043000200440044304410441043a043e043c0021"
61
+ ].pack('H*')
62
+
63
+ worksheet.write('A2', "Text")
64
+ worksheet.write('B2', "Hello Excel")
65
+ worksheet.write('A3', "Formatted text")
66
+ worksheet.write('B3', "Hello Excel", text_format)
67
+ worksheet.write('A4', "Unicode text")
68
+ worksheet.write_utf16be_string('B4', unicode)
69
+
70
+
71
+ #######################################################################
72
+ #
73
+ # Some numeric examples
74
+ #
75
+ num1_format = workbook.add_format(:num_format => '$#,##0.00')
76
+ num2_format = workbook.add_format(:num_format => ' d mmmm yyy')
77
+
78
+ worksheet.write('A5', "Numbers")
79
+ worksheet.write('B5', 1234.56)
80
+ worksheet.write('A6', "Formatted numbers")
81
+ worksheet.write('B6', 1234.56, num1_format)
82
+ worksheet.write('A7', "Formatted numbers")
83
+ worksheet.write('B7', 37257, num2_format)
84
+
85
+
86
+ #######################################################################
87
+ #
88
+ # Formulae
89
+ #
90
+ worksheet.set_selection('B8')
91
+ worksheet.write('A8', 'Formulas and functions, "=SIN(PI()/4)"')
92
+ worksheet.write('B8', '=SIN(PI()/4)')
93
+
94
+
95
+ #######################################################################
96
+ #
97
+ # Hyperlinks
98
+ #
99
+ worksheet.write('A9', "Hyperlinks")
100
+ worksheet.write('B9', 'http://www.perl.com/' )
101
+
102
+
103
+ #######################################################################
104
+ #
105
+ # Images
106
+ #
107
+ worksheet.write('A10', "Images")
108
+ worksheet.insert_image('B10', 'republic.png', 16, 8)
109
+
110
+
111
+ #######################################################################
112
+ #
113
+ # Misc
114
+ #
115
+ worksheet.write('A18', "Page/printer setup")
116
+ worksheet.write('A19', "Multiple worksheets")
117
+
118
+ workbook.close
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/ruby -w
2
+
3
+ ##############################################################################
4
+ #
5
+ # A simple formatting example using Spreadsheet::WriteExcel.
6
+ #
7
+ # This program demonstrates the diagonal border cell format.
8
+ #
9
+ # reverse('©'), May 2004, 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 = Spreadsheet::WriteExcel.new('diag_border.xls')
19
+ worksheet = workbook.add_worksheet
20
+
21
+ format1 = workbook.add_format(:diag_type => 1)
22
+ format2 = workbook.add_format(:diag_type => 2)
23
+ format3 = workbook.add_format(:diag_type => 3)
24
+ format4 = workbook.add_format(
25
+ :diag_type => 3,
26
+ :diag_border => 7,
27
+ :diag_color => 'red'
28
+ )
29
+
30
+ worksheet.write('B3', 'Text', format1)
31
+ worksheet.write('B6', 'Text', format2)
32
+ worksheet.write('B9', 'Text', format3)
33
+ worksheet.write('B12', 'Text', format4)
34
+
35
+ workbook.close