Got more questions? Find advice on: SQL | XML | Regular Expressions | Windows
in Search
Welcome to AspAdvice Sign in | Join | Help

TX Text Control

News and interesting articles about the word processing component TX Text Control.

Ready-to-use template: Creating invoices using TX Text Control

Creating invoices is certainly one of the most typical applications for TX Text Control. MS Word compatibility, flow type layouts and WYSIWYG template creation are just a few of the wide-ranging advantages over pure reporting tools.

This tutorial shows how to create professional invoices using TX Text Control. You will learn how to create the template using TX Text Control Words and how to use the MailMerge component to create the final invoice.

Data structure

First, let's take a look at the data structure for invoices. Typically, invoice data come from different database tables. The sender is coming from a different table than the addressee. Invoice items are typically loaded from an article database. The following tables are usually required to create an invoice.

company
company_companyname
company_street
company_city
company_country
company_bankname
company_bankaba
company_bankaccount
company_bankswift
company_bankiban
company_phone
company_email
company_www
invoice
invoice_address
invoice_invoicenumber
invoice_intro
invoice_totalnet
invoice_total
invoice_note
invoiceitems
invoiceitem_item
invoiceitem_quantity
invoiceitem_price
invoiceitem_title
invoiceitem_description
invoiceitem_total
taxes
tax_taxname
tax_rate
tax_amount

Creating the template

For this tutorial, we prepared a ready-to-use invoice template you can use, modify or redesign for your purposes. Refer to the documentation to learn how to use TX Text Control Words to create a template from scratch.

The template consists of different parts with dynamic fields, repeating blocks and special fields such as a field to display the current date.

Invoice template

All merge fields from the listed data tables are used and have been added to the above template. The green areas are repeating blocks that will be merged with a list of invoice items and taxes.

Preparing the data

In invoicing modules of ERP systems, the complete invoice is stored in database tables. The resulting PDF or the printout is a specific view of this invoice. The pure invoice data is used for further processing inside the ERP system. This data gathering process is always different and depends on the used databases and the .NET data layer (e.g. ADO.NET).

In our sample, we are using an already merged DataSet in form of an XML file that could have been generated as a database view for real-live scenarios as well.

Merging the document as easy as 1-2-3

All you need to do is to connect a TextControl with the MailMerge component in order to load the template:

TXTextControl.LoadSettings ls = new TXTextControl.LoadSettings(); 
ls.ApplicationFieldFormat = TXTextControl.ApplicationFieldFormat.MSWord; 
 
mailMerge1.TextComponent = textControl1; 
textControl1.Load("invoice.docx", TXTextControl.StreamType.WordprocessingML, ls);

The following code lines are required to merge the document:

DataSet ds = new DataSet(); 
ds.ReadXml("invoice.xml"); 
 
mailMerge1.MergeBlocks(ds); 
mailMerge1.Merge(ds.Tables["invoice"], false);

TX Text Control is looking for the appropriate merge fields in the data automatically in order to merge the fields. The repeating blocks are recognized and merged with the associated DataTables.

A sample data source, a ready-to-use invoice template and a Visual Studio sample project can be downloaded for your own tests.

DownloadDownload Visual Studio 2010 project

How to use the sample?

  1. Download the Visual Studio 2010 project

    Download and open the project in Visual Studio 2010. At least, a TX Text Control .NET for Windows Forms trial version is required.

  2. Start the application

    The template is loaded automatically. You can see different text fields that are not merged yet.

    Creating Invoices using MailMerge
  3. Choose Create from the Invoice menu to start the merge process

    The data is merged into the text fields. Pay attention to the invoice items that are part of a repeating block. These item lines are repeated based on the number of invoice items passed in the data.

    Creating Invoices using MailMerge

As you can see, creating invoices using TX Text Control is a very easy task and has advantages over pure reporting tools. You can easily change your templates in a true WYSIWYG editor or reuse MS Word documents to create your templates.

 

 
TX Text Control was originally released in 1991, since then more than 50,000 copies have been sold. Starting off as a single, small DLL, TX Text Control has made its way through 16-bit DLL and VBX versions to today‘s Enterprise edition with its .NET and ActiveX components. The recent addition to the family, TX Text Control .NET Server, offers all of TX Text Control advanced word processing functionality in an easy-to-use server-side .NET component. Customers benefit from these years of experience, large user base, and at the same time, appreciate developing with a mature, reliable product.
 
 
North & South America: Phone: +1 704-370-0110 Phone: +1 877-462-4772 (toll free)
Europe: Phone: +49 (0)421 42 70 67 10
Asia Pacific: Phone: +886 2-2797-8508

 

Sponsor
Published Friday, February 08, 2013 5:20 AM by Christopher Krause

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

No Comments

Leave a Comment

(required) 
(optional)
(required) 
Enter the code you see below

Submit

This Blog

Syndication