开发者

unable to read a converted HTML file from Word in C#

Problem that I am trying to resolve:

I want to convert a word document into HTML and along with that I want to convert specific text into Hyperlinks. I can't find a way in C# to add hyperlinks before saving the word document as HTML. So, I do the trick I save document as HTML and then read the HTML document and replace the specific text with hyperlink.

I don't know if that is the best way to do it but so far I didn't find any other option.

Now the problem is that when I read the HTML file, I got garbage characters for some special characters. In my word document I have "..." three dots which I think is a special c开发者_Go百科haracter in word, so when I read that in HTML I got garbage letters... The strange thing is that when I open that HTML file in notepad it shows me correctly.

However, through coding i am not able to read such characters.

Please help me.


Sounds like you may need to look into the encoding used by the ms word doc. MS Word may be using ASCIIEncoding.

Also have a look for existing c# libraries that do this.


My actual problem was that I wanted to convert specific text in word document to hyperlinks and I couldn't find a way to do that. The MSDN help is really pathetic and had errors that wasted lot of my time. I am new in automating word documents.

That's why I found it easy to add hyperlinks after converting the file to HTML but that has its own issues. Here is how I am doing it now

Word library provides you the Find function but that does not tell you the position where the text was found.

Find the text and the starting position and then

Address = doc.Range(start, end).Text + ".pdf"

doc.Hyperlinks.Add(doc.Range(start, end), Address, _

                                SubAddress, ScreenTip, TextToDisplay, Target)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜