Solved

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

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

808 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