set Header=$$Line("Sequence\HeatNo\Calalogue\First\Surname\Bisca No\LeftHand\Flexible\Country\Exhibitor No")

set NewFileName=$p(Target_"\"_$$$NewDocument(PageTitle),".",1)_".csv"
        set File=##class(abc.file.FlatFile).%New(),xcount=0
        do File.WriteLine(Header)

set Seq=Seq+1,Line=Seq_"\"_$lg(ExportData,12)_"\"_CatNo_"\"_$lg(ExportData,3)_"\"_$lg(ExportData,4)_"\"_$lg(ExportData,16)_"\"_$lg(ExportData,18)_"\"_$lg(ExportData,17)_"\"_$lg(ExportData,15)_"\"_$lg(ExportData,10)
        set Data=$$Line(Line) do File.WriteLine(Data)

do File.SaveFile(NewFileName)
    kill File            
    Q

Line(str)
    set ln=$l(str,"\"),New=""
    for lp=1:1:ln set New=New_$c(34)_$p(str,"\",lp)_$c(34,44)
    quit $e(New,1,$l(New)-1)
    q str

Procedure

build the Taget folder and make sure that the file Name is legal and ends in.csv

I built my row (line) data with a delimitor "\"

then I pass this through the $$Line(Line)

1) open the file and add a header to identify the columns

2) loop down the data build the Line of data and file the 'do file.WriteLine(Line)' for each row

3) Close the file and kill the file object