I need to open and amend a Word doc (using an aspx page)

knee_boarder

New member
Joined
Sep 24, 2003
Messages
4
I cant find any code to do this at all (well not that I understood anyway).

I tried reading the file in (as a string - that works), replacing what needed to be replaced and then writing the string to the file. The problem is all the "Word" formatting is lost then.

So I thought I could open an instance of "Word" and control the replace in "Word" itself but although Ive seen VB versions of this, Ive seen nothing for use in an aspx page (written in VB.net).

any help in the right direction would be most appreciated.

Steve
 
Note: you have to reference Microsoft.word 9.0 object then use this code and Have Fun ;)

Creating a Word application, document and selection object
Dim WordApp As New Word.Application()
Dim WordDoc As New Word.Document()
Dim WordSelection As Word.Selection
Dim strToAdd As String Text that will be added to the word document
WordDoc = WordApp.Documents.Add Sets the word document to the first document of the word application
WordDoc.Select() Sets the working document
WordSelection = WordApp.Selection Sets the word selection to the selection of the document
strToAdd = "Test To insert here" Title
WordSelection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter Sets alignment of paragraph to center
WordSelection.Font.Size = 12 Sets the size of the font
WordSelection.Font.Name = "Times New Roman" Sets the type of the font
WordSelection.Font.Bold = True Sets the font to Bold
WordSelection.TypeText(strToAdd) Inserts text to the word application
WordSelection.TypeText(vbCrLf) Inserts a cariage return
WordSelection.TypeText(vbCrLf) Inserts a cariage return
WordSelection.Font.Bold = False resets font bold to false
WordSelection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft Sets alignment of paragraph to left
Saves the word document under the root application
WordDoc.SaveAs(SelectedMeeting.SiteRootPath & "Reports\Report of " & SelectedMeeting.MeetingName & ".doc")
Dispose and deallocate the Word variables
WordSelection = Nothing
WordDoc = Nothing
WordApp.Documents.Close()
WordApp = Nothing
 
thanks for that

errm how do I reference the Word object (seen a few references to "referencing" it but not any actual code). Sorry to ask such simple stuff but Im an asp programmer whose had a .net project thrust upon me (the original version is a VB application which doesnt help cos Im not a VB programmer!) :confused: :D

thanks again
 
Dont Worry,
Go to Project then Add Reference then select the Com tab and scroll to Microsoft Word object 9.0
Let Me know if you need any more clarifications
 
Back
Top