WriteExcel 0.2.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 (80) hide show
  1. data/.document +5 -0
  2. data/.gitignore +21 -0
  3. data/LICENSE +20 -0
  4. data/README.rdoc +17 -0
  5. data/Rakefile +47 -0
  6. data/VERSION +1 -0
  7. data/examples/a_simple.rb +42 -0
  8. data/examples/autofilters.rb +266 -0
  9. data/examples/bigfile.rb +30 -0
  10. data/examples/copyformat.rb +51 -0
  11. data/examples/data_validate.rb +278 -0
  12. data/examples/date_time.rb +86 -0
  13. data/examples/demo.rb +118 -0
  14. data/examples/diag_border.rb +35 -0
  15. data/examples/formats.rb +489 -0
  16. data/examples/header.rb +136 -0
  17. data/examples/hidden.rb +28 -0
  18. data/examples/hyperlink.rb +42 -0
  19. data/examples/images.rb +52 -0
  20. data/examples/merge1.rb +39 -0
  21. data/examples/merge2.rb +44 -0
  22. data/examples/merge3.rb +65 -0
  23. data/examples/merge4.rb +82 -0
  24. data/examples/merge5.rb +79 -0
  25. data/examples/protection.rb +46 -0
  26. data/examples/regions.rb +52 -0
  27. data/examples/repeat.rb +42 -0
  28. data/examples/stats.rb +75 -0
  29. data/examples/stocks.rb +80 -0
  30. data/examples/tab_colors.rb +30 -0
  31. data/lib/WriteExcel.rb +30 -0
  32. data/lib/WriteExcel/biffwriter.rb +259 -0
  33. data/lib/WriteExcel/chart.rb +217 -0
  34. data/lib/WriteExcel/excelformula.y +138 -0
  35. data/lib/WriteExcel/excelformulaparser.rb +573 -0
  36. data/lib/WriteExcel/format.rb +1108 -0
  37. data/lib/WriteExcel/formula.rb +986 -0
  38. data/lib/WriteExcel/olewriter.rb +322 -0
  39. data/lib/WriteExcel/properties.rb +250 -0
  40. data/lib/WriteExcel/storage_lite.rb +590 -0
  41. data/lib/WriteExcel/workbook.rb +2602 -0
  42. data/lib/WriteExcel/worksheet.rb +6378 -0
  43. data/spec/WriteExcel_spec.rb +7 -0
  44. data/spec/spec.opts +1 -0
  45. data/spec/spec_helper.rb +9 -0
  46. data/test/tc_all.rb +31 -0
  47. data/test/tc_biff.rb +104 -0
  48. data/test/tc_chart.rb +22 -0
  49. data/test/tc_example_match.rb +1280 -0
  50. data/test/tc_format.rb +1264 -0
  51. data/test/tc_formula.rb +63 -0
  52. data/test/tc_ole.rb +110 -0
  53. data/test/tc_storage_lite.rb +102 -0
  54. data/test/tc_workbook.rb +115 -0
  55. data/test/tc_worksheet.rb +115 -0
  56. data/test/test_00_IEEE_double.rb +14 -0
  57. data/test/test_01_add_worksheet.rb +12 -0
  58. data/test/test_02_merge_formats.rb +58 -0
  59. data/test/test_04_dimensions.rb +397 -0
  60. data/test/test_05_rows.rb +182 -0
  61. data/test/test_06_extsst.rb +80 -0
  62. data/test/test_11_date_time.rb +484 -0
  63. data/test/test_12_date_only.rb +506 -0
  64. data/test/test_13_date_seconds.rb +486 -0
  65. data/test/test_21_escher.rb +629 -0
  66. data/test/test_22_mso_drawing_group.rb +739 -0
  67. data/test/test_23_note.rb +78 -0
  68. data/test/test_24_txo.rb +80 -0
  69. data/test/test_26_autofilter.rb +327 -0
  70. data/test/test_27_autofilter.rb +144 -0
  71. data/test/test_28_autofilter.rb +174 -0
  72. data/test/test_29_process_jpg.rb +131 -0
  73. data/test/test_30_validation_dval.rb +82 -0
  74. data/test/test_31_validation_dv_strings.rb +131 -0
  75. data/test/test_32_validation_dv_formula.rb +211 -0
  76. data/test/test_40_property_types.rb +191 -0
  77. data/test/test_41_properties.rb +238 -0
  78. data/test/test_42_set_properties.rb +430 -0
  79. data/test/ts_all.rb +34 -0
  80. metadata +154 -0
@@ -0,0 +1,51 @@
1
+ #!/usr/bin/ruby -w
2
+
3
+ ###############################################################################
4
+ #
5
+ # Example of how to use the format copying method with Spreadsheet::WriteExcel #
6
+ # reverse('©'), March 2001, John McNamara, jmcnamara@cpan.org
7
+ #
8
+ # original written in Perl by John McNamara
9
+ # converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
10
+ #
11
+ require 'rubygems'
12
+ require 'WriteExcel'
13
+
14
+ # Create workbook1
15
+ workbook1 = Spreadsheet::WriteExcel.new("workbook1.xls")
16
+ worksheet1 = workbook1.add_worksheet
17
+ format1a = workbook1.add_format
18
+ format1b = workbook1.add_format
19
+
20
+ # Create workbook2
21
+ workbook2 = Spreadsheet::WriteExcel.new("workbook2.xls")
22
+ worksheet2 = workbook2.add_worksheet
23
+ format2a = workbook2.add_format
24
+ format2b = workbook2.add_format
25
+
26
+ # Create a global format object that isn't tied to a workbook
27
+ global_format = Format.new
28
+
29
+ # Set the formatting
30
+ global_format.set_color('blue')
31
+ global_format.set_bold
32
+ global_format.set_italic
33
+
34
+ # Create another example format
35
+ format1b.set_color('red')
36
+
37
+ # Copy the global format properties to the worksheet formats
38
+ format1a.copy(global_format)
39
+ format2a.copy(global_format)
40
+
41
+ # Copy a format from worksheet1 to worksheet2
42
+ format2b.copy(format1b)
43
+
44
+ # Write some output
45
+ worksheet1.write(0, 0, "Ciao", format1a)
46
+ worksheet1.write(1, 0, "Ciao", format1b)
47
+
48
+ worksheet2.write(0, 0, "Hello", format2a)
49
+ worksheet2.write(1, 0, "Hello", format2b)
50
+ workbook1.close
51
+ workbook2.close
@@ -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
@@ -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