ASP.NET(vb.net) & Word (Word Application) - Paragraphs & Range - This article example scripts you will learn how to set Paragraphs & Range in Word document using ASP.NET Scripts
ShotDev Focus:
- ASP.NET(vb.net) & Word (Word Application) - Paragraphs & Range
Example
AspNetWordParagraphsRange.aspx
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="AspNetWordParagraphsRange.aspx.vb" Inherits="AspNetWordParagraphsRange" %> <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>
AspNetWordParagraphsRange.aspx.vb
Imports Microsoft.Office.Interop.Word Public Class AspNetWordParagraphsRange Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Const wdAlignParagraphCenter = 1 Const wdAlignParagraphLeft = 0 Const wdParagraph = 4 Const wdHorizontalPositionMargin = 0 Const wdTableLeft = -999998 Const wdCollapseEnd = 0 Dim Wrd As New Microsoft.Office.Interop.Word.Application Dim WrdDoc As Microsoft.Office.Interop.Word.Document Dim MyRange1, MyRange2 As Microsoft.Office.Interop.Word.Range Dim DocName As String = "MyDoc/MyWord.doc" Wrd.Application.Visible = False WrdDoc = Wrd.Documents.Add() MyRange1 = WrdDoc.Paragraphs.Add.Range With MyRange1 .ParagraphFormat.Alignment = wdAlignParagraphCenter .Font.Name = "Verdana" .Font.Size = "30" .Font.Bold = True .InsertBefore("www.ShotDev.Com" & vbCrLf & "Version 2010") .Font.Bold = True End With MyRange1 = WrdDoc.Paragraphs.Add.Range With MyRange1 .InsertBefore(Chr(12)) '*** New Page ***' End With MyRange2 = WrdDoc.Paragraphs.Add.Range With MyRange2 .ParagraphFormat.Alignment = wdAlignParagraphCenter .Font.Name = "Verdana" .Font.Size = "15" .Font.Bold = True .InsertBefore("PHP,ASP and ASP.NET Tutorial") End With WrdDoc.SaveAs(Server.MapPath(DocName)) Wrd.Application.Quit() Wrd = Nothing End Sub End Class
Screenshot