简体   繁体   中英

How to insert AltChunk to docx page header?

I'm trying to build a docx document with HTML content in the page headers. This is what my document.xml body looks like:

<?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 refers to header2.xml which looks like this:

<?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>

And htmlchunk refers to a simple html file:

<!DOCTYPE html>
<html>
<body><b>Real HTML</b></body>
</html>

This is how these references look in the 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"/>

When trying to open the resulting document in MS Word, it tries to repair the document and then shows the header "The Header" portion without the html contents. When trying to validate the document with OOXMLValidator, it shows this error:

[{"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"}]

How can I solve this problem? How can the header xml file refer to other chunk?

To reference the part identified by "htmlchunk" , that part must be added to the header part ( header2.xml in your example) rather than the main document part ( document.xml ). This means that the Relationship element would not be found in document.xml.rels but in header2.xml.rels .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM