I am trying to create and send a csv file by email. However, in the output csv file, I am having trouble reading special characters such as "è", "à", "ù" or "ç".
My original idea was to use the built-in function Transform list like this:
Code: Select all
#FilePathMat := '/LANSA_ptdpgmlib/tmp/' + "CmdMateriel.csv"
#CITI01CMDLIB := 'Id Categorie,Categorie,Id Materiel,Materiel,Quantite'
Add_Entry To_List(#CmdHC)
Use Builtin(Transform_List) With_Args(#CmdHC #FilePathMat SU B T '.' N) To_Get(#IO$STS)
Clr_List Named(#CmdHC)
Select_Sql Fields(#CITI01CTMACH #CITI01LBCTMC #CITI01CDMACH #CITI01LBMACH #CITI01QTEMAT) Using(#SQLQUERY)
* #CITI01LBCTMC := #com_owner.CleanString( #CITI01LBCTMC )
* #CITI01LBMACH := #com_owner.CleanString( #CITI01LBMACH )
Add_Entry To_List(#ListGetMat)
Endselect
Use Builtin(Transform_List) With_Args(#ListGetMat #FilePathMat SU B T) To_Get(#IO$STS)
I then wanted to try and add the BOM to my file before inserting my data like this:
Code: Select all
Define_Com Class(#PRIM_IOC.FileStream) Name(#FileStream) Fileaccess(Write) Filemode(CreateNew) Fileshare(Write)
Define_Com Class(#PRIM_DC.UnicodeString) Name(#CsvContent)
#FilePathMat := '/LANSA_ptdpgmlib/tmp/' + "CmdMateriel.csv"
* Open FileStream
#FileStream.Path := #FilePathMat
* Write BOM to the file
#FileStream.WriteBytes('EFBBBF') * Using the property ('EFBBBF').AsBytes would be the ideal candidate but it does not exist.
* Add CSV Header
#CsvContent := 'Id Categorie,Categorie,Id Materiel,Materiel,Quantite' + (10).AsUnicodeString
#FileStream.WriteChars(#CsvContent)
* Add CSV Data
Select_Sql Fields(#CITI01CTMACH #CITI01LBCTMC #CITI01CDMACH #CITI01LBMACH #CITI01QTEMAT) Using(#SQLQUERY)
#CsvContent := ('&1,&2,&3,&4,&5' + (10).AsUnicodeString).Substitute(#CITI01CTMACH #CITI01LBCTMC #CITI01CDMACH #CITI01LBMACH #CITI01QTEMAT.AsString)
#FileStream.WriteChars(#CsvContent)
Endselect
* Attach the file to email
Use Builtin(MAIL_ADD_ATTACHMENT) With_Args(#FilePathMat 'CmdMateriel.csv') To_Get(#LEM_RETC)
Thank you for your help,
Kind regards,
Romain