Free Support Forum - aspose.com

Aspose Word trashes the format of our our two column document

I use Aspose.Words for Java 11.7.0.
I encountered the same issues.
Could anyone provide the solutions?

Thanks a lot.

Hi
Vince,


Thanks for your inquiry. Could you please share more details about your problem and attach your input documents (.doc/.rtf files) here for testing? I will investigate the issue on my side and provide you more information.

Best Regards,

Hi Awais:

Attahcment is my input documents (Source1, Source2), and preferred out and actual out.

Thanks for your help.

Regards,

Vince

Hi Vince,


Thanks for your inquiry and sorry for the delayed response. Please use the following code snippet to achieve this:

Document dstDoc = new
Document(@“C:\test\Source1.docx”);

Document srcDoc = new Document(@"C:\test\Source2.docx");

Paragraph targetPara = dstDoc.FirstSection.Body.LastParagraph;

InsertDocument(targetPara, srcDoc);

targetPara.Remove();

dstDoc.Save(@"c:\test\out.docx");


static void InsertDocument(Node insertAfterNode, Document srcDoc)

{

// Make sure that the node is either a paragraph or table.

if ((!insertAfterNode.NodeType.Equals(NodeType.Paragraph)) &

(!insertAfterNode.NodeType.Equals(NodeType.Table)))

throw new ArgumentException("The destination node should be either a paragraph or table.");

// We will be inserting into the parent of the destination paragraph.

CompositeNode dstStory = insertAfterNode.ParentNode;

// This object will be translating styles and lists during the import.

NodeImporter importer = new NodeImporter(srcDoc, insertAfterNode.Document, ImportFormatMode.KeepSourceFormatting);

// Loop through all sections in the source document.

foreach (Section srcSection in srcDoc.Sections)

{

// Loop through all block level nodes (paragraphs and tables) in the body of the section.

foreach (Node srcNode in srcSection.Body)

{

// Let's skip the node if it is a last empty paragraph in a section.

if (srcNode.NodeType.Equals(NodeType.Paragraph))

{

Paragraph para = (Paragraph)srcNode;

if (para.IsEndOfSection && !para.HasChildNodes)

continue;

}

// This creates a clone of the node, suitable for insertion into the destination document.

Node newNode = importer.ImportNode(srcNode, true);

// Insert new node after the reference node.

dstStory.InsertAfter(newNode, insertAfterNode);

insertAfterNode = newNode;

}

}

}


I hope, this will help.

Best Regards,