CSV en UTF8 SIN BOM

HMG en Español

Moderator: Rathinagiri

Post Reply
User avatar
edufloriv
Posts: 240
Joined: Thu Nov 08, 2012 3:42 am
DBs Used: DBF, MariaDB, MySQL, MSSQL, MariaDB
Location: PERU

CSV en UTF8 SIN BOM

Post by edufloriv »

Saludos amigos, yo de nuevo por aquí, esperando que todos se encuentren bien junto a sus familiares.

Tengo que enviar la info de los comprobantes de un cliente a un proveedor de servicio electrónico y me lo piden en UTF8 SIN BOM.
Recuerdo que antes solo ponia el .prg en codificación UTF8 SIN BOM (Notepad++) y este generaba el archivo de texto en este mismo formato. Por alguna razón ya no lo hace.

Tengo al inicio de mi programa estos request:

Code: Select all

   REQUEST HB_CODEPAGE_ESWIN
   REQUEST HB_CODEPAGE_ES850
   REQUEST HB_CODEPAGE_UTF8
   REQUEST HB_LANG_ES
   REQUEST HB_LANG_ESWIN
   REQUEST DBFCDX

   RDDSETDEFAULT("DBFCDX")
   HB_SETCODEPAGE("ESWIN")
   HB_LANGSELECT( "ES" )
   SET LANGUAGE TO SPANISH  //Seleciona languaje para interface de mensajes

   DEFINE WINDOW Win_InfoFarma ;
      AT 0,0 ;
      WIDTH  1060 ;
      HEIGHT 740 ;
      TITLE 'CHAMA IMPORT' ;
      FONT "Courier" SIZE 20 ;
      NOMAXIMIZE ;
      ON INIT CargarProg() ;
      MAIN
Luego en el .prg donde creo el CSV esta asi:

Code: Select all

//    CREACION DEL ARCHIVO .CSV
   cFileText := 'CSV\' + SIS_RUC + '-09-' + FRM_DOCNUM + '.CSV'
   HB_SETCODEPAGE("UTF8")
   hb_memowrit( cFileText , hb_StrToUtf8(cText) )
   HB_SETCODEPAGE("ESWIN")
Pero cuando abro el .CSV con el Notepad++ está codificado en ANSI:
utf8-sin-bom.png
utf8-sin-bom.png (56.99 KiB) Viewed 1226 times
Alguien que me tienda una mano por favor. Saludos y gracias anticipadas.

Eduardo Flores Rivas


LIMA - PERU
User avatar
serge_girard
Posts: 3342
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: CSV en UTF8 SIN BOM

Post by serge_girard »

Eduardo,

I use this:

Code: Select all

FERASE(cPHP )
IF !FILE(cPHP)
   fh_dbgen   := FCREATE(cPHP,0)
   cTXT     := HMG_UTF8InsertBOM('')
   nLen	:= FWRITE(fh_dbgen, cTXT) 
   FCLOSE(fh_dbgen)
ENDIF
fh_dbgen := FOPEN(cPHP, FO_READWRITE + FO_SHARED)
FSEEK(fh_dbgen,0,2)    //End Of File
Serge
There's nothing you can do that can't be done...
User avatar
edufloriv
Posts: 240
Joined: Thu Nov 08, 2012 3:42 am
DBs Used: DBF, MariaDB, MySQL, MSSQL, MariaDB
Location: PERU

Re: CSV en UTF8 SIN BOM

Post by edufloriv »

Hi Serge,

Thanks for reply. I made the changes:

Code: Select all

   cFileText := 'CSV\' + SIS_RUC + '-09-' + FRM_DOCNUM + '.CSV'
   FERASE( cFileText )
   IF ! FILE(cFileText)
      fh_dbgen := FCREATE(cFileText,0)
      cTXT     := HMG_UTF8InsertBOM( cText )
      nLen	   := FWRITE( fh_dbgen , cTXT ) 
      FCLOSE(fh_dbgen)
   ENDIF
   fh_dbgen := FOPEN( cFileText , FO_READWRITE + FO_SHARED )
   FSEEK(fh_dbgen,0,2)    //End Of File
But now, this is the result:
utf8-bom.png
utf8-bom.png (60.89 KiB) Viewed 1168 times
I need to format in UTF without BOM. Best regards,

--------------------------------------------------------------------------------

Hola Serge,

Gracias por responder. Hice los cambios:

Code: Select all

   cFileText := 'CSV\' + SIS_RUC + '-09-' + FRM_DOCNUM + '.CSV'
   FERASE( cFileText )
   IF ! FILE(cFileText)
      fh_dbgen := FCREATE(cFileText,0)
      cTXT     := HMG_UTF8InsertBOM( cText )
      nLen	   := FWRITE( fh_dbgen , cTXT ) 
      FCLOSE(fh_dbgen)
   ENDIF
   fh_dbgen := FOPEN( cFileText , FO_READWRITE + FO_SHARED )
   FSEEK(fh_dbgen,0,2)    //End Of File
Pero ahora lo tengo formateado en UTF8 :
utf8-bom.png
utf8-bom.png (60.89 KiB) Viewed 1168 times
Lo necesito formateado en UTF8 SIN BOM. Cordiales saludos.

Eduardo Flores Rivas


LIMA - PERU
User avatar
serge_girard
Posts: 3342
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: CSV en UTF8 SIN BOM

Post by serge_girard »

Eduardo,

Is it the 'numero symbol, №' which is causing problems? More of such symbols? Maybe try to STRTRAN('º', 'o')?

Serge
There's nothing you can do that can't be done...
User avatar
edufloriv
Posts: 240
Joined: Thu Nov 08, 2012 3:42 am
DBs Used: DBF, MariaDB, MySQL, MSSQL, MariaDB
Location: PERU

Re: CSV en UTF8 SIN BOM

Post by edufloriv »

Hi Serge,

I solved !! :D , ok, I proceed to explain. First I change the .PRG to ANSI:
prg-ansi.png
prg-ansi.png (67.87 KiB) Viewed 1159 times
Then I use this:

Code: Select all

// CREACION DEL ARCHIVO .CSV
   cFileText := 'CSV\' + SIS_RUC + '-09-' + FRM_DOCNUM + '.CSV'
   hb_memowrit( cFileText , hb_strtoutf8(hb_ansitooem(cText),'ES850') )
And this is the result:
utf8-sin-bom.png
utf8-sin-bom.png (47.26 KiB) Viewed 1159 times
I hope that this must be useful for someone else. Thank you and a hug.

Eduardo Flores Rivas


LIMA - PERU
Post Reply