diff --git a/data/customXml.xlsx b/data/customXml.xlsx new file mode 100644 index 0000000..d8a8362 Binary files /dev/null and b/data/customXml.xlsx differ diff --git a/src/read.jl b/src/read.jl index c938715..9973a82 100644 --- a/src/read.jl +++ b/src/read.jl @@ -203,7 +203,10 @@ function open_or_read_xlsx(source::Union{IO, AbstractString}, read_files::Bool, continue end - if endswith(f.name, ".xml") || endswith(f.name, ".rels") + # Rather than ignore custom XML internal files here, let them get passed through to write like binaries are. + if !startswith(f.name, "customXml") && (endswith(f.name, ".xml") || endswith(f.name, ".rels")) + #if endswith(f.name, ".xml") || endswith(f.name, ".rels") + # XML file internal_xml_file_add!(xf, f.name) if read_files @@ -215,9 +218,10 @@ function open_or_read_xlsx(source::Union{IO, AbstractString}, read_files::Bool, end # ignore custom XML internal files - if startswith(f.name, "customXml") - continue - end + # no longer needed if these files are passed through like binary files + #if startswith(f.name, "customXml") + # continue + #end internal_xml_file_read(xf, f.name) end @@ -225,6 +229,7 @@ function open_or_read_xlsx(source::Union{IO, AbstractString}, read_files::Bool, # Binary file # we only read binary files to save the Excel file later + # Custom XML files also now get passed through this way, too bytes = ZipFile.read(f) @assert sizeof(bytes) == f.uncompressedsize xf.binary_data[f.name] = bytes diff --git a/test/runtests.jl b/test/runtests.jl index 84f762f..85eeb00 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1113,6 +1113,31 @@ end isfile(filename_copy) && rm(filename_copy) end +@testset "CustomXml" begin + # issue #210 + # None of the example .xlsx files in the test suite include custoimXml internal files + # but customXml.xlsx does + template = XLSX.open_xlsx_template(joinpath(data_directory, "customXml.xlsx")) + filename_copy = "customXml_copy.xlsx" + for sn in XLSX.sheetnames(template) + sheet = template[sn] + sheet["Q1"] = "Cant" # using an apostrophe here causes a test failure reading the copy - "Evaluated: "Can't" == "Can't"" + sheet["Q2"] = "write" + sheet["Q3"] = "this" + sheet["Q4"] = "template" + end + @test XLSX.writexlsx(filename_copy, template, overwrite=true) == nothing # This is where the bug will throw if custoimXml internal files present. + @test isfile(filename_copy) + f_copy = XLSX.readxlsx(filename_copy) # Don't really think this second part is necessary. + test_Xmlread = [["Cant", "write", "this", "template"]] + for sn in XLSX.sheetnames(f_copy) + sheet = template[sn] + data = [[sheet["Q1"], sheet["Q2"], sheet["Q3"], sheet["Q4"]]] + check_test_data(data, test_Xmlread) + end + isfile(filename_copy) && rm(filename_copy) +end + @testset "Edit Template" begin new_filename = "new_file_from_empty_template.xlsx" f = XLSX.open_empty_template()