Welcome to OpenXML Developer Sign in | Join | Help

AltChunk

Last post 12-08-2008, 3:28 AM by sandra. 6 replies.
Sort Posts: Previous Next
  •  06-25-2007, 12:27 PM 1695

    AltChunk

    Hi All,

    I am trying to include a htm file into a docx.

    I have done a lot of tests, but I am not able to see the content of the htm file into Word 2007 (MS office pro). I have no more ideas...

    No error message. The document is empty.

    I have build a very simple document.
    Can anybody download my docx file and find what is missing in files ?
    Here is the link : http://comptes.ergole.fr/christophe/mydocx.zip
    Rename it to .docx if you want to open it with Word.

    Thanks.

     

  •  07-10-2007, 5:24 AM 1737 in reply to 1695

    Re: AltChunk

    There were couple of errors in your xml files
     
    1. html file is in word folder, but relationship file target mentioned as test.html instead of /word/test.html
    2. In document.xml file, instead of having xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships, it was xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships/AFChunk
     
    Or else, follow these steps to create a docx file containing altchunk
     
    Create a document.xml having the following contents (small to make it simple)
     

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <w:document xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"
              xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
      <w:body>
        <w:altChunk r:id="rId1" />
      </w:body>
    </w:document>
     

    Add a relationship to the html file
     
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
    <Relationship Id="rId1"
    Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/aFChunk" Target="test.html"
    TargetMode="Internal"/>
    </Relationships>
     
    Create an html file containing the following text
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
     <head>
      <title></title>
     </head>
     <body>
     This is to test altchunk feature in OpenXML file format
     </body>
    </html>
     
    In the content types file, add the following line
    <Default Extension="html" ContentType="text/html" />
     

    Zip all relevant files, rename it to <name>.docx, you will see the content placed in html file on document
  •  12-27-2007, 11:18 AM 2549 in reply to 1737

    Re: AltChunk

    Note : Files generated with Altchunk content can only be opened in Word 2007!  So, if you're experimenting with this on Word 2003 with the converter plugin, like I am.. you're not going to have any luck.

    PS.  Great work guys! This is going to silver-bullt my problem of trying to insert HTML, XHTML into a Word Doc; I should be able to combine that HTML then with Headers and Footers in Word (in a pre-built setup) and it will rock!

    P.P.S Here are some more relevant materials :

    http://openxmldeveloper.org/forums/477/ShowThread.aspx#477
    http://blogs.msdn.com/brian_jones/archive/2006/08/08/692705.aspx


    Director of Technology
    Express Dynamics, the WorkXpress company
    http://www.workxpress.com
  •  12-31-2007, 10:22 AM 2566 in reply to 1737

    Re: AltChunk

    Since I couldn't find a step by step on how to add HTML to a Word Doc (DOCX - Open XML) in 2007 programatically; I decided to write one.

    Here's a revised copy of myDoc.zip which is a complete version of what the OP is trying to get working, with the twist that it's complete, and works.  So, if you want to see a very simple sample that uses HTML to populate the documents body, check that out.

    In my case, I had a client that wanted to attach a Header, Footer and Watermark to reports I was generating with HTML, in Word.  So, I started by finalizing the Header, Footer and Water mark with them, and creating a Word Doc that had ONLY that Header, Footer and Watermark on it.  A Template, of sorts.

    Then, I saved that as a Word 2007 doc (.docx), unzipped it, and started working.

    The changes I made are below, in red.

    TemplateDoc/[Content_Types].xml

    <Types>
    <Default Extension="xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml"/>
    <Default Extension="html" ContentType="text/html"/>
    <Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>
    </Types>

    NEW FILE : TemplateDoc/word/test.html
    <html>
    <head>
    <title>tourisme</title>
    </head>
    <body>
    Hello
    </body>
    </html>


    TemplateDoc/word/_rels/document.xml.rels
    <?xml version="1.0" encoding="utf-8"?>
    <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
    <Relationship Id="rId1000" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/aFChunk" Target="test.html"/>
    </Relationships>

    TemplateDoc/word/document.xml (At the location where I wanted my HTML)
      <w:body>
        <w:altChunk r:id="rId1000" />
      </w:body>

    Then, I zipped the contents of TemplateDoc, changed the extension to .docx and opened it with Word... BAM!  My HTML contents are in the body of the document, and the headers, footers and watermark are still in tact!

    Director of Technology
    Express Dynamics, the WorkXpress company
    http://www.workxpress.com
  •  07-20-2008, 3:42 AM 3484 in reply to 2566

    Re: AltChunk

    Hi! I am not able to download the zip file you linked to - is it still available?
    Thanks!
    Renee
  •  10-09-2008, 7:53 PM 3775 in reply to 3484

    Re: AltChunk

    This seemed to be very useful in my project. Ideally I would try to have another docx to be processed in this way. Then I tried using a html file.

    I tried to do the same thing as described here.
    1. I created a very small docx file with 2/3 lines written using MSWord.
    2. Save it.
    3.Open the docx using xmlSpy.
    4. Add a html file under /word.
    5. Edit Contents.xml to have the new content type.  <Default Extension="htm" ContentType="application/html"/>
    6.Edit .rels file to include unique relationship
    <Relationship Id="rId1000" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/aFChunk" Target="word/xxx.htm"/>
    7.Edit document.xml and add <w:altChunk r:id="rId1000"/> inside body node.
    8.Save the docx.

    Open the docx file and error in opening. I redo it. This time till step 4 and it does show "error in opening" error. Addition of a new part in the zipped package is not working at all in this straight way. Forget about any xml tag error.

    Can anybody throw an idea?

    Thank you.


  •  12-08-2008, 3:28 AM 3928 in reply to 1695

    Re: AltChunk

    Can this html part use picture which existed and saved as image part in this docx document?
View as RSS news feed in XML