Page 1 of 1

altChunk

PostPosted: Tue Oct 27, 2009 5:16 pm
by holgerschlegel
Hi,

does anyone knows/has experience on how to add an altChunk tag and relationship to an existing docx document?

What I want to do is to merge one docx document into another docx document at a specific location. One way to let Word 2007 perform the merge of content, styles, ... should be to import the (sub)document using altChunk. Trying to output such a docx document using docx4j works, but the created file can not be opened (opening the created file in Word fails).

What I did so far is:
- create a Relationship to the external docx file (properties TargetMode and Target set)
- add that relationship to the relationships of the main document part of the target package
- create an altChunk element and add it into the body of the target document
Do I miss something?

Regards
Holger

Re: altChunk

PostPosted: Wed Oct 28, 2009 1:17 am
by jason
Hi, I just tried it with a basic HTML document.

The sample, and a couple of fixes can be found in http://dev.plutext.org/trac/docx4j/changeset/955

It should now also work with an embedded docx, but I haven't tried that.

Re: altChunk

PostPosted: Wed Oct 28, 2009 11:57 am
by holgerschlegel
It works for embedded docx files.

Do you know if it is possible to import an external docx file using altChunk elements?
Instead of adding an AlternativeFormatInputPart I've manually created a Relationship and added it to the main document part. Trying to open such a docx results in an error message (document invalid) if opened with Word 2007.

Re: altChunk

PostPosted: Wed Oct 28, 2009 1:08 pm
by jason
holgerschlegel wrote:It works for embedded docx files.


Thanks for the report.

holgerschlegel wrote:Do you know if it is possible to import an external docx file using altChunk elements?
Instead of adding an AlternativeFormatInputPart I've manually created a Relationship and added it to the main document part. Trying to open such a docx results in an error message (document invalid) if opened with Word 2007.


Interesting idea. You did have the TargetMode set to external?

Re: altChunk

PostPosted: Wed Oct 28, 2009 1:14 pm
by holgerschlegel
The TargetMode of the relationship is set to external and the Target to the name of the external docx file to be merged in. I'm not sure what Type I should set for the relationship. Tried Namesspaces.AF and Namespaces.NS_WORD12 but both Word failed to open the document in both cases. Reading some more on the internet suggest that the altChunk syntax only allows internal parts but I did not found any explicit statement about that.

Re: altChunk

PostPosted: Wed Oct 28, 2009 2:45 pm
by jason
You could try "http://schemas.openxmlformats.org/officeDocument/2006/relationships/package"

One other thing, I've used external images a fair bit, with a URL. Sometimes Word 2007 fails to get them (or even ask for them), and then seems to remember/cache its failure, until it is restarted. Not sure whether this would affect what you are trying to do, but restarting Word after a failure might help.

Re: altChunk

PostPosted: Thu Nov 11, 2010 8:53 am
by jason
2.17.3.1 altChunk (Anchor for Imported External Content)

If the relationship type of the relationship specified by this element .. does not have a TargetMode attribute value of Internal, then the document shall be considered non-conformant.


so, not possible :-(