Solved

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

Posted on 2004-10-05
3
166 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now