Permalink
Browse files

Fix ods format so it reads column|row default style

  • Loading branch information...
1 parent 6d8ad2b commit 599e04bb04ce7cf33273a79901bf9ad9778d9505 --unset committed Feb 24, 2009
Showing with 39 additions and 14 deletions.
  1. +4 −4 lib/roo/openoffice.rb
  2. BIN test/style.ods
  3. +35 −10 test/test_roo.rb
View
8 lib/roo/openoffice.rb
@@ -58,8 +58,8 @@ def initialize(filename, packed=nil, file_warning=:error) #, create = false)
@first_column = Hash.new
@last_column = Hash.new
@style = Hash.new
- @style_defaults = Hash.new
- @style_definitions = Hash.new { |h,k| h[k] = {} }
+ @style_defaults = Hash.new { |h,k| h[k] = [] }
+ @style_definitions = Hash.new
@header_line = 1
end
@@ -133,7 +133,7 @@ def font(row, col, sheet=nil)
sheet = @default_sheet unless sheet
read_cells(sheet) unless @cells_read[sheet]
row,col = normalize(row,col)
- style_name = @style[sheet][[row,col]] || @style_defaults[sheet]
+ style_name = @style[sheet][[row,col]] || @style_defaults[sheet][col - 1] || 'Default'
@style_definitions[style_name]
end
@@ -308,7 +308,7 @@ def read_cells(sheet=nil)
se.each_element do |te|
if te.name == "table-column"
rep = te.attributes["number-columns-repeated"]
- @style_defaults[sheet] = te.attributes["default-cell-style-name"]
+ @style_defaults[sheet] << te.attributes["default-cell-style-name"]
elsif te.name == "table-row"
if te.attributes['number-rows-repeated']
skip_y = te.attributes['number-rows-repeated'].to_i
View
BIN test/style.ods
Binary file not shown.
View
45 test/test_roo.rb
@@ -4871,54 +4871,79 @@ def test_cell_excel_boolean
# for test_cell_styles
def verify_cell_fonts(oo)
oo.default_sheet = oo.sheets.first
+
+ # bold
assert_equal true, oo.font(1,1).bold?
assert_equal false, oo.font(1,1).italic?
assert_equal false, oo.font(1,1).underline?
+ # italic
assert_equal false, oo.font(2,1).bold?
assert_equal true, oo.font(2,1).italic?
assert_equal false, oo.font(2,1).underline?
+ # normal
assert_equal false, oo.font(3,1).bold?
assert_equal false, oo.font(3,1).italic?
assert_equal false, oo.font(3,1).underline?
+ # underline
assert_equal false, oo.font(4,1).bold?
assert_equal false, oo.font(4,1).italic?
assert_equal true, oo.font(4,1).underline?
+ # bold italic
assert_equal true, oo.font(5,1).bold?
assert_equal true, oo.font(5,1).italic?
assert_equal false, oo.font(5,1).underline?
+ # bold underline
assert_equal true, oo.font(6,1).bold?
assert_equal false, oo.font(6,1).italic?
assert_equal true, oo.font(6,1).underline?
+ # italic underline
assert_equal false, oo.font(7,1).bold?
assert_equal true, oo.font(7,1).italic?
assert_equal true, oo.font(7,1).underline?
+
+
+
end
def test_cell_styles
if OPENOFFICE
oo = Openoffice.new(File.join(TESTDIR,"style.ods"))
verify_cell_fonts(oo)
- # assert_equal true, oo.font(8,1).bold?
- # assert_equal false, oo.font(8,1).italic?
- # assert_equal false, oo.font(8,1).underline?
- # assert_equal true, oo.font(9,2).bold?
- # assert_equal false, oo.font(9,2).italic?
- # assert_equal false, oo.font(9,2).underline?
+
+ # bolded row
+ assert_equal true, oo.font(8,1).bold?
+ assert_equal false, oo.font(8,1).italic?
+ assert_equal false, oo.font(8,1).underline?
+
+ # bolded col
+ assert_equal true, oo.font(9,2).bold?
+ assert_equal false, oo.font(9,2).italic?
+ assert_equal false, oo.font(9,2).underline?
+
+ # bolded row, italic col
+ assert_equal true, oo.font(10,3).bold?
+ assert_equal true, oo.font(10,3).italic?
+ assert_equal false, oo.font(10,3).underline?
+
+ # normal
+ assert_equal false, oo.font(11,4).bold?
+ assert_equal false, oo.font(11,4).italic?
+ assert_equal false, oo.font(11,4).underline?
end
if EXCELX
oo = Excelx.new(File.join(TESTDIR,"style.xlsx"))
- verify_cell_fonts(oo)
- end
+ verify_cell_fonts(oo)
+ end
if EXCEL
oo = Excel.new(File.join(TESTDIR,"style.xls"))
- verify_cell_fonts(oo)
+ verify_cell_fonts(oo)
+ end
end
- end
end # class

0 comments on commit 599e04b

Please sign in to comment.