About EasyMorph Tutorials & Examples Web-help

Export to Fixed-Width Format

Hi All,
Can anyone advise how I could easily export to a fixed-width format text file instead of delimited?
e.g. Column 1 always 10 chars, Column 2 always 15 chars…
This requirement is still quite common when dealing with older systems and high-volume processing.
(You can see similar functionality in MS Access - Export to Text file)
Thanks for any help!
Regards,
Dave

Hi Dave,

with a bit of preparation you can use the “Export to delimited file” action to produce a fixed-width file. The logic is:

  • append the column headers as the 1st row
  • use function padstart() to pad values with spaces
  • export into a text file without headers and delimiters

See below an example:

export-fixed-width.morph (3.5 KB)

Hi Dmitri,
Thanks for the response.
The Easymorph PAD functions do not seem to cutoff the data at the pad width though? So to format a text field (e.g. address) in Easymorph I would also need a LEFT function as well to make sure the contents never exceeded the defined column width. I will also need to change to PADEND so that any source data is always visible.
Cheers,
Dave

That’s correct, the PAD functions don’t cut off. For cutting off they should be wrapped in a LEFT or RIGHT function.

To learn more about EasyMorph visit easymorph.com.