Solved

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

Posted on 2004-10-05
3
200 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: 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!

Question has a verified solution.

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

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 …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

739 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