Convert a Windows ANSI flat file to an MS DOS ASCII CSV file
With this example we wish to demonstrate how easy it is to convert text files to other formats (codepages and locales) with the TextFile Adapter and at the same time perform dynamic calculations.
With this example we wish to demonstrate how easy it is to convert text files to other formats (codepages and locales) with the TextFile Adapter and at the same time perform dynamic calculations. You can open the example directly in FlowHeater using the menu option "Examples->TextFile Adapter->Windows ANSI FlatFile to ASCII". You can see it done the other way around (ANSI to ASCII) here.
Note: The same procedure is used to convert to UNICODE (utf7, utf8, ...), EBCDIC, etc.
We have a Windows ANSI flat file and for a supplier in the States (USA) we want to prepare an MS DOS ASCII CSV text file. The date format is to be in the American form of m.d.yyyy (i.e. month.day.year). The supplier wants numbers in the following format: $1,000.23 and that means the decimal character is a point, the thousand-separator a comma and the currency symbol a dollar sign. The character set for our file will additionally be converted from ANSI Codepage 1252 to MS DOS Codepage 437.
What we have to do
On the READ (left) side
- open the Configurator for the READ Adapter (left) side
- for the filename enter "ansi-flatfile.txt"
- check the checkbox "First row contains field names" and reply to the query as to whether the field names should be loaded from the file with "no"
- ensure that the codepage "1252, Windows-1252,Westeuropäisch (Windows)" is selected
- select under the delimitation radio options "fixed widths"
- click in the lower area with the mouse on the sliders in order to adjust the sliders to match the field divisions visually. Alternatively, you can manually specify the field widths/lengths by switching to the "Fields / Data types" tab
- switch to the "Fields / Data types" tab and assign some suitable names to the fields
That is all for this side.
On the WRITE (right) side
- open the Configurator for the WRITE (right) side
- for the filename enter something like "output.txt", for example
- check the checkbox "First row contains field names"
- choose for codepage "437, IBM 437,OEM United States"
- switch to the "Separators" tab and choose as the CSV separator string "abc"
- switch to the "Fields / Data types" tab and insert the following fields, including the specified FlowHeater data types
That is all for this side.
Now all we need is to connect the individual fields together and introduce a handful of Heaters in between. How to do this is described in the Hello World (1, 2, 3) examples, or simply inspect the completed Definition provided in the FlowHeater examples directory.