Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Excelx hyperlink r:id fix + to_csv fix for :link types = no more failing tests #135

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
/log/
.ruby-version
.project
.rvmrc
.idea
2 changes: 1 addition & 1 deletion lib/roo/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@ def cell_to_csv(row, col, sheet)
onecell = cell(row,col,sheet)

case celltype(row,col,sheet)
when :string, :link
when :string
unless onecell.empty?
%{"#{onecell.gsub(/"/,'""')}"}
end
Expand Down
17 changes: 5 additions & 12 deletions lib/roo/excelx.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def initialize(filename, options = {}, deprecated_file_warning = :error)
end
@comments_files = Array.new
@rels_files = Array.new
extract_content(tmpdir, @filename)
process_zipfile(tmpdir, @filename)
@workbook_doc = load_xml(File.join(tmpdir, "roo_workbook.xml"))
@shared_table = []
if File.exist?(File.join(tmpdir, 'roo_sharedStrings.xml'))
Expand Down Expand Up @@ -538,8 +538,8 @@ def read_hyperlinks(sheet=nil)
rels = Hash[rels_doc.xpath("/xmlns:Relationships/xmlns:Relationship").map do |r|
[r.attribute('Id').text, r]
end]
@sheet_doc[n].xpath("/xmlns:worksheet/xmlns:hyperlinks/xmlns:hyperlink[id]").each do |h|
if rel_element = rels[h.attribute('id').text]
@sheet_doc[n].xpath("/xmlns:worksheet/xmlns:hyperlinks/xmlns:hyperlink").each do |h|
if h.attribute('id') && rel_element = rels[h.attribute('id').text]
row,col = Roo::Base.split_coordinate(h.attributes['ref'].to_s)
@hyperlink[sheet] ||= {}
@hyperlink[sheet][[row,col]] = rel_element.attribute('Target').text
Expand All @@ -559,7 +559,7 @@ def read_labels
end

# Extracts all needed files from the zip file
def process_zipfile(tmpdir, zipfilename, zip, path='')
def process_zipfile(tmpdir, zipfilename)
@sheet_files = []
Roo::ZipFile.open(zipfilename) {|zf|
zf.entries.each {|entry|
Expand Down Expand Up @@ -597,7 +597,7 @@ def process_zipfile(tmpdir, zipfilename, zip, path='')
@rels_files[nr.to_i-1] = "#{tmpdir}/roo_rels#{nr}"
end
if path
extract_file(zip, entry, path)
extract_file(zf, entry, path)
end
}
}
Expand All @@ -609,13 +609,6 @@ def extract_file(source_zip, entry, destination_path)
}
end

# extract files from the zip file
def extract_content(tmpdir, zipfilename)
Roo::ZipFile.open(@filename) do |zip|
process_zipfile(tmpdir, zipfilename,zip)
end
end

# read the shared strings xml document
def read_shared_strings(doc)
doc.xpath("/xmlns:sst/xmlns:si").each do |si|
Expand Down
1 change: 1 addition & 0 deletions test/files/so_datetime.csv
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
1961-11-21T12:17:18+00:00,1961-11-21T12:17:18+00:00,1961-11-21T12:17:18+00:00
1961-11-21,1961-11-21,1961-11-21
1961-11-21,1961-11-21,1961-11-21
2013-11-05T11:45:00+00:00,2013-11-05T11:45:00+00:00,2013-11-05T11:45:00+00:00
1 change: 0 additions & 1 deletion test/test_roo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1133,7 +1133,6 @@ def test_link_to_csv
csv_output = File.join(tempdir,'link.csv')
assert oo.to_csv(csv_output)
assert File.exists?(csv_output)
puts `diff --strip-trailing-cr #{TESTDIR}/link.csv #{csv_output}`
assert_equal "", `diff --strip-trailing-cr #{TESTDIR}/link.csv #{csv_output}`
# --strip-trailing-cr is needed because the test-file use 0A and
# the test on an windows box generates 0D 0A as line endings
Expand Down