none
Are Altchucks supported in word 2007 RRS feed

  • Question

  • I creates a word document using docx4j which have altchunks, it is opened on Word 2010 and 2013 without any issue but not on Word 2007 version.

    I think Word 2007 has a problem with altchunks.

    How can I resolve this issue? Please help me ASAP.

    Thanks in advance...


    Wednesday, September 21, 2016 6:35 AM

Answers

  • Hello,

    Using the C# code below, I could successfully merge documents in Office 2007.

    Since I am not familiar with Java, so sorry that we couldn’t give any suggestions for your project.

    For your project, I would suggest you post on Java forum.

    Besides, I suggest you use Open XML library if you want to use Altchucks in Office2007.

    Thanks for your understanding.

    Regards,

    Celeste

             string fileName1 = @"C:\Users\Admin\Desktop\Destination.docx";
                string fileName2 = @"C:\Users\Admin\Desktop\Source.docx";
                string testFile = @"C:\Users\Admin\Desktop\Test.docx";
                File.Delete(fileName1);
                File.Copy(testFile, fileName1);
                using (WordprocessingDocument myDoc =
                    WordprocessingDocument.Open(fileName1, true))
                {
                    string altChunkId = "AltChunkId1";
                    MainDocumentPart mainPart = myDoc.MainDocumentPart;
                    AlternativeFormatImportPart chunk =
                        mainPart.AddAlternativeFormatImportPart(
                        AlternativeFormatImportPartType.WordprocessingML, altChunkId);
                    using (FileStream fileStream = File.Open(fileName2, FileMode.Open))
                        chunk.FeedData(fileStream);
                    AltChunk altChunk = new AltChunk();
                    altChunk.Id = altChunkId;
                    mainPart.Document
                        .Body
                        .InsertAfter(altChunk, mainPart.Document.Body
                        .Elements<Paragraph>().Last());
                    mainPart.Document.Save();
                }

    Friday, September 23, 2016 1:34 AM
    Moderator

All replies

  • >>I creates a word document using docx4j which have altchunks, it is opened on Word 2010 and 2013 without any issue but not on Word 2007 version.

     

    If there are any error when opening in Word 2007?

    According to How to Use altChunk for Document Assembly, altchunks are supported in Word 2007.

    Could you please share with us your detail steps to add the altchunks, so that we could try to reproduce and find solution or workaround.

    Thursday, September 22, 2016 2:27 AM
    Moderator
  • hello,

    i am using java and actually i am merging multiple documents in a single document using docx4j.

    my code is as below, it does not work on Word 2007:

     public static void mergeDocx(InputStream s1, InputStream s2, OutputStream os) throws Exception {
            WordprocessingMLPackage target = WordprocessingMLPackage.load(s1);
            insertDocx(target.getMainDocumentPart(), IOUtils.toByteArray(s2));
            SaveToZipFile saver = new SaveToZipFile(target);
            saver.save(os);
        }

        private static void insertDocx(MainDocumentPart main, byte[] bytes) throws Exception {
            AlternativeFormatInputPart afiPart = new AlternativeFormatInputPart(new PartName("/part" + (chunk++) + ".docx"));
            afiPart.setContentType(new ContentType(CONTENT_TYPE));
            afiPart.setBinaryData(bytes);
            Relationship altChunkRel = main.addTargetPart(afiPart);

            CTAltChunk chunk = Context.getWmlObjectFactory().createCTAltChunk();
            chunk.setId(altChunkRel.getId());

            main.addObject(chunk);
        }


    Software Engineer

    Thursday, September 22, 2016 7:51 AM
  • Hello,

    Using the C# code below, I could successfully merge documents in Office 2007.

    Since I am not familiar with Java, so sorry that we couldn’t give any suggestions for your project.

    For your project, I would suggest you post on Java forum.

    Besides, I suggest you use Open XML library if you want to use Altchucks in Office2007.

    Thanks for your understanding.

    Regards,

    Celeste

             string fileName1 = @"C:\Users\Admin\Desktop\Destination.docx";
                string fileName2 = @"C:\Users\Admin\Desktop\Source.docx";
                string testFile = @"C:\Users\Admin\Desktop\Test.docx";
                File.Delete(fileName1);
                File.Copy(testFile, fileName1);
                using (WordprocessingDocument myDoc =
                    WordprocessingDocument.Open(fileName1, true))
                {
                    string altChunkId = "AltChunkId1";
                    MainDocumentPart mainPart = myDoc.MainDocumentPart;
                    AlternativeFormatImportPart chunk =
                        mainPart.AddAlternativeFormatImportPart(
                        AlternativeFormatImportPartType.WordprocessingML, altChunkId);
                    using (FileStream fileStream = File.Open(fileName2, FileMode.Open))
                        chunk.FeedData(fileStream);
                    AltChunk altChunk = new AltChunk();
                    altChunk.Id = altChunkId;
                    mainPart.Document
                        .Body
                        .InsertAfter(altChunk, mainPart.Document.Body
                        .Elements<Paragraph>().Last());
                    mainPart.Document.Save();
                }

    Friday, September 23, 2016 1:34 AM
    Moderator