@@ -359,12 +359,21 @@ archiveToDocxWithWarnings archive = do
359359 Right doc -> Right (Docx doc, stateWarnings st)
360360 Left e -> Left e
361361
362−
362+getDocumentPath :: Archive -> Maybe String
363+getDocumentPath zf = do
364+ entry <- findEntryByPath "_rels/.rels" zf
365+ relsElem <- (parseXMLDoc . UTF8.toStringLazy . fromEntry) entry
366+ let rels = filterChildrenName (\n -> qName n == "Relationship") relsElem
367+ rel <- listToMaybe $
368+ filter (\e -> findAttr (QName "Type" Nothing Nothing) e ==
369+ Just "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument")
370+ rels
371+ findAttr (QName "Target" Nothing Nothing) rel
363372
364373archiveToDocument :: Archive -> D Document
365374archiveToDocument zf = do
366− entry <- maybeToD $ findEntryByPath "word/document.xml" zf
367− `mplus` findEntryByPath "word/document2.xml" zf -- see #5277
375+ docPath <- maybeToD $ getDocumentPath zf
376+ entry <- maybeToD $ findEntryByPath docPath zf
368377 docElem <- maybeToD $ (parseXMLDoc . UTF8.toStringLazy . fromEntry) entry
369378 let namespaces = elemToNameSpaces docElem
370379 bodyElem <- maybeToD $ findChildByName namespaces "w" "body" docElem