How to convert html from emails into text?

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
HGAutomator
Posts: 197
Joined: Thu Jul 16, 2020 5:42 pm
DBs Used: DBF

How to convert html from emails into text?

Post by HGAutomator »

Hi,

I'm converting a whole bunch of Thunderbird emails into eml files, then into .csv, then into Excel, the into DBf format.

I've done all this so far, but of course the body of the email is littered with html codes.

How can I strip all the html out, and leave only text? I can probably replace <br> with character returns and line feeds, but I'd like to strip out all of the html in each body memo field into text.
edk
Posts: 999
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: How to convert html from emails into text?

Post by edk »

It is quite simple:

Code: Select all

Function HTMLToPlainText ( cHTML )
   Local oHTMLDoc := CreateObject( "HTMLFile" )
   Local cPlainText
   
   oHTMLDoc:Write ( cHTML ) 
   cPlainText := oHTMLDoc:body:innerText
   oHTMLDoc := Nil
RETURN cPlainText
HGAutomator
Posts: 197
Joined: Thu Jul 16, 2020 5:42 pm
DBs Used: DBF

Re: How to convert html from emails into text?

Post by HGAutomator »

I'll give it a try, thanks edk.
User avatar
serge_girard
Posts: 3309
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: How to convert html from emails into text?

Post by serge_girard »

Thanks Edward, this is what I also needed !

Serge
There's nothing you can do that can't be done...
Post Reply