Home > Archive > Programming with dBASE > March 2006 > Text to HTML









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Text to HTML
Rick

2006-03-22, 3:23 am

I need to copy and convert the contents of a memo field to an html file. So far, I plan to copy the memo file contents to a text file with:
form.rowset.fields[?MyMemo?].CopyToFile(?MyNew.htm?)

Then programmatically load this text file into MS Word, and save it as an html file.

Anyone have an idea for a better, easier way.

Thanks for any ideas on this,
Rick

Ken Mayer [dBVIPS]

2006-03-22, 9:23 am

Rick wrote:
> I need to copy and convert the contents of a memo field to an html file. So far, I plan to copy the memo file contents to a text file with:
> form.rowset.fields[?MyMemo?].CopyToFile(?MyNew.htm?)
>
> Then programmatically load this text file into MS Word, and save it as an html file.
>
> Anyone have an idea for a better, easier way.
>
> Thanks for any ideas on this,


Simply use the file object:

f = new file()
f.create( "MyNew.htm" )
f.puts( [<html><head><title>My Memo</title></head><body>] )
f.puts( form.rowset.fields["MyMemo"].value )
f.puts( [</body></html>] )
f.close()

(This code sample is completely untested ... <g> )

Ken

--
/(Opinions expressed are purely my own, not those of dataBased
Intelligence, Inc.)/

*Ken Mayer* [dBVIPS]
/Golden Stag Productions/
dBASE at goldenstag dot net
http://www.goldenstag.net/dbase/dBASEBook.htm
http://www.goldenstag.net/GSP
http://www.goldenstag.net/dbase
Silvio Genco

2006-03-22, 9:23 am

try:

mytext = form.rowset.fields["MyMemo"].value

f = new File()
f.create("test.htm", "RW")
f.puts("<html><head><title>My Title</title></head><body>")
f.puts(mytext)
f.puts( "</body></html>")
f.close()

or

set alternate to test.htm
set alternate on
? "<html><head><title>My Title</title></head><body>"
? mytext
? "</body></html>"
set alternate off
set alternate to
close alternate

Silvio


Michael Nuwer [dBVIPS]

2006-03-22, 11:24 am

Ken Mayer [dBVIPS] wrote:

> f.puts( [<html><head><title>My Memo</title></head><body>] )
> f.puts( form.rowset.fields["MyMemo"].value )
> f.puts( [</body></html>] )


Should work ok for a single paragraph, but multiple paragraphs will be
problamatic.
Rick

2006-03-22, 11:24 am

Ken,

I like this lots better than my plan. But as Michael suggested, I seem to lose all the CR/LF at the end of each paragraph. So the text is all in one line.

Any ideas on how I might retain those?

Thanks,
Rick

Ken Mayer [dBVIPS] Wrote:

> Rick wrote:
>
> Simply use the file object:
>
> f = new file()
> f.create( "MyNew.htm" )
> f.puts( [<html><head><title>My Memo</title></head><body>] )
> f.puts( form.rowset.fields["MyMemo"].value )
> f.puts( [</body></html>] )
> f.close()
>
> (This code sample is completely untested ... <g> )
>
> Ken
>
> --
> /(Opinions expressed are purely my own, not those of dataBased
> Intelligence, Inc.)/
>
> *Ken Mayer* [dBVIPS]
> /Golden Stag Productions/
> dBASE at goldenstag dot net
> http://www.goldenstag.net/dbase/dBASEBook.htm
> http://www.goldenstag.net/GSP
> http://www.goldenstag.net/dbase


Rick

2006-03-22, 11:24 am

Thanks Silvio,

Only problem is I am losing the CR/LF on each paragraph, so the text is all in one line.

Any ideas on how to keep those?

Rick

Silvio Genco Wrote:

> try:
>
> mytext = form.rowset.fields["MyMemo"].value
>
> f = new File()
> f.create("test.htm", "RW")
> f.puts("<html><head><title>My Title</title></head><body>")
> f.puts(mytext)
> f.puts( "</body></html>")
> f.close()
>
> or
>
> set alternate to test.htm
> set alternate on
> ? "<html><head><title>My Title</title></head><body>"
> ? mytext
> ? "</body></html>"
> set alternate off
> set alternate to
> close alternate
>
> Silvio
>
>


Michael Nuwer [dBVIPS]

2006-03-22, 1:24 pm

Rick wrote:
> Ken,
>
> I like this lots better than my plan. But as Michael suggested, I seem to lose all the CR/LF at the end of each paragraph. So the text is all in one line.
>
> Any ideas on how I might retain those?


The following might work:

cString = "are we' "+ chr(13)+chr(10) +" in the correct place?"
oRegExp = new OleAutoClient("VBScript.RegExp")
oRegExp.global := true
oRegExp.Pattern := "\r\n"
x = oRegExp.Replace(cString , "<P>" )
? "<P>"+x
Ken Mayer [dBVIPS]

2006-03-22, 8:25 pm

Michael Nuwer [dBVIPS] wrote:
> Ken Mayer [dBVIPS] wrote:
>
>
>
> Should work ok for a single paragraph, but multiple paragraphs will be
> problamatic.


Well, if the formatting is not in the memo, sure ... <g>

Ken

--
/(Opinions expressed are purely my own, not those of dataBased
Intelligence, Inc.)/

*Ken Mayer* [dBVIPS]
/Golden Stag Productions/
dBASE at goldenstag dot net
http://www.goldenstag.net/dbase/dBASEBook.htm
http://www.goldenstag.net/GSP
http://www.goldenstag.net/dbase
Ken Mayer [dBVIPS]

2006-03-22, 8:25 pm

Rick wrote:
> Thanks Silvio,
>
> Only problem is I am losing the CR/LF on each paragraph, so the text is all in one line.
>
> Any ideas on how to keep those?


See Michael's response. Basically you would need to change them to HTML
<p> tags ...

Ken

--
/(Opinions expressed are purely my own, not those of dataBased
Intelligence, Inc.)/

*Ken Mayer* [dBVIPS]
/Golden Stag Productions/
dBASE at goldenstag dot net
http://www.goldenstag.net/dbase/dBASEBook.htm
http://www.goldenstag.net/GSP
http://www.goldenstag.net/dbase
Rick

2006-03-22, 8:25 pm

Michael,

Question ? do I need a do while loop here or does the global true mean it will replace all occurrences?

I tried this code, and the memo field still appeared with all CR/LF removed (i.e., no paragraphs same as before). I tried using \n by itself, and \r by itself instead of \r\n with the exact same results.

I loaded the resulting html file in word and found the replacement did not take place, i.e., there were no <p> in the html code. So it looks like the replace just never found the CR/LF in the memofield. Maybe there is another designation for this instea
d of \r\n?

Anyway, I?m scratching my head. Hope one of you guys have another idea. I know when I load a text file copied from a memo field into MS word, and save it as html, the paragraphs are retained. But was hoping there would be another way.

My code is below. Thanks for any more ideas you might have.
Rick

cBody= form.rowset.fields[ "EMtext" ].value
oRegExp = new OleAutoClient("VBScript.RegExp")
oRegExp.global := true
oRegExp.Pattern := "\r\n"
x = oRegExp.Replace(cBody , "<P>" )

f = new file()
f.create( cNuFileName )
f.puts( [<html><head><title>My Memo</title></head><body>] )
f.puts( cBody )
f.puts( [</body></html>] )
f.close()


Michael Nuwer [dBVIPS] Wrote:

> Rick wrote:
>
> The following might work:
>
> cString = "are we' "+ chr(13)+chr(10) +" in the correct place?"
> oRegExp = new OleAutoClient("VBScript.RegExp")
> oRegExp.global := true
> oRegExp.Pattern := "\r\n"
> x = oRegExp.Replace(cString , "<P>" )
> ? "<P>"+x


Michael Nuwer [dBVIPS]

2006-03-23, 3:26 am

Rick wrote:
>
> Question ? do I need a do while loop here or does the global true mean it will replace all occurrences?


Correct, all occurrences are replaced with the global property.

> cBody= form.rowset.fields[ "EMtext" ].value
> oRegExp = new OleAutoClient("VBScript.RegExp")
> oRegExp.global := true
> oRegExp.Pattern := "\r\n"
> x = oRegExp.Replace(cBody , "<P>" )


In the line above "cBody" is not modified. The modified string is in "X"


> f.puts( cBody )


f.puts( X ) should work in place of the line above.

Silvio Genco

2006-03-23, 7:30 am

save form.rowset.fields["MyMemo"].value to mymemo.txt
fm = new File( )
fm.open( "mymemo.txt")

f = new File()
f.create("test.htm", "RW")
f.puts("<html><head><title>My Title</title></head><body>")

do while not fm.eof( ) // scan mymemo.txt and replace the line breaks with
<BR>
mytext += fm.gets( ) + "<BR>" // Write lines to HTML component
enddo
fm.close( )

f.puts(mytext)
f.puts( "</body></html>")
f.close()


Silvio




"Rick" <Sportman7@netzero.com> ha scritto nel messaggio
news:L2ftFYdTGHA.2320@news-server...
> Thanks Silvio,
>
> Only problem is I am losing the CR/LF on each paragraph, so the text is

all in one line.
>
> Any ideas on how to keep those?
>
> Rick
>
> Silvio Genco Wrote:
>
>



Ivar B. Jessen

2006-03-23, 1:24 pm

On Tue, 21 Mar 2006 23:11:35 -0500, in dbase.programming,
Subject: Text to HTML,
Message-ID: <NQHs1aWTGHA.1740@news-server>,
Rick <Sportman7@netzero.com> wrote:

>I need to copy and convert the contents of a memo field to an html file. So far, I plan to copy the memo file contents to a text file with:
>form.rowset.fields[?MyMemo?].CopyToFile(?MyNew.htm?)
>
>Then programmatically load this text file into MS Word, and save it as an html file.
>
>Anyone have an idea for a better, easier way.
>
>Thanks for any ideas on this,



Try the code below my signature. It uses a primitive line wrap. Looks Ok with a
line length of 60 and fails when the length is 40, but I hope you can improve
upon it :-)


Ivar B. Jessen

//-----
d = new database()
d.databasename = "dBASESamples"
d.active = true

q = new query()
q.sql = 'select description from fish where ID = 1'
q.active = true

cStr = q.rowset.fields["description"].value

fs = new file()
fs.create("Des.txt")
fs.open("Des.txt", "W")
fs.write(cStr, len(cStr))
fs.close()

clear

fs = new file()
fs.open("Des.txt", "R")
fs.seek(0)

n = 0
cS = "<html><head><title>Wrapped Fish</title></head><body>" + chr(10)
do
if n = 0
cs = cS + "<PRE>"
endif
n++
c = fs.read(1)

if n > 60 and ( asc(c) = 32 or asc(c) = 10 )
cS = cS + c
cS = cS + iif(asc(c) = 32, chr(10), "")
n = 0
else
cS = cS + c
endif

until fs.eof()
cS = cS + "</body></html>"
fs.close()

fd = new file()
fd.create("Des.html")
fd.open("Des.html", "W")
fd.write(cS, len(cS))
fd.close()

erase Des.txt
q.active = false
d.active = false
//-----
Rick

2006-03-23, 1:24 pm

Michael,

Duh, I should have seen that myself. Can I chalk that up to March Madness?

All works great now.

Thanks,
Rick

Michael Nuwer [dBVIPS] Wrote:

> Rick wrote:
>
> Correct, all occurrences are replaced with the global property.
>
>
> In the line above "cBody" is not modified. The modified string is in "X"
>
>
>
> f.puts( X ) should work in place of the line above.
>


Ronnie MacGregor

2006-03-23, 1:24 pm


On Thu, 23 Mar 2006 16:05:31 +0100
Ivar B. Jessen said :

> It uses a primitive line wrap. Looks Ok with a
> line length of 60 and fails when the length is 40


Here's a function that will take a string of any length, and return the string
wrapped at the last whole word which gives a line length less than cWidth.

Should be fairly easily to modify it to do this job, starting by adding an html
tag in place of chr(13).

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

function StringToParagraph(cS
tring, cWidth)

/*

Ronnie MacGregor

February 2006

Takes a string of any length and returns the
same string wrapped at the end of a whole word
giving a line length less than or equal to cWidth

*/

local aWords, aLines, cOutput

cOutput = ""
aWords = new array()
aLines = new array()

// Feed individual words into array
do while len(cString) > 0
// Chop off leading space
do while substr(cString, 1, 1) == " "
cString := substr(cString, 2)
enddo
// Add leading word to array
if len(cString) > 0
if " " $ cString
aWords.add(substr(cString, 1, at(" ", cString, 1) - 1))
else
aWords.add(cString)
endif
cString := substr(cString, at(" ", cString, 1))
endif
enddo // next

// Construct lines at less than paragraph width
for nCount = 1 to aWords.size
if len(cOutput) + 1 + len(aWords[nCount]) <= cWidth
if len(cOutput) == 0
cOutput := aWords[nCount]
else
cOutput := cOutput + " " + aWords[nCount]
endif
else
aLines.add(cOutput)
cOutput := aWords[nCount]
endif
endfor // next
if len(cOutput) > 0
aLines.add(cOutput)
endif

// Construct output paragraph
cOutput = ""
for nCount = 1 to aLines.size - 1
cOutput := cOutput + aLines[nCount] + chr(13)
endfor // next
cOutput := cOutput + aLines[aLines.size]

return cOutput

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

--
Ronnie MacGregor
Scotland

Ronnie at
dBASEdeveloper
dot co dot uk

www.dBASEdeveloper.co.uk



Rick

2006-03-23, 8:26 pm

Silvio,

Thanks. Michael's code to replace cr/lf worked for me.

Appreciate the help,
Rick

Silvio Genco Wrote:

> save form.rowset.fields["MyMemo"].value to mymemo.txt
> fm = new File( )
> fm.open( "mymemo.txt")
>
> f = new File()
> f.create("test.htm", "RW")
> f.puts("<html><head><title>My Title</title></head><body>")
>
> do while not fm.eof( ) // scan mymemo.txt and replace the line breaks with
> <BR>
> mytext += fm.gets( ) + "<BR>" // Write lines to HTML component
> enddo
> fm.close( )
>
> f.puts(mytext)
> f.puts( "</body></html>")
> f.close()
>
>
> Silvio
>
>
>
>
> "Rick" <Sportman7@netzero.com> ha scritto nel messaggio
> news:L2ftFYdTGHA.2320@news-server...
> all in one line.
>
>


Ivar B. Jessen

2006-03-24, 3:24 am

On Thu, 23 Mar 2006 16:13:03 -0000, in dbase.programming,
Subject: Re: Text to HTML,
Message-ID: <MPG. 1e8cd965ebeff5c99897
62@news.dbase.com>,
Ronnie MacGregor <No_Sp@m.Thanks> wrote:

>Here's a function that will take a string of any length, and return the string
>wrapped at the last whole word which gives a line length less than cWidth.
>
>Should be fairly easily to modify it to do this job, starting by adding an html
>tag in place of chr(13).


Thanks. This gave me a lot of headaches.

I tested in this way,

? StringToParagraph("Should be fairly easily to modify it to do this job,
starting by adding an html ", "40") (Why is the width not of type number?)

and the funcion went into an infinite loop. After a lot of headscratching I
noticed the space at the end of the string and it became obvious that the result
of the condition in the do loop below was always true.

do while substr(cString, 1, 1) == " "

The fix was to change the do loop to,

do while asc(substr(cString, 1, 1)) == 32

The Danish language driver evaluates the condition in this way,

? "" == " " // true
? asc("") == asc(" ") // false

So in order to permit the function to run on computers not having having your
Scottish language driver installed I recommend that you change the code as
outlined above :-)

As this was my first attempt to delve into the mysteries of HTML code I will
leave it up to Rick to modify it if it solves his problem.


Ivar B. Jessen
Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com