nurettin-jruby-poi 0.8.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. data/.travis.yml +2 -0
  2. data/Gemfile +9 -0
  3. data/Gemfile.lock +29 -0
  4. data/LICENSE +507 -0
  5. data/NOTICE +21 -0
  6. data/README.markdown +87 -0
  7. data/Rakefile +35 -0
  8. data/VERSION +1 -0
  9. data/bin/autospec +16 -0
  10. data/bin/htmldiff +16 -0
  11. data/bin/ldiff +16 -0
  12. data/bin/rdebug +16 -0
  13. data/bin/rspec +16 -0
  14. data/jruby-poi.gemspec +90 -0
  15. data/lib/ooxml-lib/dom4j-1.6.1.jar +0 -0
  16. data/lib/ooxml-lib/geronimo-stax-api_1.0_spec-1.0.jar +0 -0
  17. data/lib/ooxml-lib/xmlbeans-2.3.0.jar +0 -0
  18. data/lib/poi/workbook/area.rb +81 -0
  19. data/lib/poi/workbook/cell.rb +175 -0
  20. data/lib/poi/workbook/named_range.rb +30 -0
  21. data/lib/poi/workbook/row.rb +58 -0
  22. data/lib/poi/workbook/workbook.rb +262 -0
  23. data/lib/poi/workbook/worksheet.rb +78 -0
  24. data/lib/poi/workbook.rb +41 -0
  25. data/lib/poi-3.7-20101029.jar +0 -0
  26. data/lib/poi-examples-3.7-20101029.jar +0 -0
  27. data/lib/poi-ooxml-3.7-20101029.jar +0 -0
  28. data/lib/poi-ooxml-schemas-3.7-20101029.jar +0 -0
  29. data/lib/poi-scratchpad-3.7-20101029.jar +0 -0
  30. data/lib/poi.rb +15 -0
  31. data/spec/data/simple_with_picture.ods +0 -0
  32. data/spec/data/simple_with_picture.xls +0 -0
  33. data/spec/data/spreadsheet.ods +0 -0
  34. data/spec/data/timesheet.xlsx +0 -0
  35. data/spec/data/various_samples.xlsx +0 -0
  36. data/spec/facade_spec.rb +48 -0
  37. data/spec/io_spec.rb +69 -0
  38. data/spec/spec_helper.rb +16 -0
  39. data/spec/support/java/jrubypoi/MockOutputStream.java +24 -0
  40. data/spec/support/java/support.jar +0 -0
  41. data/spec/support/matchers/cell_matcher.rb +17 -0
  42. data/spec/workbook_spec.rb +370 -0
  43. data/spec/writing_spec.rb +146 -0
  44. data/spec_debug.sh +32 -0
  45. metadata +135 -0
@@ -0,0 +1,370 @@
1
+ require 'spec_helper'
2
+
3
+ require 'date'
4
+ require 'stringio'
5
+
6
+ describe POI::Workbook do
7
+ it "should open a workbook and allow access to its worksheets" do
8
+ name = TestDataFile.expand_path("various_samples.xlsx")
9
+ book = POI::Workbook.open(name)
10
+ book.worksheets.size.should == 5
11
+ book.filename.should == name
12
+ end
13
+
14
+ it "should be able to create a Workbook from an IO object" do
15
+ content = StringIO.new(open(TestDataFile.expand_path("various_samples.xlsx"), 'rb'){|f| f.read})
16
+ book = POI::Workbook.open(content)
17
+ book.worksheets.size.should == 5
18
+ book.filename.should =~ /spreadsheet.xlsx$/
19
+ end
20
+
21
+ it "should be able to create a Workbook from a Java input stream" do
22
+ content = java.io.FileInputStream.new(TestDataFile.expand_path("various_samples.xlsx"))
23
+ book = POI::Workbook.open(content)
24
+ book.worksheets.size.should == 5
25
+ book.filename.should =~ /spreadsheet.xlsx$/
26
+ end
27
+
28
+ it "should return a column of cells by reference" do
29
+ name = TestDataFile.expand_path("various_samples.xlsx")
30
+ book = POI::Workbook.open(name)
31
+ book["numbers!$A"].should == book['numbers'].rows.collect{|e| e[0].value}
32
+ book["numbers!A"].should == book['numbers'].rows.collect{|e| e[0].value}
33
+ book["numbers!C"].should == book['numbers'].rows.collect{|e| e[2].value}
34
+ book["numbers!$D:$D"].should == book['numbers'].rows.collect{|e| e[3].value}
35
+ book["numbers!$c:$D"].should == {"C" => book['numbers'].rows.collect{|e| e[2].value}, "D" => book['numbers'].rows.collect{|e| e[3].value}}
36
+ end
37
+
38
+ it "should return cells by reference" do
39
+ name = TestDataFile.expand_path("various_samples.xlsx")
40
+ book = POI::Workbook.open(name)
41
+ book.cell("numbers!A1").value.should == 'NUM'
42
+ book.cell("numbers!A2").to_s.should == '1.0'
43
+ book.cell("numbers!A3").to_s.should == '2.0'
44
+ book.cell("numbers!A4").to_s.should == '3.0'
45
+
46
+ book.cell("numbers!A10").to_s.should == '9.0'
47
+ book.cell("numbers!B10").to_s.should == '81.0'
48
+ book.cell("numbers!C10").to_s.should == '729.0'
49
+ book.cell("numbers!D10").to_s.should == '3.0'
50
+
51
+ book.cell("text & pic!A10").value.should == 'This is an Excel XLSX workbook.'
52
+ book.cell("bools & errors!B3").value.should == true
53
+ book.cell("high refs!AM619").value.should == 'This is some text'
54
+ book.cell("high refs!AO624").value.should == 24.0
55
+ book.cell("high refs!AP631").value.should == 13.0
56
+
57
+ book.cell(%Q{'text & pic'!A10}).value.should == 'This is an Excel XLSX workbook.'
58
+ book.cell(%Q{'bools & errors'!B3}).value.should == true
59
+ book.cell(%Q{'high refs'!AM619}).value.should == 'This is some text'
60
+ book.cell(%Q{'high refs'!AO624}).value.should == 24.0
61
+ book.cell(%Q{'high refs'!AP631}).value.should == 13.0
62
+ end
63
+
64
+ it "should handle named cell ranges" do
65
+ name = TestDataFile.expand_path("various_samples.xlsx")
66
+ book = POI::Workbook.open(name)
67
+
68
+ book.named_ranges.length.should == 3
69
+ book.named_ranges.collect{|e| e.name}.should == %w{four_times_six NAMES nums}
70
+ book.named_ranges.collect{|e| e.sheet.name}.should == ['high refs', 'bools & errors', 'high refs']
71
+ book.named_ranges.collect{|e| e.formula}.should == ["'high refs'!$AO$624", "'bools & errors'!$D$2:$D$11", "'high refs'!$AP$619:$AP$631"]
72
+ book['four_times_six'].should == 24.0
73
+ book['nums'].should == (1..13).collect{|e| e * 1.0}
74
+
75
+ # NAMES is a range of empty cells
76
+ book['NAMES'].should == [nil, nil, nil, nil, nil, nil, nil, nil, nil, nil]
77
+ book.cell('NAMES').each do | cell |
78
+ cell.value.should be_nil
79
+ cell.poi_cell.should_not be_nil
80
+ cell.to_s.should be_empty
81
+ end
82
+ end
83
+
84
+ it "should return an array of cell values by reference" do
85
+ name = TestDataFile.expand_path("various_samples.xlsx")
86
+ book = POI::Workbook.open(name)
87
+ book['dates!A2:A16'].should == (Date.parse('2010-02-28')..Date.parse('2010-03-14')).to_a
88
+ end
89
+
90
+ it "should return cell values by reference" do
91
+ name = TestDataFile.expand_path("various_samples.xlsx")
92
+ book = POI::Workbook.open(name)
93
+
94
+ book['text & pic!A10'].should == 'This is an Excel XLSX workbook.'
95
+ book['bools & errors!B3'].should == true
96
+ book['high refs!AM619'].should == 'This is some text'
97
+ book['high refs!AO624'].should == 24.0
98
+ book['high refs!AP631'].should == 13.0
99
+ end
100
+ end
101
+
102
+ describe POI::Worksheets do
103
+ it "should allow indexing worksheets by ordinal" do
104
+ name = TestDataFile.expand_path("various_samples.xlsx")
105
+ book = POI::Workbook.open(name)
106
+
107
+ book.worksheets[0].name.should == "text & pic"
108
+ book.worksheets[1].name.should == "numbers"
109
+ book.worksheets[2].name.should == "dates"
110
+ book.worksheets[3].name.should == "bools & errors"
111
+ end
112
+
113
+ it "should allow indexing worksheets by name" do
114
+ name = TestDataFile.expand_path("various_samples.xlsx")
115
+ book = POI::Workbook.open(name)
116
+
117
+ book.worksheets["text & pic"].name.should == "text & pic"
118
+ book.worksheets["numbers"].name.should == "numbers"
119
+ book.worksheets["dates"].name.should == "dates"
120
+ end
121
+
122
+ it "should be enumerable" do
123
+ name = TestDataFile.expand_path("various_samples.xlsx")
124
+ book = POI::Workbook.open(name)
125
+ book.worksheets.should be_kind_of Enumerable
126
+
127
+ book.worksheets.each do |sheet|
128
+ sheet.should be_kind_of POI::Worksheet
129
+ end
130
+
131
+ book.worksheets.size.should == 5
132
+ book.worksheets.collect.size.should == 5
133
+ end
134
+
135
+ it "returns cells when passing a cell reference" do
136
+ name = TestDataFile.expand_path("various_samples.xlsx")
137
+ book = POI::Workbook.open(name)
138
+ book['dates']['A2'].to_s.should == '2010-02-28'
139
+ book['dates']['a2'].to_s.should == '2010-02-28'
140
+ book['dates']['B2'].to_s.should == '2010-03-14'
141
+ book['dates']['b2'].to_s.should == '2010-03-14'
142
+ book['dates']['C2'].to_s.should == '2010-03-28'
143
+ book['dates']['c2'].to_s.should == '2010-03-28'
144
+ end
145
+ end
146
+
147
+ describe POI::Rows do
148
+ it "should be enumerable" do
149
+ name = TestDataFile.expand_path("various_samples.xlsx")
150
+ book = POI::Workbook.open(name)
151
+ sheet = book.worksheets["text & pic"]
152
+ sheet.rows.should be_kind_of Enumerable
153
+
154
+ sheet.rows.each do |row|
155
+ row.should be_kind_of POI::Row
156
+ end
157
+
158
+ sheet.rows.size.should == 7
159
+ sheet.rows.collect.size.should == 7
160
+ end
161
+ end
162
+
163
+ describe POI::Cells do
164
+ before :each do
165
+ @name = TestDataFile.expand_path("various_samples.xlsx")
166
+ @book = POI::Workbook.open(@name)
167
+ end
168
+
169
+ def book
170
+ @book
171
+ end
172
+
173
+ def name
174
+ @name
175
+ end
176
+
177
+ it "should be enumerable" do
178
+ sheet = book.worksheets["text & pic"]
179
+ rows = sheet.rows
180
+ cells = rows[0].cells
181
+
182
+ cells.should be_kind_of Enumerable
183
+ cells.size.should == 1
184
+ cells.collect.size.should == 1
185
+ end
186
+ end
187
+
188
+ describe POI::Cell do
189
+ before :each do
190
+ @name = TestDataFile.expand_path("various_samples.xlsx")
191
+ @book = POI::Workbook.open(@name)
192
+ end
193
+
194
+ def book
195
+ @book
196
+ end
197
+
198
+ def name
199
+ @name
200
+ end
201
+
202
+ it "should provide dates for date cells" do
203
+ sheet = book.worksheets["dates"]
204
+ rows = sheet.rows
205
+
206
+ dates_by_column = [
207
+ (Date.parse('2010-02-28')..Date.parse('2010-03-14')),
208
+ (Date.parse('2010-03-14')..Date.parse('2010-03-28')),
209
+ (Date.parse('2010-03-28')..Date.parse('2010-04-11'))]
210
+ (0..2).each do |col|
211
+ dates_by_column[col].each_with_index do |date, index|
212
+ row = index + 1
213
+ rows[row][col].value.should equal_at_cell(date, row, col)
214
+ end
215
+ end
216
+ end
217
+
218
+ it "should provide numbers for numeric cells" do
219
+ sheet = book.worksheets["numbers"]
220
+ rows = sheet.rows
221
+
222
+ (1..15).each do |number|
223
+ row = number
224
+ rows[row][0].value.should equal_at_cell(number, row, 0)
225
+ rows[row][1].value.should equal_at_cell(number ** 2, row, 1)
226
+ rows[row][2].value.should equal_at_cell(number ** 3, row, 2)
227
+ rows[row][3].value.should equal_at_cell(Math.sqrt(number), row, 3)
228
+ end
229
+
230
+ rows[9][0].to_s.should == '9.0'
231
+ rows[9][1].to_s.should == '81.0'
232
+ rows[9][2].to_s.should == '729.0'
233
+ rows[9][3].to_s.should == '3.0'
234
+ end
235
+
236
+ it "should handle array access from the workbook down to cells" do
237
+ book[1][9][0].to_s.should == '9.0'
238
+ book[1][9][1].to_s.should == '81.0'
239
+ book[1][9][2].to_s.should == '729.0'
240
+ book[1][9][3].to_s.should == '3.0'
241
+
242
+ book["numbers"][9][0].to_s.should == '9.0'
243
+ book["numbers"][9][1].to_s.should == '81.0'
244
+ book["numbers"][9][2].to_s.should == '729.0'
245
+ book["numbers"][9][3].to_s.should == '3.0'
246
+ end
247
+
248
+ it "should provide error text for error cells" do
249
+ sheet = book.worksheets["bools & errors"]
250
+ rows = sheet.rows
251
+
252
+ rows[6][0].value.should == 0.0 #'~CIRCULAR~REF~'
253
+ rows[6][0].error_value.should be_nil
254
+
255
+ rows[7][0].value.should be_nil
256
+ rows[7][0].error_value.should == '#DIV/0!'
257
+
258
+ rows[8][0].value.should be_nil
259
+ rows[8][0].error_value.should == '#N/A'
260
+
261
+ rows[9][0].value.should be_nil
262
+ rows[9][0].error_value.should == '#NAME?'
263
+
264
+ rows[10][0].value.should be_nil
265
+ rows[10][0].error_value.should == '#NULL!'
266
+
267
+ rows[11][0].value.should be_nil
268
+ rows[11][0].error_value.should == '#NUM!'
269
+
270
+ rows[12][0].value.should be_nil
271
+ rows[12][0].error_value.should == '#REF!'
272
+
273
+ rows[13][0].value.should be_nil
274
+ rows[13][0].error_value.should == '#VALUE!'
275
+
276
+ lambda{ rows[14][0].value }.should_not raise_error(Java::java.lang.RuntimeException)
277
+
278
+ rows[6][0].to_s.should == '0.0' #'~CIRCULAR~REF~'
279
+ rows[7][0].to_s.should == '' #'#DIV/0!'
280
+ rows[8][0].to_s.should == '' #'#N/A'
281
+ rows[9][0].to_s.should == '' #'#NAME?'
282
+ rows[10][0].to_s.should == '' #'#NULL!'
283
+ rows[11][0].to_s.should == '' #'#NUM!'
284
+ rows[12][0].to_s.should == '' #'#REF!'
285
+ rows[13][0].to_s.should == '' #'#VALUE!'
286
+ rows[14][0].to_s.should == ''
287
+ end
288
+
289
+ it "should provide booleans for boolean cells" do
290
+ sheet = book.worksheets["bools & errors"]
291
+ rows = sheet.rows
292
+ rows[1][0].value.should == false
293
+ rows[1][0].to_s.should == 'false'
294
+
295
+ rows[1][1].value.should == false
296
+ rows[1][1].to_s.should == 'false'
297
+
298
+ rows[2][0].value.should == true
299
+ rows[2][0].to_s.should == 'true'
300
+
301
+ rows[2][1].value.should == true
302
+ rows[2][1].to_s.should == 'true'
303
+ end
304
+
305
+ it "should provide the cell value as a string" do
306
+ sheet = book.worksheets["text & pic"]
307
+ rows = sheet.rows
308
+
309
+ rows[0][0].value.should == "This"
310
+ rows[1][0].value.should == "is"
311
+ rows[2][0].value.should == "an"
312
+ rows[3][0].value.should == "Excel"
313
+ rows[4][0].value.should == "XLSX"
314
+ rows[5][0].value.should == "workbook"
315
+ rows[9][0].value.should == 'This is an Excel XLSX workbook.'
316
+
317
+
318
+ rows[0][0].to_s.should == "This"
319
+ rows[1][0].to_s.should == "is"
320
+ rows[2][0].to_s.should == "an"
321
+ rows[3][0].to_s.should == "Excel"
322
+ rows[4][0].to_s.should == "XLSX"
323
+ rows[5][0].to_s.should == "workbook"
324
+ rows[9][0].to_s.should == 'This is an Excel XLSX workbook.'
325
+ end
326
+
327
+ it "should provide formulas instead of string-ified values" do
328
+ sheet = book.worksheets["numbers"]
329
+ rows = sheet.rows
330
+
331
+ (1..15).each do |number|
332
+ row = number
333
+ rows[row][0].to_s(false).should == "#{number}.0"
334
+ rows[row][1].to_s(false).should == "A#{row + 1}*A#{row + 1}"
335
+ rows[row][2].to_s(false).should == "B#{row + 1}*A#{row + 1}"
336
+ rows[row][3].to_s(false).should == "SQRT(A#{row + 1})"
337
+ end
338
+
339
+ sheet = book.worksheets["bools & errors"]
340
+ rows = sheet.rows
341
+ rows[1][0].to_s(false).should == '1=2'
342
+ rows[1][1].to_s(false).should == 'FALSE'
343
+ rows[2][0].to_s(false).should == '1=1'
344
+ rows[2][1].to_s(false).should == 'TRUE'
345
+ rows[14][0].to_s(false).should == 'foobar(1)'
346
+
347
+ sheet = book.worksheets["text & pic"]
348
+ sheet.rows[9][0].to_s(false).should == 'CONCATENATE(A1," ", A2," ", A3," ", A4," ", A5," ", A6,".")'
349
+ end
350
+
351
+ it "should handle getting values out of 'non-existent' cells" do
352
+ sheet = book.worksheets["bools & errors"]
353
+ sheet.rows[14][2].value.should be_nil
354
+ end
355
+
356
+ it "should notify the workbook that I have been updated" do
357
+ book['dates!A10'].to_s.should == '2010-03-08'
358
+ book['dates!A16'].to_s.should == '2010-03-14'
359
+ book['dates!B2'].to_s.should == '2010-03-14'
360
+
361
+ cell = book.cell('dates!B2')
362
+ cell.formula.should == 'A16'
363
+
364
+ cell.formula = 'A10 + 1'
365
+ book.cell('dates!B2').poi_cell.should === cell.poi_cell
366
+ book.cell('dates!B2').formula.should == 'A10 + 1'
367
+
368
+ book['dates!B2'].to_s.should == '2010-03-09'
369
+ end
370
+ end
@@ -0,0 +1,146 @@
1
+ require 'spec_helper'
2
+
3
+ require 'date'
4
+ require 'stringio'
5
+
6
+ describe "writing Workbooks" do
7
+ it "should create a new empty workbook" do
8
+ name = 'new-workbook.xlsx'
9
+ book = POI::Workbook.create(name)
10
+ book.should_not be_nil
11
+ end
12
+
13
+ it "should create a new workbook and write something to it" do
14
+ name = "spec/data/timesheet-#{Time.now.strftime('%Y%m%d%H%M%S%s')}.xlsx"
15
+ create_timesheet_spreadsheet(name)
16
+ book = POI::Workbook.open(name)
17
+ book.worksheets.size.should == 1
18
+ book.worksheets[0].name.should == 'Timesheet'
19
+ book.filename.should == name
20
+ book['Timesheet!A3'].should == 'Yegor Kozlov'
21
+ book.cell('Timesheet!J13').formula_value.should == 'SUM(J3:J12)'
22
+ FileUtils.rm_f name
23
+ end
24
+
25
+ def create_timesheet_spreadsheet name='spec/data/timesheet.xlsx'
26
+ titles = ["Person", "ID", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun", "Total\nHrs", "Overtime\nHrs", "Regular\nHrs"]
27
+ sample_data = [
28
+ ["Yegor Kozlov", "YK", 5.0, 8.0, 10.0, 5.0, 5.0, 7.0, 6.0],
29
+ ["Gisella Bronzetti", "GB", 4.0, 3.0, 1.0, 3.5, nil, nil, 4.0]
30
+ ]
31
+
32
+ book = POI::Workbook.create(name)
33
+ title_style = book.create_style :font_height_in_points => 18, :boldweight => :boldweight_bold,
34
+ :alignment => :align_center, :vertical_alignment => :vertical_center
35
+ header_style = book.create_style :font_height_in_points => 11, :color => :white, :fill_foreground_color => :grey_50_percent,
36
+ :fill_pattern => :solid_foreground, :alignment => :align_center, :vertical_alignment => :vertical_center
37
+ cell_style = book.create_style :alignment => :align_center, :border_bottom => :border_thin, :border_top => :border_thin,
38
+ :border_left => :border_thin, :border_right => :border_thin, :bottom_border_color => :black,
39
+ :right_border_color => :black, :left_border_color => :black, :top_border_color => :black
40
+ form1_style = book.create_style :data_format => '0.00', :fill_pattern => :solid_foreground, :fill_foreground_color => :grey_25_percent,
41
+ :alignment => :align_center, :vertical_alignment => :vertical_center
42
+ form2_style = book.create_style :data_format => '0.00', :fill_pattern => :solid_foreground, :fill_foreground_color => :grey_40_percent,
43
+ :alignment => :align_center, :vertical_alignment => :vertical_center
44
+
45
+ sheet = book.create_sheet 'Timesheet'
46
+ print_setup = sheet.print_setup
47
+ print_setup.landscape = true
48
+ sheet.fit_to_page = true
49
+ sheet.horizontally_center = true
50
+
51
+ title_row = sheet.rows[0]
52
+ title_row.height_in_points = 45
53
+ title_cell = title_row.cells[0]
54
+ title_cell.value = 'Weekly Timesheet'
55
+ title_cell.style = title_style
56
+ sheet.add_merged_region org.apache.poi.ss.util.CellRangeAddress.valueOf("$A$1:$L$1")
57
+
58
+ header_row = sheet[1]
59
+ header_row.height_in_points = 40
60
+ titles.each_with_index do | title, index |
61
+ header_cell = header_row[index]
62
+ header_cell.value = title
63
+ header_cell.style = header_style
64
+ end
65
+
66
+ row_num = 2
67
+ 10.times do
68
+ row = sheet[row_num]
69
+ row_num += 1
70
+ titles.each_with_index do | title, index |
71
+ cell = row[index]
72
+ if index == 9
73
+ cell.formula = "SUM(C#{row_num}:I#{row_num})"
74
+ cell.style = form1_style
75
+ elsif index == 11
76
+ cell.formula = "J#{row_num} - K#{row_num}"
77
+ cell.style = form1_style
78
+ else
79
+ cell.style = cell_style
80
+ end
81
+ end
82
+ end
83
+
84
+ # row with totals below
85
+ sum_row = sheet[row_num]
86
+ row_num += 1
87
+ sum_row.height_in_points = 35
88
+ cell = sum_row[0]
89
+ cell.style = form1_style
90
+ cell = sum_row[1]
91
+ cell.style = form1_style
92
+ cell.value = 'Total Hrs:'
93
+ (2...12).each do | cell_index |
94
+ cell = sum_row[cell_index]
95
+ column = (?A + cell_index).chr
96
+ cell.formula = "SUM(#{column}3:#{column}12)"
97
+ if cell_index > 9
98
+ cell.style = form2_style
99
+ else
100
+ cell.style = form1_style
101
+ end
102
+ end
103
+ row_num += 1
104
+ sum_row = sheet[row_num]
105
+ row_num += 1
106
+ sum_row.height_in_points = 25
107
+ cell = sum_row[0]
108
+ cell.value = 'Total Regular Hours'
109
+ cell.style = form1_style
110
+ cell = sum_row[1]
111
+ cell.formula = 'L13'
112
+ cell.style = form2_style
113
+ sum_row = sheet[row_num]
114
+ row_num += 1
115
+ cell = sum_row[0]
116
+ cell.value = 'Total Overtime Hours'
117
+ cell.style = form1_style
118
+ cell = sum_row[1]
119
+ cell.formula = 'K13'
120
+ cell.style = form2_style
121
+
122
+ # set sample data
123
+ sample_data.each_with_index do |each, row_index|
124
+ row = sheet[2 + row_index]
125
+ each.each_with_index do | data, cell_index |
126
+ data = sample_data[row_index][cell_index]
127
+ next unless data
128
+ if data.kind_of? String
129
+ row[cell_index].value = data #.to_java(:string)
130
+ else
131
+ row[cell_index].value = data #.to_java(:double)
132
+ end
133
+ end
134
+ end
135
+
136
+ # finally set column widths, the width is measured in units of 1/256th of a character width
137
+ sheet.set_column_width 0, 30*256 # 30 characters wide
138
+ (2..9).to_a.each do | column |
139
+ sheet.set_column_width column, 6*256 # 6 characters wide
140
+ end
141
+ sheet.set_column_width 10, 10*256 # 10 characters wide
142
+
143
+ book.save
144
+ File.exist?(name).should == true
145
+ end
146
+ end
data/spec_debug.sh ADDED
@@ -0,0 +1,32 @@
1
+ #!/bin/sh
2
+ #set -x
3
+ RUBY_DIR=$(dirname $(which ruby))/..
4
+ if [[ ${RUBY_DIR} == *1.6.* ]]
5
+ then
6
+ RUBYGEMS_DIR=${RUBY_DIR}/lib/ruby/gems/jruby/gems
7
+ else
8
+ RUBYGEMS_DIR=${RUBY_DIR}/lib/ruby/gems/1.8/gems
9
+ fi
10
+
11
+ GEM_COLUMNIZE=$(ls -1d $RUBYGEMS_DIR/columnize*/lib | head -1 | /usr/bin/ruby -e 'print File.expand_path($stdin.read)')
12
+ GEM_RUBY_DEBUG_BASE=$(ls -1d $RUBYGEMS_DIR/ruby-debug-base-*/lib | head -1 | /usr/bin/ruby -e 'print File.expand_path($stdin.read)')
13
+ GEM_RUBY_DEBUG_CLI=$(ls -1d $RUBYGEMS_DIR/ruby-debug-*/cli | head -1 | /usr/bin/ruby -e 'print File.expand_path($stdin.read)')
14
+ GEM_SOURCES=$(ls -1d $RUBYGEMS_DIR/sources-*/lib | head -1 | /usr/bin/ruby -e 'print File.expand_path($stdin.read)')
15
+
16
+ echo "RUBYGEMS_DIR: ${RUBYGEMS_DIR}"
17
+ echo "GEM_SOURCES: ${GEM_SOURCES}"
18
+ echo "GEM_COLUMNIZE: ${GEM_COLUMNIZE}"
19
+ echo "GEM_RUBY_DEBUG_CLI: ${GEM_RUBY_DEBUG_CLI}"
20
+ echo "GEM_RUBY_DEBUG_BASE: ${GEM_RUBY_DEBUG_BASE}"
21
+
22
+ runner="ruby --client \
23
+ -I${GEM_COLUMNIZE} \
24
+ -I${GEM_RUBY_DEBUG_BASE} \
25
+ -I${GEM_RUBY_DEBUG_CLI} \
26
+ -I${GEM_SOURCES} \
27
+ -rubygems -S"
28
+
29
+ cmd="bundle exec rdebug rspec -c $*"
30
+ #cmd="irb"
31
+
32
+ $runner $cmd
metadata ADDED
@@ -0,0 +1,135 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nurettin-jruby-poi
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.8.2
6
+ platform: ruby
7
+ authors:
8
+ - Scott Deming
9
+ - Jason Rogers
10
+ - Nurettin Onur TUĞCU
11
+ autorequire:
12
+ bindir: bin
13
+ cert_chain: []
14
+ date: 2012-04-19 00:00:00.000000000Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: rspec
18
+ version_requirements: &2060 !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: 2.5.0
23
+ none: false
24
+ requirement: *2060
25
+ prerelease: false
26
+ type: :development
27
+ - !ruby/object:Gem::Dependency
28
+ name: jeweler
29
+ version_requirements: &2078 !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: 1.6.0
34
+ none: false
35
+ requirement: *2078
36
+ prerelease: false
37
+ type: :development
38
+ - !ruby/object:Gem::Dependency
39
+ name: rcov
40
+ version_requirements: &2094 !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ none: false
46
+ requirement: *2094
47
+ prerelease: false
48
+ type: :development
49
+ description: A rubyesque library for manipulating spreadsheets and other document types for jruby, using Apache POI.
50
+ email:
51
+ - sdeming@makefile.com
52
+ - jacaetevha@gmail.com
53
+ - onur.tugcu@gmail.com
54
+ executables:
55
+ - autospec
56
+ - htmldiff
57
+ - ldiff
58
+ - rdebug
59
+ - rspec
60
+ extensions: []
61
+ extra_rdoc_files:
62
+ - LICENSE
63
+ - README.markdown
64
+ files:
65
+ - .travis.yml
66
+ - Gemfile
67
+ - Gemfile.lock
68
+ - LICENSE
69
+ - NOTICE
70
+ - README.markdown
71
+ - Rakefile
72
+ - VERSION
73
+ - bin/autospec
74
+ - bin/htmldiff
75
+ - bin/ldiff
76
+ - bin/rdebug
77
+ - bin/rspec
78
+ - jruby-poi.gemspec
79
+ - lib/ooxml-lib/dom4j-1.6.1.jar
80
+ - lib/ooxml-lib/geronimo-stax-api_1.0_spec-1.0.jar
81
+ - lib/ooxml-lib/xmlbeans-2.3.0.jar
82
+ - lib/poi-3.7-20101029.jar
83
+ - lib/poi-examples-3.7-20101029.jar
84
+ - lib/poi-ooxml-3.7-20101029.jar
85
+ - lib/poi-ooxml-schemas-3.7-20101029.jar
86
+ - lib/poi-scratchpad-3.7-20101029.jar
87
+ - lib/poi.rb
88
+ - lib/poi/workbook.rb
89
+ - lib/poi/workbook/area.rb
90
+ - lib/poi/workbook/cell.rb
91
+ - lib/poi/workbook/named_range.rb
92
+ - lib/poi/workbook/row.rb
93
+ - lib/poi/workbook/workbook.rb
94
+ - lib/poi/workbook/worksheet.rb
95
+ - spec/data/simple_with_picture.ods
96
+ - spec/data/simple_with_picture.xls
97
+ - spec/data/spreadsheet.ods
98
+ - spec/data/timesheet.xlsx
99
+ - spec/data/various_samples.xlsx
100
+ - spec/facade_spec.rb
101
+ - spec/io_spec.rb
102
+ - spec/spec_helper.rb
103
+ - spec/support/java/jrubypoi/MockOutputStream.java
104
+ - spec/support/java/support.jar
105
+ - spec/support/matchers/cell_matcher.rb
106
+ - spec/workbook_spec.rb
107
+ - spec/writing_spec.rb
108
+ - spec_debug.sh
109
+ homepage: http://github.com/nurettin/jruby-poi
110
+ licenses:
111
+ - Apache
112
+ post_install_message:
113
+ rdoc_options: []
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ! '>='
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ none: false
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ! '>='
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ none: false
128
+ requirements: []
129
+ rubyforge_project:
130
+ rubygems_version: 1.8.15
131
+ signing_key:
132
+ specification_version: 3
133
+ summary: Apache POI class library for jruby
134
+ test_files: []
135
+ ...