jruby-poi 0.6.1 → 0.7.1
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.
- data/Gemfile +6 -0
- data/Gemfile.lock +25 -0
- data/README.markdown +16 -1
- data/Rakefile +22 -0
- data/VERSION +1 -1
- data/bin/autospec +16 -0
- data/bin/htmldiff +16 -0
- data/bin/ldiff +16 -0
- data/bin/rdebug +16 -0
- data/bin/rspec +16 -0
- data/jruby-poi.gemspec +55 -43
- data/lib/poi/workbook.rb +16 -0
- data/lib/poi/workbook/area.rb +60 -3
- data/lib/poi/workbook/cell.rb +83 -34
- data/lib/poi/workbook/named_range.rb +4 -4
- data/lib/poi/workbook/row.rb +20 -10
- data/lib/poi/workbook/workbook.rb +165 -19
- data/lib/poi/workbook/worksheet.rb +33 -15
- data/spec_debug.sh +13 -2
- data/specs/data/simple_with_picture.ods +0 -0
- data/specs/data/various_samples.xlsx +0 -0
- data/specs/spec_helper.rb +2 -1
- data/specs/support/matchers/cell_matcher.rb +1 -1
- data/specs/workbook_spec.rb +47 -10
- data/specs/writing_spec.rb +145 -0
- metadata +92 -66
- data/.gitignore +0 -9
Binary file
|
Binary file
|
data/specs/spec_helper.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'rspec'
|
1
2
|
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'poi'))
|
2
3
|
Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each {|f| require f}
|
3
4
|
require File.join(File.dirname(__FILE__), "support", "java", "support.jar")
|
@@ -8,5 +9,5 @@ class TestDataFile
|
|
8
9
|
end
|
9
10
|
end
|
10
11
|
|
11
|
-
|
12
|
+
RSpec.configure do |config|
|
12
13
|
end
|
data/specs/workbook_spec.rb
CHANGED
@@ -24,10 +24,19 @@ describe POI::Workbook do
|
|
24
24
|
book.filename.should =~ /spreadsheet.xlsx$/
|
25
25
|
end
|
26
26
|
|
27
|
+
it "should return a column of cells by reference" do
|
28
|
+
name = TestDataFile.expand_path("various_samples.xlsx")
|
29
|
+
book = POI::Workbook.open(name)
|
30
|
+
book["numbers!$A"].should == book['numbers'].rows.collect{|e| e[0].value}
|
31
|
+
book["numbers!A"].should == book['numbers'].rows.collect{|e| e[0].value}
|
32
|
+
book["numbers!C"].should == book['numbers'].rows.collect{|e| e[2].value}
|
33
|
+
book["numbers!$D:$D"].should == book['numbers'].rows.collect{|e| e[3].value}
|
34
|
+
book["numbers!$c:$D"].should == {"C" => book['numbers'].rows.collect{|e| e[2].value}, "D" => book['numbers'].rows.collect{|e| e[3].value}}
|
35
|
+
end
|
36
|
+
|
27
37
|
it "should return cells by reference" do
|
28
38
|
name = TestDataFile.expand_path("various_samples.xlsx")
|
29
39
|
book = POI::Workbook.open(name)
|
30
|
-
|
31
40
|
book.cell("numbers!A1").value.should == 'NUM'
|
32
41
|
book.cell("numbers!A2").to_s.should == '1.0'
|
33
42
|
book.cell("numbers!A3").to_s.should == '2.0'
|
@@ -63,10 +72,10 @@ describe POI::Workbook do
|
|
63
72
|
book['nums'].should == (1..13).collect{|e| e * 1.0}
|
64
73
|
|
65
74
|
# NAMES is a range of empty cells
|
66
|
-
book['NAMES'].should == [nil, nil, nil, nil, nil, nil, nil]
|
75
|
+
book['NAMES'].should == [nil, nil, nil, nil, nil, nil, nil, nil, nil, nil]
|
67
76
|
book.cell('NAMES').each do | cell |
|
68
77
|
cell.value.should be_nil
|
69
|
-
cell.poi_cell.
|
78
|
+
cell.poi_cell.should_not be_nil
|
70
79
|
cell.to_s.should be_empty
|
71
80
|
end
|
72
81
|
end
|
@@ -125,12 +134,12 @@ describe POI::Worksheets do
|
|
125
134
|
it "returns cells when passing a cell reference" do
|
126
135
|
name = TestDataFile.expand_path("various_samples.xlsx")
|
127
136
|
book = POI::Workbook.open(name)
|
128
|
-
book['dates']['A2'].should ==
|
129
|
-
book['dates']['a2'].should ==
|
130
|
-
book['dates']['B2'].should ==
|
131
|
-
book['dates']['b2'].should ==
|
132
|
-
book['dates']['C2'].should ==
|
133
|
-
book['dates']['c2'].should ==
|
137
|
+
book['dates']['A2'].to_s.should == '2010-02-28'
|
138
|
+
book['dates']['a2'].to_s.should == '2010-02-28'
|
139
|
+
book['dates']['B2'].to_s.should == '2010-03-14'
|
140
|
+
book['dates']['b2'].to_s.should == '2010-03-14'
|
141
|
+
book['dates']['C2'].to_s.should == '2010-03-28'
|
142
|
+
book['dates']['c2'].to_s.should == '2010-03-28'
|
134
143
|
end
|
135
144
|
end
|
136
145
|
|
@@ -173,6 +182,21 @@ describe POI::Cells do
|
|
173
182
|
cells.size.should == 1
|
174
183
|
cells.collect.size.should == 1
|
175
184
|
end
|
185
|
+
end
|
186
|
+
|
187
|
+
describe POI::Cell do
|
188
|
+
before :each do
|
189
|
+
@name = TestDataFile.expand_path("various_samples.xlsx")
|
190
|
+
@book = POI::Workbook.open(@name)
|
191
|
+
end
|
192
|
+
|
193
|
+
def book
|
194
|
+
@book
|
195
|
+
end
|
196
|
+
|
197
|
+
def name
|
198
|
+
@name
|
199
|
+
end
|
176
200
|
|
177
201
|
it "should provide dates for date cells" do
|
178
202
|
sheet = book.worksheets["dates"]
|
@@ -328,5 +352,18 @@ describe POI::Cells do
|
|
328
352
|
sheet.rows[14][2].value.should be_nil
|
329
353
|
end
|
330
354
|
|
331
|
-
|
355
|
+
it "should notify the workbook that I have been updated" do
|
356
|
+
book['dates!A10'].to_s.should == '2010-03-08'
|
357
|
+
book['dates!A16'].to_s.should == '2010-03-14'
|
358
|
+
book['dates!B2'].to_s.should == '2010-03-14'
|
359
|
+
|
360
|
+
cell = book.cell('dates!B2')
|
361
|
+
cell.formula.should == 'A16'
|
362
|
+
|
363
|
+
cell.formula = 'A10 + 1'
|
364
|
+
book.cell('dates!B2').poi_cell.should === cell.poi_cell
|
365
|
+
book.cell('dates!B2').formula.should == 'A10 + 1'
|
332
366
|
|
367
|
+
book['dates!B2'].to_s.should == '2010-03-09'
|
368
|
+
end
|
369
|
+
end
|
@@ -0,0 +1,145 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
+
require 'date'
|
3
|
+
require 'stringio'
|
4
|
+
|
5
|
+
describe "writing Workbooks" do
|
6
|
+
it "should create a new empty workbook" do
|
7
|
+
name = 'new-workbook.xlsx'
|
8
|
+
book = POI::Workbook.create(name)
|
9
|
+
book.should_not be_nil
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should create a new workbook and write something to it" do
|
13
|
+
name = 'specs/data/timesheet.xlsx'
|
14
|
+
create_timesheet_spreadsheet(name)
|
15
|
+
book = POI::Workbook.open(name)
|
16
|
+
book.worksheets.size.should == 1
|
17
|
+
book.worksheets[0].name.should == 'Timesheet'
|
18
|
+
book.filename.should == name
|
19
|
+
book['Timesheet!A3'].should == 'Yegor Kozlov'
|
20
|
+
book.cell('Timesheet!J13').formula_value.should == 'SUM(J3:J12)'
|
21
|
+
FileUtils.rm_f name
|
22
|
+
end
|
23
|
+
|
24
|
+
def create_timesheet_spreadsheet name='specs/data/timesheet.xlsx'
|
25
|
+
titles = ["Person", "ID", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun", "Total\nHrs", "Overtime\nHrs", "Regular\nHrs"]
|
26
|
+
sample_data = [
|
27
|
+
["Yegor Kozlov", "YK", 5.0, 8.0, 10.0, 5.0, 5.0, 7.0, 6.0],
|
28
|
+
["Gisella Bronzetti", "GB", 4.0, 3.0, 1.0, 3.5, nil, nil, 4.0]
|
29
|
+
]
|
30
|
+
|
31
|
+
book = POI::Workbook.create(name)
|
32
|
+
title_style = book.create_style :font_height_in_points => 18, :boldweight => :boldweight_bold,
|
33
|
+
:alignment => :align_center, :vertical_alignment => :vertical_center
|
34
|
+
header_style = book.create_style :font_height_in_points => 11, :color => :white, :fill_foreground_color => :grey_50_percent,
|
35
|
+
:fill_pattern => :solid_foreground, :alignment => :align_center, :vertical_alignment => :vertical_center
|
36
|
+
cell_style = book.create_style :alignment => :align_center, :border_bottom => :border_thin, :border_top => :border_thin,
|
37
|
+
:border_left => :border_thin, :border_right => :border_thin, :bottom_border_color => :black,
|
38
|
+
:right_border_color => :black, :left_border_color => :black, :top_border_color => :black
|
39
|
+
form1_style = book.create_style :data_format => '0.00', :fill_pattern => :solid_foreground, :fill_foreground_color => :grey_25_percent,
|
40
|
+
:alignment => :align_center, :vertical_alignment => :vertical_center
|
41
|
+
form2_style = book.create_style :data_format => '0.00', :fill_pattern => :solid_foreground, :fill_foreground_color => :grey_40_percent,
|
42
|
+
:alignment => :align_center, :vertical_alignment => :vertical_center
|
43
|
+
|
44
|
+
sheet = book.create_sheet 'Timesheet'
|
45
|
+
# print_setup = sheet.print_setup
|
46
|
+
# print_setup.landscape = true
|
47
|
+
# sheet.fit_to_page = true
|
48
|
+
# sheet.horizontally_center = true
|
49
|
+
|
50
|
+
title_row = sheet.rows[0]
|
51
|
+
title_row.height_in_points = 45
|
52
|
+
title_cell = title_row.cells[0]
|
53
|
+
title_cell.value = 'Weekly Timesheet'
|
54
|
+
title_cell.style = title_style
|
55
|
+
sheet.add_merged_region org.apache.poi.ss.util.CellRangeAddress.valueOf("$A$1:$L$1")
|
56
|
+
|
57
|
+
header_row = sheet[1]
|
58
|
+
header_row.height_in_points = 40
|
59
|
+
titles.each_with_index do | title, index |
|
60
|
+
header_cell = header_row[index]
|
61
|
+
header_cell.value = title
|
62
|
+
header_cell.style = header_style
|
63
|
+
end
|
64
|
+
|
65
|
+
row_num = 2
|
66
|
+
10.times do
|
67
|
+
row = sheet[row_num]
|
68
|
+
row_num += 1
|
69
|
+
titles.each_with_index do | title, index |
|
70
|
+
cell = row[index]
|
71
|
+
if index == 9
|
72
|
+
cell.formula = "SUM(C#{row_num}:I#{row_num})"
|
73
|
+
cell.style = form1_style
|
74
|
+
elsif index == 11
|
75
|
+
cell.formula = "J#{row_num} - K#{row_num}"
|
76
|
+
cell.style = form1_style
|
77
|
+
else
|
78
|
+
cell.style = cell_style
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
# row with totals below
|
84
|
+
sum_row = sheet[row_num]
|
85
|
+
row_num += 1
|
86
|
+
sum_row.height_in_points = 35
|
87
|
+
cell = sum_row[0]
|
88
|
+
cell.style = form1_style
|
89
|
+
cell = sum_row[1]
|
90
|
+
cell.style = form1_style
|
91
|
+
cell.value = 'Total Hrs:'
|
92
|
+
(2...12).each do | cell_index |
|
93
|
+
cell = sum_row[cell_index]
|
94
|
+
column = (?A + cell_index).chr
|
95
|
+
cell.formula = "SUM(#{column}3:#{column}12)"
|
96
|
+
if cell_index > 9
|
97
|
+
cell.style = form2_style
|
98
|
+
else
|
99
|
+
cell.style = form1_style
|
100
|
+
end
|
101
|
+
end
|
102
|
+
row_num += 1
|
103
|
+
sum_row = sheet[row_num]
|
104
|
+
row_num += 1
|
105
|
+
sum_row.height_in_points = 25
|
106
|
+
cell = sum_row[0]
|
107
|
+
cell.value = 'Total Regular Hours'
|
108
|
+
cell.style = form1_style
|
109
|
+
cell = sum_row[1]
|
110
|
+
cell.formula = 'L13'
|
111
|
+
cell.style = form2_style
|
112
|
+
sum_row = sheet[row_num]
|
113
|
+
row_num += 1
|
114
|
+
cell = sum_row[0]
|
115
|
+
cell.value = 'Total Overtime Hours'
|
116
|
+
cell.style = form1_style
|
117
|
+
cell = sum_row[1]
|
118
|
+
cell.formula = 'K13'
|
119
|
+
cell.style = form2_style
|
120
|
+
|
121
|
+
# set sample data
|
122
|
+
sample_data.each_with_index do |each, row_index|
|
123
|
+
row = sheet[2 + row_index]
|
124
|
+
each.each_with_index do | data, cell_index |
|
125
|
+
data = sample_data[row_index][cell_index]
|
126
|
+
next unless data
|
127
|
+
if data.kind_of? String
|
128
|
+
row[cell_index].value = data #.to_java(:string)
|
129
|
+
else
|
130
|
+
row[cell_index].value = data #.to_java(:double)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
# finally set column widths, the width is measured in units of 1/256th of a character width
|
136
|
+
sheet.set_column_width 0, 30*256 # 30 characters wide
|
137
|
+
(2..9).to_a.each do | column |
|
138
|
+
sheet.set_column_width column, 6*256 # 6 characters wide
|
139
|
+
end
|
140
|
+
sheet.set_column_width 10, 10*256 # 10 characters wide
|
141
|
+
|
142
|
+
book.save
|
143
|
+
File.exist?(name).should == true
|
144
|
+
end
|
145
|
+
end
|
metadata
CHANGED
@@ -1,98 +1,124 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jruby-poi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
|
6
|
-
- 0
|
7
|
-
- 6
|
8
|
-
- 1
|
9
|
-
version: 0.6.1
|
4
|
+
prerelease:
|
5
|
+
version: 0.7.1
|
10
6
|
platform: ruby
|
11
7
|
authors:
|
12
|
-
|
13
|
-
|
8
|
+
- Scott Deming
|
9
|
+
- Jason Rogers
|
14
10
|
autorequire:
|
15
11
|
bindir: bin
|
16
12
|
cert_chain: []
|
17
13
|
|
18
|
-
date:
|
14
|
+
date: 2011-03-27 00:00:00 -04:00
|
19
15
|
default_executable:
|
20
|
-
dependencies:
|
21
|
-
|
16
|
+
dependencies:
|
17
|
+
- !ruby/object:Gem::Dependency
|
18
|
+
name: rspec
|
19
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
21
|
+
requirements:
|
22
|
+
- - ">="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: "0"
|
25
|
+
type: :development
|
26
|
+
prerelease: false
|
27
|
+
version_requirements: *id001
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: ruby-debug
|
30
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
31
|
+
none: false
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: "0"
|
36
|
+
type: :development
|
37
|
+
prerelease: false
|
38
|
+
version_requirements: *id002
|
22
39
|
description: A rubyesque library for manipulating spreadsheets and other document types for jruby, using Apache POI.
|
23
40
|
email:
|
24
|
-
|
25
|
-
|
26
|
-
executables:
|
27
|
-
|
41
|
+
- sdeming@makefile.com
|
42
|
+
- jacaetevha@gmail.com
|
43
|
+
executables:
|
44
|
+
- autospec
|
45
|
+
- htmldiff
|
46
|
+
- ldiff
|
47
|
+
- rdebug
|
48
|
+
- rspec
|
28
49
|
extensions: []
|
29
50
|
|
30
51
|
extra_rdoc_files:
|
31
|
-
|
32
|
-
|
52
|
+
- LICENSE
|
53
|
+
- README.markdown
|
33
54
|
files:
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
55
|
+
- Gemfile
|
56
|
+
- Gemfile.lock
|
57
|
+
- LICENSE
|
58
|
+
- NOTICE
|
59
|
+
- README.markdown
|
60
|
+
- Rakefile
|
61
|
+
- VERSION
|
62
|
+
- bin/autospec
|
63
|
+
- bin/htmldiff
|
64
|
+
- bin/ldiff
|
65
|
+
- bin/rdebug
|
66
|
+
- bin/rspec
|
67
|
+
- jruby-poi.gemspec
|
68
|
+
- lib/ooxml-lib/dom4j-1.6.1.jar
|
69
|
+
- lib/ooxml-lib/geronimo-stax-api_1.0_spec-1.0.jar
|
70
|
+
- lib/ooxml-lib/xmlbeans-2.3.0.jar
|
71
|
+
- lib/poi-3.6-20091214.jar
|
72
|
+
- lib/poi-contrib-3.6-20091214.jar
|
73
|
+
- lib/poi-examples-3.6-20091214.jar
|
74
|
+
- lib/poi-ooxml-3.6-20091214.jar
|
75
|
+
- lib/poi-ooxml-schemas-3.6-20091214.jar
|
76
|
+
- lib/poi-scratchpad-3.6-20091214.jar
|
77
|
+
- lib/poi.rb
|
78
|
+
- lib/poi/workbook.rb
|
79
|
+
- lib/poi/workbook/area.rb
|
80
|
+
- lib/poi/workbook/cell.rb
|
81
|
+
- lib/poi/workbook/named_range.rb
|
82
|
+
- lib/poi/workbook/row.rb
|
83
|
+
- lib/poi/workbook/workbook.rb
|
84
|
+
- lib/poi/workbook/worksheet.rb
|
85
|
+
- spec_debug.sh
|
86
|
+
- specs/data/simple_with_picture.ods
|
87
|
+
- specs/data/simple_with_picture.xls
|
88
|
+
- specs/data/spreadsheet.ods
|
89
|
+
- specs/data/various_samples.xlsx
|
90
|
+
- specs/io_spec.rb
|
91
|
+
- specs/spec_helper.rb
|
92
|
+
- specs/support/java/jrubypoi/MockOutputStream.java
|
93
|
+
- specs/support/java/support.jar
|
94
|
+
- specs/support/matchers/cell_matcher.rb
|
95
|
+
- specs/workbook_spec.rb
|
96
|
+
- specs/writing_spec.rb
|
69
97
|
has_rdoc: true
|
70
98
|
homepage: http://github.com/sdeming/jruby-poi
|
71
99
|
licenses: []
|
72
100
|
|
73
101
|
post_install_message:
|
74
|
-
rdoc_options:
|
75
|
-
|
102
|
+
rdoc_options: []
|
103
|
+
|
76
104
|
require_paths:
|
77
|
-
|
105
|
+
- lib
|
78
106
|
required_ruby_version: !ruby/object:Gem::Requirement
|
107
|
+
none: false
|
79
108
|
requirements:
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
- 0
|
84
|
-
version: "0"
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: "0"
|
85
112
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
86
114
|
requirements:
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
- 0
|
91
|
-
version: "0"
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: "0"
|
92
118
|
requirements: []
|
93
119
|
|
94
120
|
rubyforge_project:
|
95
|
-
rubygems_version: 1.
|
121
|
+
rubygems_version: 1.6.0
|
96
122
|
signing_key:
|
97
123
|
specification_version: 3
|
98
124
|
summary: Apache POI class library for jruby
|