We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

MailMerge.Execute - word doc with 2 page columns

Hi,

I have a word doc with 2 columns and i am trying to mailmerge the datasource so it fills the left column, then the right column, and then move to next page, and so on...

I can achieve this using MS Word mail merge, but my code (which works great until this 2 column issue) ignores he right column ?

I have read some forum replies where Regions are used, but i am purely using MS Word for the template design , and aspose code to merge.

Am i missing something obvious ?

Please can you help or offer some guidance

Many Thanks, Mark

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. Could you please attach your template and provide me sample code, which will allow me to reproduce this problem. I will check it and provide you more information.

Best regards,

Hi

Thanks for the swift response.

I have attached my mw word template.

The code to generate the mail merge is simply

doc.MailMerge.Execute(myProc)

where myproc is my datatable

Thanks

Mark

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for additional information. I have changed your template document. Please try using the following code to fill this document with data:

// Create dummy datasource.

DataTable data = new DataTable("Numbers");

data.Columns.Add("tel_no");

// Add few rows.

for (int i = 0; i < 200; i++)

data.Rows.Add(new object[] { "123-456-"+i.ToString() });

Document doc = new Document(@"Test\WA_00012.dot");

doc.MailMerge.ExecuteWithRegions(data);

doc.Save(@"Test\out.doc");

Please see the attached template document and produced output.

Best regards,

Hi

Still cant get this to work..

It still goes onto 1 column

Thanks

Mark

Hi Mark,

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for additional information. Could you please also attach your output document here? We will check it and provide you more information.

Also, it would be great if you create a simple application, which will allow to reproduce the problem.

Best regards,

Hi,

Using your code, i can get the data to merge to columns , which is great...

But now the issue is that when i insert this document into another document, it displays as only 1 column ?

I am using the following code to insert the merged 2 columns document into another document...

Private Sub InsertDocument(ByVal insertAfterNode As Node, ByVal srcDoc As Document)
' We need to make sure that the specified node is either paragraph or table.
If Not ((insertAfterNode.NodeType = NodeType.Paragraph) OrElse (insertAfterNode.NodeType = NodeType.Table)) Then
Throw New ArgumentException("The destination node should be either paragraph or table.")
End If

' We will be inserting into the parent of the destination paragraph.
Dim dstStory As CompositeNode = insertAfterNode.ParentNode

' This object will be translating styles and lists during the import.
Dim importer As NodeImporter = New NodeImporter(srcDoc, insertAfterNode.Document, ImportFormatMode.KeepSourceFormatting)
' Loop through all sections in the source document.

For Each srcSection As Aspose.Words.Section In srcDoc.Sections
' Loop through all block level nodes (paragraphs and tables) in the body of the section.
For Each srcNode As Node In srcSection.Body
' Do not insert node if it is a last empty paragarph in the section.
Dim para As Aspose.Words.Paragraph = TryCast(srcNode, Aspose.Words.Paragraph)
If (Not para Is Nothing) AndAlso para.IsEndOfSection AndAlso (Not para.HasChildNodes) Then
Exit For
End If
' This creates a clone of the node, suitable for insertion into the destination document.
Dim newNode As Node = importer.ImportNode(srcNode, True)
' Insert new node after the reference node.
dstStory.InsertAfter(newNode, insertAfterNode)
insertAfterNode = newNode
Next srcNode
Next srcSection
End Sub

Thanks

Mark

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for additional information. As you can see InsertDocument method just insert content of Section, but does not preserve Section. So settings of sections are not preserved upon inserting. That is why TextColumns are lost.

As a simple workaround, try using Document.AppendDocument method to append one document to another. In this case, settings of sections will be preserved.

Best regards,

Hi,

Many Thanks again for your help.

But...what am i replacing with Document.AppendDocument ?

Do i replace the whole InsertDocument Sub ?

Thanks

Also, i can only find AppendChild

Mark

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for additional information. Maybe you are using some old version of Aspose.Words and that is why you do not have AppendDocument method. If so, please follow the link to learn how to achieve the same:

http://www.aspose.com/documentation/.net-components/aspose.words-for-.net/howto-join-and-append-documents.html

Best regards,

Many Thanks, That sorted it

Mark