@@ -11,6 +11,7 @@ def initialize(filename, options={})
11
11
packed = options [ :packed ]
12
12
file_warning = options [ :file_warning ] || :error
13
13
14
+ @only_visible_sheets = options [ :only_visible_sheets ]
14
15
file_type_check ( filename , '.ods' , 'an Roo::OpenOffice' , file_warning , packed )
15
16
@tmpdir = make_tmpdir ( filename . split ( '/' ) . last , options [ :tmpdir_root ] )
16
17
@filename = local_filename ( filename , @tmpdir , packed )
@@ -33,7 +34,8 @@ def initialize(filename, options={})
33
34
@formula = Hash . new
34
35
@style = Hash . new
35
36
@style_defaults = Hash . new { |h , k | h [ k ] = [ ] }
36
- @style_definitions = Hash . new
37
+ @table_display = Hash . new { |h , k | h [ k ] = true }
38
+ @font_style_definitions = Hash . new
37
39
@comment = Hash . new
38
40
@comments_read = Hash . new
39
41
end
@@ -309,7 +311,7 @@ def font(row, col, sheet=nil)
309
311
read_cells ( sheet )
310
312
row , col = normalize ( row , col )
311
313
style_name = @style [ sheet ] [ [ row , col ] ] || @style_defaults [ sheet ] [ col - 1 ] || 'Default'
312
- @style_definitions [ style_name ]
314
+ @font_style_definitions [ style_name ]
313
315
end
314
316
315
317
# returns the type of a cell:
@@ -332,9 +334,16 @@ def celltype(row,col,sheet=nil)
332
334
end
333
335
334
336
def sheets
335
- doc . xpath ( "//*[local-name()='table']" ) . map do |sheet |
336
- sheet . attributes [ "name" ] . value
337
+ unless @table_display . any?
338
+ doc . xpath ( "//*[local-name()='automatic-styles']" ) . each do |style |
339
+ read_table_styles ( style )
340
+ end
337
341
end
342
+ doc . xpath ( "//*[local-name()='table']" ) . map do |sheet |
343
+ if !@only_visible_sheets || @table_display [ attr ( sheet , 'style-name' ) ]
344
+ sheet . attributes [ "name" ] . value
345
+ end
346
+ end . compact
338
347
end
339
348
340
349
# version of the Roo::OpenOffice document
@@ -595,7 +604,7 @@ def read_labels
595
604
end
596
605
597
606
def read_styles ( style_elements )
598
- @style_definitions [ 'Default' ] = Roo ::Font . new
607
+ @font_style_definitions [ 'Default' ] = Roo ::Font . new
599
608
style_elements . each do |style |
600
609
next unless style . name == 'style'
601
610
style_name = attr ( style , 'name' )
@@ -604,7 +613,19 @@ def read_styles(style_elements)
604
613
font . bold = attr ( properties , 'font-weight' )
605
614
font . italic = attr ( properties , 'font-style' )
606
615
font . underline = attr ( properties , 'text-underline-style' )
607
- @style_definitions [ style_name ] = font
616
+ @font_style_definitions [ style_name ] = font
617
+ end
618
+ end
619
+ end
620
+
621
+ def read_table_styles ( styles )
622
+ styles . children . each do |style |
623
+ next unless style . name == 'style'
624
+ style_name = attr ( style , 'name' )
625
+ style . children . each do |properties |
626
+ display = attr ( properties , 'display' )
627
+ next unless display
628
+ @table_display [ style_name ] = ( display == 'true' )
608
629
end
609
630
end
610
631
end
0 commit comments