From e1f509cfbd66a9aeb4e0916fa5e6a154775014f0 Mon Sep 17 00:00:00 2001 From: Morgunov Mmike Date: Mon, 16 Sep 2019 12:29:40 +0300 Subject: [PATCH] Fix Excel2003: set namespace if not exist --- lib/roo/xls/excel_2003_xml.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/roo/xls/excel_2003_xml.rb b/lib/roo/xls/excel_2003_xml.rb index 40853f5..4df2c0e 100644 --- a/lib/roo/xls/excel_2003_xml.rb +++ b/lib/roo/xls/excel_2003_xml.rb @@ -22,7 +22,12 @@ def initialize(filename, options = {}) @doc = ::Roo::Utils.load_xml(@filename) end namespace = @doc.namespaces.select { |_, urn| urn == 'urn:schemas-microsoft-com:office:spreadsheet' }.keys.last - @namespace = (namespace.nil? || namespace.empty?) ? 'ss' : namespace.split(':').last + if namespace.to_s.empty? || namespace.split(':').size == 1 + namespace = 'xmlns:ss' + workbook = @doc.at('Workbook') + workbook.add_namespace_definition('ss', 'urn:schemas-microsoft-com:office:spreadsheet') + end + @namespace = namespace.split(':').last || 'ss' super(filename, options) @formula = {} @style = {}