Blog

All Blog Posts  |  Next Post  |  Previous Post

FNC WX Docx: Generating Word documents made easy!

Tuesday, January 25, 2022

In need of an intuitive way to generate Docx files with Delphi without having to install Microsoft® Word? TMS has you covered! With the latest release of TMS FNC WX Pack, we've added the new TTMSFNCWXDocx component which lets you generate Docx files on all platforms. 

We’ve added a lot of functionality to offer maximum flexibility and allow you to customize the document requirements. 

You can add: 

  • formatted text
  • tables
  • images
  • table of contents
  • headers
  • footers
  • bookmarks
  • links
  • page numbering


Everything you'll need to build your documents. It’s even possible to export the document structure to a JSON template. A template that can easily be modified and used to perform actions like mail merging.

Creating a document

The creation of the document is intuitive. you can work with predefined methods and properties to customize your document. You can see how to create a document in this video:


Building a template

Building a template is as simple as adding the fields you want to edit later and just set the ID of that field. You can later use this ID to search the document for the desired field.

Using a template

After creating a template you can use following code to generate an invoice. This is a code snippet from the advanced demo. This code loops over a dataset and creates for every customer their invoices. 

Customers.First;

  while not Customers.Eof do
  begin
    id := Customers.FieldByName('CustNo').AsInteger;
    AsText(TMSFNCWXDocx1.FindByID('CustNo') as TTMSFNCWXDocxChild).Text := IntToStr(id);
    AsText(TMSFNCWXDocx1.FindByID('Contact') as TTMSFNCWXDocxChild).Text := Customers.FieldByName('Contact').AsString;
    AsText(TMSFNCWXDocx1.FindByID('Company') as TTMSFNCWXDocxChild).Text := Customers.FieldByName('Company').AsString;
    AsText(TMSFNCWXDocx1.FindByID('Phone') as TTMSFNCWXDocxChild).Text :=Customers.FieldByName('Phone').AsString;
    AsText(TMSFNCWXDocx1.FindByID('FAX') as TTMSFNCWXDocxChild).Text := Customers.FieldByName('FAX').AsString;
    AsText(TMSFNCWXDocx1.FindByID('Addr1') as TTMSFNCWXDocxChild).Text := Customers.FieldByName('Addr1').AsString;
    AsText(TMSFNCWXDocx1.FindByID('Addr2') as TTMSFNCWXDocxChild).Text := Customers.FieldByName('Addr2').AsString;
    AsText(TMSFNCWXDocx1.FindByID('Zip') as TTMSFNCWXDocxChild).Text := Customers.FieldByName('Zip').AsString;
    AsText(TMSFNCWXDocx1.FindByID('City') as TTMSFNCWXDocxChild).Text := Customers.FieldByName('City').AsString;
    AsText(TMSFNCWXDocx1.FindByID('Country') as TTMSFNCWXDocxChild).Text := Customers.FieldByName('Country').AsString;
    t := AsTable(TMSFNCWXDocx1.FindByID('Items') as TTMSFNCWXDocxChild);
    toPay := 0;
    orders.Filtered := False;
    Orders.Filter := 'CustNo = ' + IntToStr(id);
    Orders.Filtered := true;
    Orders.First;
    t.Rows.Clear;
    while not Orders.Eof do
    begin
      tr := t.AddRow;
      tc := tr.AddCell;
      p := tc.AddParagraph;
      p.AddText(Orders.FieldByName('ItemNo').AsString);
      tc := tr.AddCell;
      p := tc.AddParagraph;
      p.AddText(Orders.FieldByName('Description').AsString);
      tc := tr.AddCell;
      p := tc.AddParagraph;
      p.AddText(Orders.FieldByName('ItemsTotal').AsString);
      tc := tr.AddCell;
      p := tc.AddParagraph;
      p.AddText(Orders.FieldByName('ItemPrice').AsString);
      tc := tr.AddCell;
      p := tc.AddParagraph;
      p.AddText(Orders.FieldByName('ItemTotalPrice').AsString);
      toPay := toPay + Orders.FieldByName('ItemTotalPrice').AsFloat;
      Orders.Next;
    end;
    AsText(TMSFNCWXDocx1.FindByID('TotalToPay') as TTMSFNCWXDocxChild).Text := FloatToStr(toPay);
    TMSFNCWXDocx1.GetDocxAsFile(TPath.Combine(pth,'Invoice' + IntToStr(id) + '.docx'));
    Customers.Next;
  end;

This will generate the following document on the right from the template on the left.

TMS Software Delphi  Components TMS Software Delphi  Components

Available Today!

The TTMSFNCWXDocx component is available in the latest update, available today. So go ahead and download the latest version of the TMS FNC WX Pack. The TMS FNC WX Pack is part of the FNC family, so as a reminder, below is an overview of what FNC has to offer.

TMS FNC Components can be used simultaneously on these frameworks


TMS FNC Components can be used simultaneously on these operating systems/browsers


TMS FNC Controls can be used simultaneously on these IDEs



Bradley Velghe




This blog post has received 2 comments.


1. Thursday, January 27, 2022 at 5:13:06 PM

It works like magic !

Kamran


2. Wednesday, March 30, 2022 at 10:35:59 AM

Hi! We are looking for a native VCL DocX component and have tried TTMSFNCWXDocx trial. Unfortunately a lot of functionality does not work. For example, cell merging, cell background color, styles. Do you have plans to improve your component in future?

Dmitry Berin




Add a new comment

You will receive a confirmation mail with a link to validate your comment, please use a valid email address.
All fields are required.



All Blog Posts  |  Next Post  |  Previous Post