Skip to main content

I am running FME Desktop 2019.1 and am trying to output the results of a Feature Merger to a csv file but I want to add an additional row in the csv file before I have the column headers

ie

I want the output to look like this:

but I can only get this:

in excel it would look like this:

FORMAT ASSET DETAILS , STANDARD 1.0

 

 

 

 

REGNAMEASSETNBRTMPLASSNBRDESCRLONGDESCRSHORTDESCRASSETTYPEASSETSTATFLEET1000000090000000Sj300 2019 White Ls Colorado 4 X 4 DieseSj300 2019 White Ls Colorado 4 X 4 Diesel (Ranger 4) SJ300Sj300 2019 White Ls SN

 

Is there a way to do this?

Preferred output is csv but if i its do-able to excel that will suffice.

Thanks in advance

Hi @left65

Cant be done out of the box with the writer directly - but writing the CSV first, then reading it as a Text File, adding the first line and then writing it as Text File works: Just make sure that the line created from the Creator + Attributecreator_5 enters the FeatureWriter_3 first - or else it will be at the bottom of the file.


csv_text_header.fmw Hi @left65 Use both a text line and CSV writers, writing to the same CSV file. Write to the text line writer first, then the CSV with the option on the feature type to NOT overwrite the existing file.


Hi @left65​ ,

another alternative is to use the a Python Startup Script:

import fme
import os
 
# Creates variable
fpath = str(fme.macroValues 'Output_FolderName'])
print('fpath: ' + fpath)
 
if not os.path.exists(fpath):
    os.makedirs(fpath)
 
f = open(fpath + "\\OneCommTemplate.csv", "a")
f.write('"FORMAT ASSET , STANDARD 1.0"\n')
f.close()

This will also create the folder path if necessary.

Just set the filename above as the same as the output on the FME Workspace for your CSV file and you'll be good to go.

 

The issue I found was that the file was being locked because it was still being written to. So this method, closes the file when the workspace  first starts.


Reply