Solved

How can i write HTML to a doc file???

Posted on 2004-10-05
3
199 Views
Last Modified: 2010-04-23
I have the next code for generating a doc file.

        Dim msword As Word.Application
        Dim msDoc As Word.Document
        Dim a_text As String
        a_text = "TEXT to be written!!! :)"
        msword = New Word.Application
        msDoc = msword.Documents.Add
        msDoc.Content.Text = a_text                    'write text to the doc file
        msDoc.SaveAs("c:\01.doc")                      'save the doc file
        msDoc.Close()
        msDoc = Nothing
        msword.Quit()
        msword = Nothing

In stead of writing oly text i would like to write html code that will be interpreted by word and desplayed like in IE. Is this possible???

Or how can i make tables into this word document? Draw lines... and make table outline invisible???

Thanks.
0
Comment
Question by:drcyrus3d
3 Comments
 
LVL 10

Accepted Solution

by:
prakash_prk earned 500 total points
ID: 12274747
Try this codes
----------------------
 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        ConvertToWord("<BODY BGCOLOR=RED> HAI </BODY>", "d:\hai.doc")
    End Sub
----------------------
    Private Function ConvertToWord2(ByVal SourcePath As String, ByVal DestPath As String)
        Dim msword As Word.Application
        Dim msDoc As Word.Document
        Dim a_text As String
        msword = New Word.Application
        msDoc = msword.Documents.Open(SourcePath)
        MsgBox(msDoc.Content.Text) 'write text to the doc file
        msDoc.SaveAs(DestPath, Word.WdSaveFormat.wdFormatDocument)                     'save the doc file
        msDoc.Close()
        msDoc = Nothing
        msword.Quit()
        msword = Nothing
    End Function
--------------------------------
    Private Function ConvertToWord(ByVal HtmlContent As String, ByVal DestPath As String)
        Dim msword As Word.Application
        Dim msDoc As Word.Document
        Try
            Dim MyWriter As New System.IO.StreamWriter(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) & "\..\temp\temp1.html")
            MyWriter.WriteLine(HtmlContent)
            MyWriter.Close()

            msword = New Word.Application
            msDoc = msword.Documents.Open(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) & "\..\temp\temp1.html")

            msDoc.SaveAs(DestPath, Word.WdSaveFormat.wdFormatDocument)                     'save the doc file
            msDoc.Close()
            msDoc = Nothing
            msword.Quit()
            msword = Nothing
            MsgBox("Success")
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Function
-----------------------------------
Regards
Prakash
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question