WriteExcel 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
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,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Eliot Dahood
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,17 @@
1
+ = WriteExcel
2
+
3
+ Description goes here.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
13
+ * Send me a pull request. Bonus points for topic branches.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2010 Eliot Dahood. See LICENSE for details.
@@ -0,0 +1,47 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "WriteExcel"
8
+ gem.summary = %Q{Write to a cross-platform Excel binary file With Ruby 1.9.1}
9
+ gem.description = %Q{An Easy, Fast way to Make Excel 2003 Compatible Files from Ruby. Write to a cross-platform Excel binary file With Ruby 1.9.1}
10
+ gem.email = "eliot.dahood@zoho.com"
11
+ gem.homepage = "http://github.com/edahood/WriteExcel"
12
+ gem.authors = ["Eliot Dahood"]
13
+ gem.add_development_dependency "rspec", ">= 1.2.9"
14
+ gem.has_rdoc = false
15
+ gem.add_dependency('ruby-ole', '>=1.2.8.2')
16
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
17
+ end
18
+ Jeweler::GemcutterTasks.new
19
+ rescue LoadError
20
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
21
+ end
22
+
23
+ require 'spec/rake/spectask'
24
+ Spec::Rake::SpecTask.new(:spec) do |spec|
25
+ spec.libs << 'lib' << 'spec'
26
+ spec.spec_files = FileList['spec/**/*_spec.rb']
27
+ end
28
+
29
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
30
+ spec.libs << 'lib' << 'spec'
31
+ spec.pattern = 'spec/**/*_spec.rb'
32
+ spec.rcov = true
33
+ end
34
+
35
+ task :spec => :check_dependencies
36
+
37
+ task :default => :spec
38
+
39
+ require 'rake/rdoctask'
40
+ Rake::RDocTask.new do |rdoc|
41
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
42
+
43
+ rdoc.rdoc_dir = 'rdoc'
44
+ rdoc.title = "WriteExcel #{version}"
45
+ rdoc.rdoc_files.include('README*')
46
+ rdoc.rdoc_files.include('lib/**/*.rb')
47
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.2.0
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/ruby -w
2
+ #
3
+ # Example of how to use the WriteExcel module to write text and numbers
4
+ # to an Excel binary file.
5
+ #
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 a new workbook called simple.xls and add a worksheet
15
+ workbook = Spreadsheet::WriteExcel.new('a_simple.xls');
16
+ worksheet = workbook.add_worksheet
17
+
18
+ # The general syntax is write(row, column, token). Note that row and
19
+ # column are zero indexed
20
+ #
21
+
22
+ # Write some text
23
+ worksheet.write(0, 0, "Hi Excel!")
24
+
25
+
26
+ # Write some numbers
27
+ worksheet.write(2, 0, 3) # Writes 3
28
+ worksheet.write(3, 0, 3.00000) # Writes 3
29
+ worksheet.write(4, 0, 3.00001) # Writes 3.00001
30
+ worksheet.write(5, 0, 3.14159) # TeX revision no.?
31
+
32
+
33
+ # Write some formulas
34
+ worksheet.write(7, 0, '=A3 + A6')
35
+ worksheet.write(8, 0, '=IF(A5>3,"Yes", "No")')
36
+
37
+
38
+ # Write a hyperlink
39
+ worksheet.write(10, 0, 'http://www.perl.com/')
40
+
41
+ # File save
42
+ workbook.close
@@ -0,0 +1,266 @@
1
+ #!/usr/bin/ruby -w
2
+
3
+ #######################################################################
4
+ #
5
+ # Example of how to create autofilters with Spreadsheet::WriteExcel.
6
+ #
7
+ # reverse('©'), September 2007, 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
+ def get_data
16
+ [
17
+ ['East', 'Apple', 9000, 'July'],
18
+ ['East', 'Apple', 5000, 'July'],
19
+ ['South', 'Orange', 9000, 'September'],
20
+ ['North', 'Apple', 2000, 'November'],
21
+ ['West', 'Apple', 9000, 'November'],
22
+ ['South', 'Pear', 7000, 'October'],
23
+ ['North', 'Pear', 9000, 'August'],
24
+ ['West', 'Orange', 1000, 'December'],
25
+ ['West', 'Grape', 1000, 'November'],
26
+ ['South', 'Pear', 10000, 'April'],
27
+ ['West', 'Grape', 6000, 'January'],
28
+ ['South', 'Orange', 3000, 'May'],
29
+ ['North', 'Apple', 3000, 'December'],
30
+ ['South', 'Apple', 7000, 'February'],
31
+ ['West', 'Grape', 1000, 'December'],
32
+ ['East', 'Grape', 8000, 'February'],
33
+ ['South', 'Grape', 10000, 'June'],
34
+ ['West', 'Pear', 7000, 'December'],
35
+ ['South', 'Apple', 2000, 'October'],
36
+ ['East', 'Grape', 7000, 'December'],
37
+ ['North', 'Grape', 6000, 'April'],
38
+ ['East', 'Pear', 8000, 'February'],
39
+ ['North', 'Apple', 7000, 'August'],
40
+ ['North', 'Orange', 7000, 'July'],
41
+ ['North', 'Apple', 6000, 'June'],
42
+ ['South', 'Grape', 8000, 'September'],
43
+ ['West', 'Apple', 3000, 'October'],
44
+ ['South', 'Orange', 10000, 'November'],
45
+ ['West', 'Grape', 4000, 'July'],
46
+ ['North', 'Orange', 5000, 'August'],
47
+ ['East', 'Orange', 1000, 'November'],
48
+ ['East', 'Orange', 4000, 'October'],
49
+ ['North', 'Grape', 5000, 'August'],
50
+ ['East', 'Apple', 1000, 'December'],
51
+ ['South', 'Apple', 10000, 'March'],
52
+ ['East', 'Grape', 7000, 'October'],
53
+ ['West', 'Grape', 1000, 'September'],
54
+ ['East', 'Grape', 10000, 'October'],
55
+ ['South', 'Orange', 8000, 'March'],
56
+ ['North', 'Apple', 4000, 'July'],
57
+ ['South', 'Orange', 5000, 'July'],
58
+ ['West', 'Apple', 4000, 'June'],
59
+ ['East', 'Apple', 5000, 'April'],
60
+ ['North', 'Pear', 3000, 'August'],
61
+ ['East', 'Grape', 9000, 'November'],
62
+ ['North', 'Orange', 8000, 'October'],
63
+ ['East', 'Apple', 10000, 'June'],
64
+ ['South', 'Pear', 1000, 'December'],
65
+ ['North', 'Grape', 10000, 'July'],
66
+ ['East', 'Grape', 6000, 'February'],
67
+ ]
68
+ end
69
+
70
+ #######################################################################
71
+ #
72
+ # Main
73
+ #
74
+
75
+ xlsfile = 'autofilters.xls'
76
+
77
+ workbook = Spreadsheet::WriteExcel.new(xlsfile)
78
+ bp=1
79
+
80
+ worksheet1 = workbook.add_worksheet
81
+ worksheet2 = workbook.add_worksheet
82
+ worksheet3 = workbook.add_worksheet
83
+ worksheet4 = workbook.add_worksheet
84
+ worksheet5 = workbook.add_worksheet
85
+ worksheet6 = workbook.add_worksheet
86
+
87
+ bold = workbook.add_format(:bold => 1)
88
+
89
+ # Extract the data embedded at the end of this file.
90
+ headings = %w(Region Item Volume Month)
91
+ data = get_data
92
+
93
+ # Set up several sheets with the same data.
94
+ workbook.sheets.each do |worksheet|
95
+ worksheet.set_column('A:D', 12)
96
+ worksheet.set_row(0, 20, bold)
97
+ worksheet.write('A1', headings)
98
+ end
99
+
100
+ ###############################################################################
101
+ #
102
+ # Example 1. Autofilter without conditions.
103
+ #
104
+
105
+ worksheet1.autofilter('A1:D51')
106
+ worksheet1.write('A2', [data])
107
+
108
+ ###############################################################################
109
+ #
110
+ #
111
+ # Example 2. Autofilter with a filter condition in the first column.
112
+ #
113
+
114
+ # The range in this example is the same as above but in row-column notation.
115
+ worksheet2.autofilter(0, 0, 50, 3)
116
+
117
+ # The placeholder "Region" in the filter is ignored and can be any string
118
+ # that adds clarity to the expression.
119
+ #
120
+ worksheet2.filter_column(0, 'Region eq East')
121
+
122
+ #
123
+ # Hide the rows that don't match the filter criteria.
124
+ #
125
+ row = 1
126
+
127
+ data.each do |row_data|
128
+ region = row_data[0]
129
+
130
+ if region == 'East'
131
+ # Row is visible.
132
+ else
133
+ # Hide row.
134
+ worksheet2.set_row(row, nil, nil, 1)
135
+ end
136
+
137
+ worksheet2.write(row, 0, row_data)
138
+ row += 1
139
+ end
140
+
141
+
142
+ ###############################################################################
143
+ #
144
+ #
145
+ # Example 3. Autofilter with a dual filter condition in one of the columns.
146
+ #
147
+
148
+ worksheet3.autofilter('A1:D51')
149
+
150
+ worksheet3.filter_column('A', 'x eq East or x eq South')
151
+
152
+ #
153
+ # Hide the rows that don't match the filter criteria.
154
+ #
155
+ row = 1
156
+
157
+ data.each do |row_data|
158
+ region = row_data[0]
159
+
160
+ if region == 'East' || region == 'South'
161
+ # Row is visible.
162
+ else
163
+ # Hide row.
164
+ worksheet3.set_row(row, nil, nil, 1)
165
+ end
166
+
167
+ worksheet3.write(row, 0, row_data)
168
+ row += 1
169
+ end
170
+
171
+
172
+ ###############################################################################
173
+ #
174
+ #
175
+ # Example 4. Autofilter with filter conditions in two columns.
176
+ #
177
+
178
+ worksheet4.autofilter('A1:D51')
179
+
180
+ worksheet4.filter_column('A', 'x eq East')
181
+ worksheet4.filter_column('C', 'x > 3000 and x < 8000' )
182
+
183
+ #
184
+ # Hide the rows that don't match the filter criteria.
185
+ #
186
+ row = 1
187
+
188
+ data.each do |row_data|
189
+ region = row_data[0]
190
+ volume = row_data[2]
191
+
192
+ if region == 'East' && volume > 3000 && volume < 8000
193
+ # Row is visible.
194
+ else
195
+ # Hide row.
196
+ worksheet4.set_row(row, nil, nil, 1)
197
+ end
198
+
199
+ worksheet4.write(row, 0, row_data)
200
+ row += 1
201
+ end
202
+
203
+
204
+ ###############################################################################
205
+ #
206
+ #
207
+ # Example 5. Autofilter with filter for blanks.
208
+ #
209
+
210
+ # Create a blank cell in our test data.
211
+ data[5][0] = ''
212
+
213
+ worksheet5.autofilter('A1:D51')
214
+ worksheet5.filter_column('A', 'x == Blanks')
215
+
216
+ #
217
+ # Hide the rows that don't match the filter criteria.
218
+ #
219
+ row = 1
220
+
221
+ data.each do |row_data|
222
+ region = row_data[0]
223
+
224
+ if region == ''
225
+ # Row is visible.
226
+ else
227
+ # Hide row.
228
+ worksheet5.set_row(row, nil, nil, 1)
229
+ end
230
+
231
+ worksheet5.write(row, 0, row_data)
232
+ row += 1
233
+ end
234
+
235
+
236
+ ###############################################################################
237
+ #
238
+ #
239
+ # Example 6. Autofilter with filter for non-blanks.
240
+ #
241
+
242
+ worksheet6.autofilter('A1:D51')
243
+ worksheet6.filter_column('A', 'x == NonBlanks')
244
+
245
+ #
246
+ # Hide the rows that don't match the filter criteria.
247
+ #
248
+ row = 1
249
+
250
+ data.each do |row_data|
251
+ region = row_data[0]
252
+
253
+ if region != ''
254
+ # Row is visible.
255
+ else
256
+ # Hide row.
257
+ worksheet6.set_row(row, nil, nil, 1)
258
+ end
259
+
260
+ worksheet6.write(row, 0, row_data)
261
+ row += 1
262
+ end
263
+
264
+ workbook.close
265
+
266
+
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/ruby -w
2
+
3
+ ###############################################################################
4
+ #
5
+ # Example of creating a Spreadsheet::WriteExcel that is larger than the
6
+ # default 7MB limit.
7
+ #
8
+ # It is exactly that same as any other Spreadsheet::WriteExcel program except
9
+ # that is requires that the OLE::Storage module is installed.
10
+ #
11
+ # reverse('©'), Jan 2007, John McNamara, jmcnamara@cpan.org
12
+ #
13
+ # original written in Perl by John McNamara
14
+ # converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
15
+ #
16
+ require 'rubygems'
17
+ require 'WriteExcel'
18
+
19
+ workbook = Spreadsheet::WriteExcel.new('bigfile.xls')
20
+ worksheet = workbook.add_worksheet
21
+
22
+ worksheet.set_column(0, 50, 18)
23
+
24
+ 0.upto(50) do |col|
25
+ 0.upto(6000) do |row|
26
+ worksheet.write(row, col, "Row: #{row} Col: #{col}")
27
+ end
28
+ end
29
+
30
+ workbook.close