FNC WX Docx: Generating Word documents made easy!
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.
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