Mail Merge with Table in Word Template

postsauravpostsaurav Member Posts: 708
edited 2014-07-28 in NAV Three Tier
Dear all,

During a upgrade process i came across a codeunit which is used for mail merge using word automation. I was able to add fields using Dotnet Variables related to word. But in later part the Merged Document Contain a table and i am unable to find dotnet automation and code for same.

Below is the sample example.
I want Customer Name from Customer Tables & All Customer Ledger Entries details for that customer. Below is the code -

Code in NAV 2009 Using Automation -
wdRange := wdApp.ActiveDocument.Fields.Item(1).Result;
wdRange.Text := FORMAT(Customer.Name);

Code Upgraded in NAV 2013 using Dotnet -
AddField('Customer_Name');
AddField(Customer.Name);

Code in NAV 2009 Using Automation - (I am unable to upgrade this part)
wdTable := wdDoc.Tables.Add(wdRange,1,2);
 RowCounter := 1;
 wdTable.Rows.Height := 20;
 wdTable.PreferredWidth := 500;
 wdTable.Cell(1,1).PreferredWidth := 150;
 wdTable.Cell(RowCounter,1).Range.Text := PostingDate;
  wdTable.Cell(RowCounter,1).Range.Bold := 1;
  wdTable.Cell(RowCounter,1).Range.Underline := 1;
  wdTable.Cell(RowCounter,2).Range.Text := CustLedEntry."Posting Date";
  wdRow := wdTable.Rows.Add;
  RowCounter += 1;
....

Please suggest the possible ways to upgrade the second part of code when its creating a table and inserting data into the table.

Thanks in advance.

Thanks & Regards,
Saurav Dhyani

Do you Know this About NAV?


Connect - Twitter | Facebook | Google + | YouTube

Follow - Blog | Facebook Page | Google + Page

Answers

  • sailorsailor Member Posts: 15
    Hi,

    You can use html tags for this. Try this code:
      WordMergefile.OpenNewMultipleValueField;
      WordMergefile.AddDataToMultipleValueField('Line 1');
      WordMergefile.AddDataToMultipleValueField('<table border="1">');
      WordMergefile.AddDataToMultipleValueField('<tr><td>Table cell 1.1</td><td>Table cell 1.2</td></tr>');
      WordMergefile.AddDataToMultipleValueField('<tr><td>Table cell 2.1</td><td>Table cell 2.2</td></tr>');
      WordMergefile.AddDataToMultipleValueField('</table>');
      WordMergefile.AddDataToMultipleValueField('Line 2');
      WordMergefile.CloseMultipleValueField;
    
  • postsauravpostsaurav Member Posts: 708
    Hi sailor,

    Thanks for the reply and sorry for delay in update as i was able to use HTML Tag already.

    But with HTML it comes with certain limitation in HTML Tags -

    1. Like i cannot specify the BOLD, ITALICS in the HTML Table Column.

    Thanks & Regards,
    Saurav Dhyani

    Do you Know this About NAV?


    Connect - Twitter | Facebook | Google + | YouTube

    Follow - Blog | Facebook Page | Google + Page
  • sailorsailor Member Posts: 15
    Did you manage to get the formatting done? I tried as well to get text bold, underline or italic, but normal html tags didn´t work.

    Also, I tried bulletin, indention or right aligned text but this doesn´t work either. Does anybody know a solution to this?
Sign In or Register to comment.