Link to home
Start Free TrialLog in
Avatar of mte01
mte01Flag for Lebanon

asked on

Word Format from HTML

Hi,
I have a text with HTML tags(that are used to keep track of formatting).
I would like to export this text with the formatting to a word document from VB.net.

My problem is that i can't seem to be able to change the formatting of a part of the paragraph without the whole paragraph formatting to change.


Is there a way to directly pass the HTML format to word? or an instruction to format part of paragraphs?
Thx for your help.

--mte
Avatar of mrwaqar
mrwaqar
Flag of United Arab Emirates image

Open word object and open the html file in word. Save as ".doc"
For help on how to open word object, see the link below:
http://www.vbdotnetheaven.com/Code/Jul2003/2123.asp
Avatar of mte01

ASKER

hi guys, i am generating the word document from VB.net, this is where i need to pass the HTML text
thanks.
Can you please give more details. Or probably post the part of code which will give an idea?
Avatar of mte01

ASKER

doc is a word document
the following will insert the string textStr into the word document:
doc.Range.InsertAfter("this is a text that will be inserted")

now if i have my text like that:

this is a <b>text </b>that will be inserted
i need the word text to be in bold, when i try to send this string as parameter to the function InsertAfter, it doesnt replace the tag b, but it will display the <b> and the </b>
is there a way to let word recognise the HTML tags?
anyways i can parse the text to XML, but i am not capable to give a format to a specific part of the paragraph, hope that this cleared things
Best
No word will not handle html tags. It is ment to be used in html only. You can make the document as html first and save it as .doc later. Otherwise you need to parse the text and determine the html tags and change the formate
Example:
"this is a <b>text </b>that will be inserted"
In the above text, you need to first check the position of <b> and start selecting the text till you find </b> and then change the formating.
One more way you can do it (but not a decent way) is that you open the actual word document where you want to insert the text, save it as html and insert the text. after inserting, save it back as doc.
I personally would prefere parsing
Good Luck!
Just to give an idea about the code:

****
Dim txt As String, nStartPosition As Integer, nEndPosition as Integer
txt = "this is a <b>text </b>that will be inserted"
nStartPosition = txt.IndexOf("<b>")
nEndPosition   = txt.IndexOf("</b>")
***
nStartPosition and nEndPosition will tell you the starting and ending position. You know what to do after that :)
Avatar of mte01

ASKER

no man, i know how to do such things, the problem is how to handle the word API and not vb.net
thanks for the effort anyway ;)
Best
Well you didnt mention that you know how to parse the text and you are not looking for that kind of solution ;)
Cheers n Good Luck!
ASKER CERTIFIED SOLUTION
Avatar of bilani
bilani

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mte01

ASKER

even though that i have to do this manually,
thanks anyways