ASP.NET(vb.net) & Word (Word Application) - Open and Write Document (Documents.Open) - This article example scripts you will learn how to Open and Write Document (Documents.Open) in Word document using ASP.NET Scripts
ShotDev Focus:
- ASP.NET(vb.net) & Word (Word Application) - Open and Write Document (Documents.Open)
Example
AspNetWordOpenDoc.aspx
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="AspNetWordOpenDoc.aspx.vb" Inherits="AspNetWordOpenDoc" %> <html> <head runat="server"> <title>ShotDev.Com Tutorial</title> </head> <body> <form id="form1" runat="server"> <asp:Label ID="lblText" runat="server"></asp:Label> </form> </body> </html>
AspNetWordOpenDoc.aspx.vb
Imports Microsoft.Office.Interop.Word
Public Class AspNetWordOpenDoc
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Const wdAlignParagraphCenter = 1
Dim Wrd As New Microsoft.Office.Interop.Word.Application
Dim WrdDoc As Microsoft.Office.Interop.Word.Document
Dim MyRange1 As Microsoft.Office.Interop.Word.Range
Dim DocName As String = "MyDoc/MyWord.doc"
Wrd.Application.Visible = False
WrdDoc = Wrd.Documents.Open(Server.MapPath("shotdev.dot"))
MyRange1 = WrdDoc.Range()
With MyRange1
.ParagraphFormat.Alignment = wdAlignParagraphCenter
.Font.Name = "Verdana"
.Font.Size = "30"
.Font.Bold = True
.InsertBefore(vbCrLf & vbCrLf & "www.ShotDev.Com" & vbCrLf & "Version 2010" & vbCrLf)
End With
MyRange1 = WrdDoc.Paragraphs.Add.Range
MyRange1.InlineShapes.AddPicture(Server.MapPath("logo.gif"))
MyRange1 = WrdDoc.Paragraphs.Add.Range
With MyRange1
.ParagraphFormat.Alignment = wdAlignParagraphCenter
.Font.Name = "Verdana"
.Font.Size = "13"
.Font.Bold = True
.InsertBefore(vbCrLf & vbCrLf & vbCrLf & vbCrLf & "All Rights Reserved.")
End With
WrdDoc.SaveAs(Server.MapPath(DocName))
Wrd.Application.Quit()
Wrd = Nothing
End Sub
End Class
Screenshot


