specs/workbook_spec.rb in jruby-poi-0.6.1 vs specs/workbook_spec.rb in jruby-poi-0.7.1
- old
+ new
@@ -22,14 +22,23 @@
book = POI::Workbook.open(content)
book.worksheets.size.should == 5
book.filename.should =~ /spreadsheet.xlsx$/
end
+ it "should return a column of cells by reference" do
+ name = TestDataFile.expand_path("various_samples.xlsx")
+ book = POI::Workbook.open(name)
+ book["numbers!$A"].should == book['numbers'].rows.collect{|e| e[0].value}
+ book["numbers!A"].should == book['numbers'].rows.collect{|e| e[0].value}
+ book["numbers!C"].should == book['numbers'].rows.collect{|e| e[2].value}
+ book["numbers!$D:$D"].should == book['numbers'].rows.collect{|e| e[3].value}
+ book["numbers!$c:$D"].should == {"C" => book['numbers'].rows.collect{|e| e[2].value}, "D" => book['numbers'].rows.collect{|e| e[3].value}}
+ end
+
it "should return cells by reference" do
name = TestDataFile.expand_path("various_samples.xlsx")
book = POI::Workbook.open(name)
-
book.cell("numbers!A1").value.should == 'NUM'
book.cell("numbers!A2").to_s.should == '1.0'
book.cell("numbers!A3").to_s.should == '2.0'
book.cell("numbers!A4").to_s.should == '3.0'
@@ -61,14 +70,14 @@
book.named_ranges.collect{|e| e.formula}.should == ["'high refs'!$AO$624", "'bools & errors'!$D$2:$D$11", "'high refs'!$AP$619:$AP$631"]
book['four_times_six'].should == 24.0
book['nums'].should == (1..13).collect{|e| e * 1.0}
# NAMES is a range of empty cells
- book['NAMES'].should == [nil, nil, nil, nil, nil, nil, nil]
+ book['NAMES'].should == [nil, nil, nil, nil, nil, nil, nil, nil, nil, nil]
book.cell('NAMES').each do | cell |
cell.value.should be_nil
- cell.poi_cell.should be_nil
+ cell.poi_cell.should_not be_nil
cell.to_s.should be_empty
end
end
it "should return an array of cell values by reference" do
@@ -123,16 +132,16 @@
end
it "returns cells when passing a cell reference" do
name = TestDataFile.expand_path("various_samples.xlsx")
book = POI::Workbook.open(name)
- book['dates']['A2'].should == Date.parse('2010-02-28')
- book['dates']['a2'].should == Date.parse('2010-02-28')
- book['dates']['B2'].should == Date.parse('2010-03-14')
- book['dates']['b2'].should == Date.parse('2010-03-14')
- book['dates']['C2'].should == Date.parse('2010-03-28')
- book['dates']['c2'].should == Date.parse('2010-03-28')
+ book['dates']['A2'].to_s.should == '2010-02-28'
+ book['dates']['a2'].to_s.should == '2010-02-28'
+ book['dates']['B2'].to_s.should == '2010-03-14'
+ book['dates']['b2'].to_s.should == '2010-03-14'
+ book['dates']['C2'].to_s.should == '2010-03-28'
+ book['dates']['c2'].to_s.should == '2010-03-28'
end
end
describe POI::Rows do
it "should be enumerable" do
@@ -171,11 +180,26 @@
cells.should be_kind_of Enumerable
cells.size.should == 1
cells.collect.size.should == 1
end
+end
+describe POI::Cell do
+ before :each do
+ @name = TestDataFile.expand_path("various_samples.xlsx")
+ @book = POI::Workbook.open(@name)
+ end
+
+ def book
+ @book
+ end
+
+ def name
+ @name
+ end
+
it "should provide dates for date cells" do
sheet = book.worksheets["dates"]
rows = sheet.rows
dates_by_column = [
@@ -326,7 +350,20 @@
it "should handle getting values out of 'non-existent' cells" do
sheet = book.worksheets["bools & errors"]
sheet.rows[14][2].value.should be_nil
end
-end
+ it "should notify the workbook that I have been updated" do
+ book['dates!A10'].to_s.should == '2010-03-08'
+ book['dates!A16'].to_s.should == '2010-03-14'
+ book['dates!B2'].to_s.should == '2010-03-14'
+ cell = book.cell('dates!B2')
+ cell.formula.should == 'A16'
+
+ cell.formula = 'A10 + 1'
+ book.cell('dates!B2').poi_cell.should === cell.poi_cell
+ book.cell('dates!B2').formula.should == 'A10 + 1'
+
+ book['dates!B2'].to_s.should == '2010-03-09'
+ end
+end