Skip to content

Commit 1179278

Browse files
Alfonso Uceda Pompapacoguzman
Alfonso Uceda Pompa
authored andcommitted
Removed hyperlinks when parsing files in streaming mode
1 parent 211f89b commit 1179278

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## [Unreleased]
2+
### Added
3+
- Discard hiperlinks lookups to allow streaming parsing without loading whole files
4+
15
## [2.4.0] 2016-05-14
26
### Fixed
37
- Fixed opening spreadsheets with charts [315](https://github.com/roo-rb/roo/pull/315)

lib/roo/excelx.rb

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def initialize(filename_or_stream, options = {})
3636
cell_max = options.delete(:cell_max)
3737
sheet_options = {}
3838
sheet_options[:expand_merged_ranges] = (options[:expand_merged_ranges] || false)
39+
sheet_options[:no_hyperlinks] = (options[:no_hyperlinks] || false)
3940

4041
unless is_stream?(filename_or_stream)
4142
file_type_check(filename_or_stream, %w[.xlsx .xlsm], 'an Excel 2007', file_warning, packed)

lib/roo/excelx/sheet_doc.rb

+7-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,13 @@ def each_row_streaming(&block)
3939
def each_cell(row_xml)
4040
return [] unless row_xml
4141
row_xml.children.each do |cell_element|
42-
key = ::Roo::Utils.ref_to_key(cell_element['r'])
43-
yield cell_from_xml(cell_element, hyperlinks(@relationships)[key])
42+
# If you're sure you're not going to need this hyperlinks you can discard it
43+
hyperlinks = unless @options[:no_hyperlinks]
44+
key = ::Roo::Utils.ref_to_key(cell_element['r'])
45+
hyperlinks(@relationships)[key]
46+
end
47+
48+
yield cell_from_xml(cell_element, hyperlinks)
4449
end
4550
end
4651

0 commit comments

Comments
 (0)