[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 184
  • Last Modified:

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
0
mte01
Asked:
mte01
  • 7
  • 4
1 Solution
 
mrwaqarCommented:
Open word object and open the html file in word. Save as ".doc"
0
 
mrwaqarCommented:
For help on how to open word object, see the link below:
http://www.vbdotnetheaven.com/Code/Jul2003/2123.asp
0
 
mte01Author Commented:
hi guys, i am generating the word document from VB.net, this is where i need to pass the HTML text
thanks.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
mrwaqarCommented:
Can you please give more details. Or probably post the part of code which will give an idea?
0
 
mte01Author Commented:
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
0
 
mrwaqarCommented:
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.
0
 
mrwaqarCommented:
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!
0
 
mrwaqarCommented:
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 :)
0
 
mte01Author Commented:
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
0
 
mrwaqarCommented:
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!
0
 
bilaniCommented:
Hey mte,

You can give a format a special format to a part of your paragraph by doing:
doc.range(start,end).Font
with doc being ur word document and the start and end being the ID of the characters over the whole document.

Hope it will help

--bilani
0
 
mte01Author Commented:
even though that i have to do this manually,
thanks anyways
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 7
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now