Save csv file in utf8 with BOM

Save csv file in utf8 with BOM

Postby Giovany Vecchi » Wed Sep 06, 2023 7:32 pm

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
 
User avatar
Giovany Vecchi
 
Posts: 207
Joined: Mon Jun 05, 2006 9:39 pm
Location: Brasil

Re: Save csv file in utf8 with BOM

Postby cnavarro » Thu Sep 07, 2023 4:54 am

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)

 
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6500
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: Save csv file in utf8 with BOM

Postby Giovany Vecchi » Thu Sep 07, 2023 11:23 am

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
 
User avatar
Giovany Vecchi
 
Posts: 207
Joined: Mon Jun 05, 2006 9:39 pm
Location: Brasil


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 87 guests