Page 1 of 1

Save csv file in utf8 with BOM

PostPosted: Wed Sep 06, 2023 7:32 pm
by Giovany Vecchi
The characters are in the utf8 standard, but when I import it into a third-party system, it says that the file is not utf8.

Does anyone have a solution?

Code: Select all  Expand view

Method N_SignoCepLayout_BuildAll(f_cFileCvsSalva)
   Local lc_cFileCvsConteudo := ""

   ::N_SignoCepLayout_CabecalhoBuild()

   lc_cFileCvsConteudo     := ::cCabecalhoCampos + CRLF
   lc_cFileCvsConteudo     += ::cTxtOcorrenciasAll

   hb_MemoWrit(f_cFileCvsSalva,hb_StrToUTF8(lc_cFileCvsConteudo))

Return Nil
 

Re: Save csv file in utf8 with BOM

PostPosted: Thu Sep 07, 2023 4:54 am
by cnavarro
What characters do you add in the header?
Please, try
Code: Select all  Expand view


.../...
   lc_cFileCvsConteudo     := ::cCabecalhoCampos //+ CRLF
   lc_cFileCvsConteudo     += hb_StrToUTF8(::cTxtOcorrenciasAll)

   hb_MemoWrit(f_cFileCvsSalva,lc_cFileCvsConteudo)

 

Re: Save csv file in utf8 with BOM

PostPosted: Thu Sep 07, 2023 11:23 am
by Giovany Vecchi
Hello Cristobar. I already solved it by applying the header to utf8 BOM

Code: Select all  Expand view

Method N_SignoCepLayout_BuildAll(f_cFileCvsSalva)
   Local lc_cFileCvsConteudo := ""
   Local lc_cUtf8Header := ""

   ::N_SignoCepLayout_CabecalhoBuild()

   lc_cFileCvsConteudo     := ::cCabecalhoCampos + CRLF
   lc_cFileCvsConteudo     += ::cTxtOcorrenciasAll

   lc_cUtf8Header := chr(239)+chr(187)+chr(191) //Header utf8 with BOM

   hb_MemoWrit(f_cFileCvsSalva,lc_cUtf8Header+hb_StrToUTF8(lc_cFileCvsConteudo))

Return Nil