Convert tu UTF-8

Convert tu UTF-8

Postby Otto » Mon Feb 25, 2019 5:08 pm

Hello friends,
how can I convert a htm file to UTF-8
Thank you in advance
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6346
Joined: Fri Oct 07, 2005 7:07 pm

Re: Convert tu UTF-8

Postby richard-service » Mon Feb 25, 2019 6:15 pm

Otto wrote:Hello friends,
how can I convert a htm file to UTF-8
Thank you in advance
Otto


Otto,

How about it?
https://onlineutf8tools.com/convert-html-entities-to-utf8
Best Regards,

Richard

Harbour 3.2.0dev (r2402101027) => Borland C++ v7.7 32bit
MySQL v8.0 /ADS v10
Harbour 3.2.0dev (r2011030937) => Borland C++ v7.4 64bit
User avatar
richard-service
 
Posts: 804
Joined: Tue Oct 16, 2007 8:57 am
Location: New Taipei City, Taiwan

Re: Convert tu UTF-8

Postby Carles » Mon Feb 25, 2019 7:09 pm

Otto,

You can use Word. When you need to save, choose save as, and type web

And select button tools, and in Codification folder select Unicode (UTF-8)

Image
Salutacions, saludos, regards

"...programar es fácil, hacer programas es difícil..."

UT Page -> https://carles9000.github.io/
Forum UT -> https://discord.gg/bq8a9yGMWh
Skype -> https://join.skype.com/cnzQg3Kr1dnk
User avatar
Carles
 
Posts: 1139
Joined: Fri Feb 10, 2006 2:34 pm
Location: Barcelona

Re: Convert tu UTF-8

Postby Otto » Mon Feb 25, 2019 7:11 pm

Hello Richard,
thank you.
But I nead a function or a tool with silent mode.
Best regards
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6346
Joined: Fri Oct 07, 2005 7:07 pm

Re: Convert tu UTF-8

Postby Otto » Mon Feb 25, 2019 7:37 pm

Hello Carles,
that's exactly what I need.
Could you please help to find out how to do this with Fivewin code.

My function is like this:

Code: Select all  Expand view  RUN
function saveAsHtml( cDatei )
   local oWord
   local cTemplate   :=  cDatei

   local cHtmlText  := ""

   local cAppPath := cFilePath( GetModuleFileName( GetInstance( ) ) )
   local cSaveAsFile := cAppPath + "Email.htm"
   ferase( cSaveAsFile )

   oWord := CreateObject( "Word.Application" )
   oWord:Documents:Open( cTemplate, 0 )
   oWord:Visible := .T.

   // save it in HTML format
   #define wdFormatHTML 8
   oWord:ActiveDocument:SaveAs2( cSaveAsFile, wdFormatHTML  )
   oWord:ActiveDocument:Close()
   oWord:Quit()

   cHtmlText := memoread( cSaveAsFile )
   cHtmlText := STRTRAN( cHtmlText, "v\:* {behavior:url(#default#VML);}", "" )
   cHtmlText := STRTRAN( cHtmlText, "o\:* {behavior:url(#default#VML);}", "" )
   cHtmlText := STRTRAN( cHtmlText, "w\:* {behavior:url(#default#VML);}", "" )
   cHtmlText := STRTRAN( cHtmlText, ".shape {behavior:url(#default#VML);}", "" )
   //? 'src="' + cAppPath
   cHtmlText := STRTRAN( cHtmlText, 'src="', 'src="' + cAppPath  )

   memowrit( cSaveAsFile, cHtmlText )

return NIL

//----------------------------------------------------------------------------//


Thank you in advance
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6346
Joined: Fri Oct 07, 2005 7:07 pm

Re: Convert tu UTF-8

Postby Otto » Mon Feb 25, 2019 8:18 pm

Hello,
I found this description on the internet and tried with:
But oWord:WebOptions:Encoding = 65001 errors out.
Best regards,
Otto
Code: Select all  Expand view  RUN

oWord := CREATEOBJECT( "Word.Application" )
oWord:Visible := .t.

oWord:ChangeFileOpenDirectory ( cDocPfad )

oWord:Documents:Open( cDocName, 0 , 1 )
//   65001      Microsoft.Office.Core.MsoEncoding.msoEncodingUTF8
oWord:WebOptions:Encoding = 65001
#define wdFormatFilteredHTML    10
oWord:ActiveDocument:SaveAs2( "test.htm", wdFormatFilteredHTML  )
oWord:ActiveDocument:Close()

 



the time of this writing, it is unclear whether I have encountered a bug with my specific version of Microsoft Word (Word Online) or the VSTO template, but I will answer what made this work for me here.

If this code does not work:

doc = app.Documents.Open("C:\\Temp\\Test.docx");
doc.WebOptions.Encoding = Microsoft.Office.Core.MsoEncoding.msoEncodingUTF8;
doc.SaveAs2("C:\\Temp\\Test.htm", MsWord.WdSaveFormat.wdFormatFilteredHTML);

Then, change the code to refresh the document's fields, like this:

doc = app.Documents.Open("C:\\Temp\\Test.docx");

doc.Fields.Update(); // ** this is the new line of code.

doc.WebOptions.Encoding = Microsoft.Office.Core.MsoEncoding.msoEncodingUTF8;
doc.SaveAs2("C:\\Temp\\Test.htm", MsWord.WdSaveFormat.wdFormatFilteredHTML);


msoEncodingUTF8 65001 UTF-8 encoding.
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6346
Joined: Fri Oct 07, 2005 7:07 pm

Re: Convert tu UTF-8

Postby Otto » Mon Feb 25, 2019 8:34 pm

Hello,
this code now is working.
Best regards,
Otto

Code: Select all  Expand view  RUN

oWord := CREATEOBJECT( "Word.Application" )
oWord:Visible := .t.
oWord:ChangeFileOpenDirectory ( cDocPfad )
oWord:Documents:Open( cDocName, 0 , 1 )
oDoc := oWord:ActiveDocument
//   65001      Microsoft.Office.Core.MsoEncoding.msoEncodingUTF8
oDoc:WebOptions:Encoding = 65001
#define wdFormatFilteredHTML    10
oWord:ActiveDocument:SaveAs2( "test.htm", wdFormatFilteredHTML  )
oWord:ActiveDocument:Close()
 


output:

Code: Select all  Expand view  RUN
<html>
<head>
<meta http-equiv=Content-Type content="text/html; charset=utf-8">
<meta name=Generator content="Microsoft Word 15 (filtered)">
 
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6346
Joined: Fri Oct 07, 2005 7:07 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 37 guests