![](/img/trans.png)
[英]How to insert a docx document into another docx at certain position without altchunk
[英]How to insert AltChunk to docx page header?
我正在嘗試在頁眉中構建一個包含 HTML 內容的 docx 文檔。 這是我的 document.xml 正文的樣子:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<w:document ...xmlns declarations.. mc:Ignorable="w14 w15 w16se w16cid w16 w16cex w16sdtdh wp14">
<w:body>
<w:p w14:paraId="43132D41" w14:textId="3A8DC205" w:rsidR="00940BB3" w:rsidRDefault="00772215">
<w:r>
<w:t>Hello</w:t>
</w:r>
</w:p>
<w:sectPr w:rsidR="00940BB3">
<w:headerReference w:type="even" r:id="rId7"/>
<w:headerReference w:type="default" r:id="rId8"/>
<w:footerReference w:type="even" r:id="rId9"/>
<w:footerReference w:type="default" r:id="rId10"/>
<w:headerReference w:type="first" r:id="rId11"/>
<w:footerReference w:type="first" r:id="rId12"/>
<w:pgSz w:w="12240" w:h="15840"/>
<w:pgMar w:top="1440" w:right="1440" w:bottom="1440" w:left="1440" w:header="708" w:footer="708" w:gutter="0"/>
<w:cols w:space="708"/>
<w:docGrid w:linePitch="360"/>
</w:sectPr>
</w:body>
</w:document>
rId8
header 指的是 header2.xml,它看起來像這樣:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<w:hdr ...lots of xmlns... mc:Ignorable="w14 w15 w16se w16cid w16 w16cex w16sdtdh wp14">
<w:p w14:paraId="775C4615" w14:textId="387F538F" w:rsidR="00772215" w:rsidRDefault="00772215">
<w:pPr>
<w:pStyle w:val="Header"/>
</w:pPr>
<w:r>
<w:t>The Header</w:t>
</w:r>
</w:p>
<w:p w14:paraId="746D41E6" w14:textId="77777777" w:rsidR="00772215" w:rsidRDefault="00772215">
<w:pPr>
<w:pStyle w:val="Header"/>
</w:pPr>
</w:p>
<w:altChunk r:id="htmlchunk"/>
</w:hdr>
而htmlchunk
指的是一個簡單的 html 文件:
<!DOCTYPE html>
<html>
<body><b>Real HTML</b></body>
</html>
這是這些引用在 document.rels.xml 中的樣子:
<Relationship Id="htmlchunk" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/aFChunk" Target="htmlchunk.html"/>
<Relationship Id="rId8" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/header" Target="header2.xml"/>
當嘗試在 MS Word 中打開生成的文檔時,它會嘗試修復文檔,然后顯示 header “標頭”部分,而沒有 html 內容。 嘗試使用 OOXMLValidator 驗證文檔時,它顯示此錯誤:
[{"Description":"The relationship 'htmlchunk' referenced by attribute 'http://schemas.openxmlformats.org/officeDocument/2006/relationships:id' does not exist.","Path":{"NamespacesDefinitions":["xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\""],"Namespaces":{},"XPath":"/w:hdr[1]/w:altChunk[1]","PartUri":"/word/header2.xml"},"Id":"Sem_InvalidRelationshipId","ErrorType":"Semantic"}]
我怎么解決這個問題? header xml 文件如何引用其他塊?
要引用由"htmlchunk"
標識的部分,該部分必須添加到header2.xml
部分(在您的示例中為 header2.xml )而不是主文檔部分( document.xml
)。 這意味着Relationship
元素不會在document.xml.rels
中找到,而是在header2.xml.rels
中找到。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.