Skip to content

KeyError: key "r:id" not found when the relationships namespace uses a prefix other than r (regression since 0.10) #507

Open

Description

@larsJonsen

Description

Since moving from EzXML to XML.jl, XLSX.jl looks up relationship attributes by the literal qualified name "r:id". Under the XML Namespaces spec the prefix can be anything, as long as it is bound to http://schemas.openxmlformats.org/officeDocument/2006/relationships. Some report generators write the sheet entries in xl/workbook.xml like this:

<sheet name="Transactions" sheetId="6"
       xmlns:relationships="http://schemas.openxmlformats.org/officeDocument/2006/relationships"
       relationships:id="rId6"/>

Excel and LibreOffice open these files without problems, and so does XLSX.jl 0.10.4. XLSX.jl 0.13.4 fails as soon as it opens the workbook:

ERROR: KeyError: key "r:id" not found
Stacktrace:
  [1] getindex
    @ XML/src/node.jl:45 [inlined]
  [2] Worksheet(xf::XLSXFile, sheet_element::XML.Node{String})
    @ XLSX src/worksheet.jl:73
  [3] parse_workbook!(xf::XLSXFile)
    @ XLSX src/read.jl:935
  [4] open_or_read_xlsx(...)
    @ XLSX src/read.jl:757
  ...

Minimal reproducer

The script writes an ordinary file with XLSX.jl and then rewrites the <sheet> element so it uses a different prefix that is bound to the same namespace:

using XLSX, ZipArchives

src, dst = "plain.xlsx", "prefixed.xlsx"
XLSX.writetable(src, "Sheet1" => [(a=[1,2], b=["x","y"])]...; overwrite=true)

r = ZipReader(read(src))
ZipWriter(dst) do w
    for name in zip_names(r)
        data = zip_readentry(r, name)
        if name == "xl/workbook.xml"
            s = replace(String(data), r"<sheet ([^>]*?)r:id=" =>
                s"<sheet \1xmlns:relationships=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" relationships:id=")
            data = Vector{UInt8}(s)
        end
        zip_writefile(w, name, data)
    end
end

XLSX.readtable(src, "Sheet1")   # works
XLSX.readtable(dst, "Sheet1")   # KeyError: key "r:id" not found

Versions

  • XLSX.jl 0.13.4 fails; 0.10.4 works on the same file
  • Julia 1.13.1, Linux x86_64

Notes

The failing lookup is src/worksheet.jl:73 (a["r:id"]). The same literal-prefix pattern also appears in other places, for example src/relationship.jl:134 and src/exceltables.jl:132,765. So files like this would probably fail in those places too once the sheet lookup is fixed. Resolving the attribute by namespace URI + local name (id), or accepting any prefix that is bound to the relationships namespace, would fix all of them.

Happy to test a fix.

Activity

  1. TimG1964 commented on Nov 22, 2026

    @TimG1964
    Collaborator

    Thanks for the clear report and the reproducer, @larsJonsen. You were right: since 0.11, XLSX.jl looked up the literal name r:id and didn't handle other prefixes bound to the relationships namespace.

    0.10.4 worked here partly by luck. Under EzXML, node["r:id"] looked up the prefix r and then matched the attribute by its namespace URI. Your reproducer starts from a writetable file, whose <workbook> root still declares xmlns:r, so the lookup succeeded. A file that declares the namespace only as relationships: fails in 0.10.4 too, with unknown namespace prefix: 'r'.

    The fix (#508) reads relationship ids under any prefix. It covers every place you listed (worksheet.jl, relationship.jl:134, exceltables.jl:132 and :765) plus a few more: table-part ids, external references and external-book paths. While auditing, I also fixed several places where XLSX.jl writes into parts it didn't create:

    • the r prefix is now declared wherever XLSX.jl writes an r:id
    • images and text boxes added to an existing drawing now use that drawing's own prefixes
    • copysheet! no longer adds a second uid attribute when the source sheet uses a different prefix for it

    Your reproducer now reads correctly, in both forms: with xmlns:r still on the root, and with only relationships:. Files written back from it open in Excel without repair. If you could try the branch with output from your report generator, that would be very helpful.

  2. added a commit that references this issue on Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions