How to quickly create a table from data

Top  Previous  Next

Lets assume you have an application with a database grid (dbgrid) which displays filtered data.

 

Now you have the demand to create a good looking table which can be also printed or exported. Even copy&paste to Excell is possible. The table cells (except for summary cells) use templates to store the paragraph attributes.

 

You do not need a lot of code to do so, only an object of class TWPTableProducerDB and the output TWPRichText.

 

1) Set up data source link in

  WPTableProducerDB1.DataSourceLink.

  Simply create one item with a reference to a TDataSource.

  The elements Masterfields and UIDFieldname are not required for now.

  The name may be "DBMASTER".

 

2) Then double click on WPTableProducerDB1. The navigator will pop up.

   Click on '+' to create a first block element.

   Click on the new line to activate it in the IDE.

   Now change to the Object inspector (F11)

 

3) Select the name of the data source link in the property DataSourceName

 

4) Add some columns after clicking on '...' here

    clip0032

    and choose the data field you want to list.

 

You can activate the navigator any time to quickly locate any of the template items without having to open multiple nested collections.

 

 

Now you can already create the table - only one line of code is required:

 

   WPTableProducerDB1.CreateReportTable( WPRichText1 );

 

 

Well, this is a very simple table. But a start.

Now you can work with the styles fro the cells.

 

In each of the column item you can create style entries in the collection Styles. Using the element Condition you can select  if the style should be used for header, footer or data in this column. If you want to create a style for multiple columns aat once you can use the Styles collection of the 'Block'.

 

Please note that you usually need to set the condition wpcondTemplate.