@@ -5,7 +5,7 @@ module Roo
5
5
class Excelx
6
6
class SheetDoc < Excelx ::Extractor
7
7
extend Forwardable
8
- delegate [ :workbook , :shared_strings ] => :@shared
8
+ delegate [ :workbook ] => :@shared
9
9
10
10
def initialize ( path , relationships , shared , options = { } )
11
11
super ( path )
@@ -41,7 +41,7 @@ def each_cell(row_xml)
41
41
row_xml . children . each do |cell_element |
42
42
# If you're sure you're not going to need this hyperlinks you can discard it
43
43
hyperlinks = unless @options [ :no_hyperlinks ]
44
- key = ::Roo ::Utils . ref_to_key ( cell_element [ 'r' . freeze ] )
44
+ key = ::Roo ::Utils . ref_to_key ( cell_element [ COMMON_STRINGS [ :r ] ] )
45
45
hyperlinks ( @relationships ) [ key ]
46
46
end
47
47
@@ -53,13 +53,13 @@ def each_cell(row_xml)
53
53
54
54
def cell_value_type ( type , format )
55
55
case type
56
- when 's' . freeze
56
+ when 's'
57
57
:shared
58
- when 'b' . freeze
58
+ when 'b'
59
59
:boolean
60
- when 'str' . freeze
60
+ when 'str'
61
61
:string
62
- when 'inlineStr' . freeze
62
+ when 'inlineStr'
63
63
:inlinestr
64
64
else
65
65
Excelx ::Format . to_type ( format )
@@ -82,32 +82,32 @@ def cell_value_type(type, format)
82
82
#
83
83
# Returns a type of <Excelx::Cell>.
84
84
def cell_from_xml ( cell_xml , hyperlink )
85
- coordinate = ::Roo ::Utils . extract_coordinate ( cell_xml [ 'r' . freeze ] )
85
+ coordinate = ::Roo ::Utils . extract_coordinate ( cell_xml [ COMMON_STRINGS [ :r ] ] )
86
86
cell_xml_children = cell_xml . children
87
87
return Excelx ::Cell ::Empty . new ( coordinate ) if cell_xml_children . empty?
88
88
89
89
# NOTE: This is error prone, to_i will silently turn a nil into a 0.
90
90
# This works by coincidence because Format[0] is General.
91
- style = cell_xml [ 's' . freeze ] . to_i
91
+ style = cell_xml [ COMMON_STRINGS [ :s ] ] . to_i
92
92
formula = nil
93
93
94
94
cell_xml_children . each do |cell |
95
95
case cell . name
96
- when 'is' . freeze
97
- content = ""
96
+ when 'is'
97
+ content = String . new
98
98
cell . children . each do |inline_str |
99
- if inline_str . name == 't' . freeze
99
+ if inline_str . name == 't'
100
100
content << inline_str . content
101
101
end
102
102
end
103
103
unless content . empty?
104
104
return Excelx ::Cell . cell_class ( :string ) . new ( content , formula , style , hyperlink , coordinate )
105
105
end
106
- when 'f' . freeze
106
+ when 'f'
107
107
formula = cell . content
108
- when 'v' . freeze
108
+ when 'v'
109
109
format = style_format ( style )
110
- value_type = cell_value_type ( cell_xml [ 't' . freeze ] , format )
110
+ value_type = cell_value_type ( cell_xml [ COMMON_STRINGS [ :t ] ] , format )
111
111
112
112
return create_cell_from_value ( value_type , cell , formula , format , style , hyperlink , coordinate )
113
113
end
@@ -169,8 +169,8 @@ def extract_hyperlinks(relationships)
169
169
return { } unless ( hyperlinks = doc . xpath ( '/worksheet/hyperlinks/hyperlink' ) )
170
170
171
171
Hash [ hyperlinks . map do |hyperlink |
172
- if hyperlink . attribute ( 'id' . freeze ) && ( relationship = relationships [ hyperlink . attribute ( 'id' . freeze ) . text ] )
173
- [ ::Roo ::Utils . ref_to_key ( hyperlink . attributes [ ' ref' . freeze ] . to_s ) , relationship . attribute ( 'Target' . freeze ) . text ]
172
+ if hyperlink . attribute ( 'id' ) && ( relationship = relationships [ hyperlink . attribute ( 'id' ) . text ] )
173
+ [ ::Roo ::Utils . ref_to_key ( hyperlink . attributes [ COMMON_STRINGS [ : ref] ] . to_s ) , relationship . attribute ( 'Target' ) . text ]
174
174
end
175
175
end . compact ]
176
176
end
@@ -179,7 +179,7 @@ def expand_merged_ranges(cells)
179
179
# Extract merged ranges from xml
180
180
merges = { }
181
181
doc . xpath ( '/worksheet/mergeCells/mergeCell' ) . each do |mergecell_xml |
182
- tl , br = mergecell_xml [ ' ref' . freeze ] . split ( /:/ ) . map { |ref | ::Roo ::Utils . ref_to_key ( ref ) }
182
+ tl , br = mergecell_xml [ COMMON_STRINGS [ : ref] ] . split ( /:/ ) . map { |ref | ::Roo ::Utils . ref_to_key ( ref ) }
183
183
for row in tl [ 0 ] ..br [ 0 ] do
184
184
for col in tl [ 1 ] ..br [ 1 ] do
185
185
next if row == tl [ 0 ] && col == tl [ 1 ]
@@ -196,7 +196,7 @@ def expand_merged_ranges(cells)
196
196
def extract_cells ( relationships )
197
197
extracted_cells = { }
198
198
doc . xpath ( '/worksheet/sheetData/row/c' ) . each do |cell_xml |
199
- key = ::Roo ::Utils . ref_to_key ( cell_xml [ 'r' . freeze ] )
199
+ key = ::Roo ::Utils . ref_to_key ( cell_xml [ COMMON_STRINGS [ :r ] ] )
200
200
extracted_cells [ key ] = cell_from_xml ( cell_xml , hyperlinks ( relationships ) [ key ] )
201
201
end
202
202
@@ -207,7 +207,7 @@ def extract_cells(relationships)
207
207
208
208
def extract_dimensions
209
209
Roo ::Utils . each_element ( @path , 'dimension' ) do |dimension |
210
- return dimension . attributes [ ' ref' . freeze ] . value
210
+ return dimension . attributes [ COMMON_STRINGS [ : ref] ] . value
211
211
end
212
212
end
213
213
0 commit comments