How to export selected columns of a list/grid to a file

Date:

4 November 2005

Product/Release:

Visual LANSA V11

Abstract:

How to export specific columns from a list/grid (Version 11 only)

Submitted By:

LANSA Technical Support

The Transform_List BIF is very useful for saving data from lists into files for later retrieval or for use by other programs (such as Microsoft Excel). However one drawback is that it will always export all columns from the list without the ability to exclude unwanted columns. One option is to define a second list which contains only the necessary columns and populate that from the full list before exporting to file.

However if you want to allow your users to select the columns which are to be exported/excluded dynamically, there is a simple way of doing this using some of the new intrinsic functionality from V11.

In the above example there are 3 columns that can be hidden and shown by selecting the checkboxes on the right. The interesting part about this is that when you press the 'Transform to file' button only the visible columns will be exported.

The way this works is to create a temporary list containing one large char field capable of storing the contents of all 3 columns. The Grid is read and for each row only the visible columns are appended to the large text field. The field contents are appended with a TAB character placed between them.

Then the Transform_List BIF is then called for the temporary list and 'I' is specified for the Unexpected Characters parameter. This causes unexpected characters (in this case the TAB characters) to be written directly to the output file without any correction. The result is a file with (possibly) multiple tab delimited columns, which are treated correctly as separate columns in Excel.

This is a simple example however the concept can easily be extended to provide more useful functionality.

In order to create the above example perform the following in version 11.0;

Create a form and ensure that the component or partition is enabled for full RDMLX