ASP.NET(vb.net) & Word (Word Application) - Create/Insert Table (Tables.Add) - This article example scripts you will learn how to Create/Insert Table (Tables.Add) in Word document using ASP.NET Scripts
ShotDev Focus:
- ASP.NET(vb.net) & Word (Word Application) - Create/Insert Table (Tables.Add)
Example
AspNetWordAddTable.aspx
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="AspNetWordAddTable.aspx.vb" Inherits="AspNetWordAddTable" %> <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>
AspNetWordAddTable.aspx.vb
Imports Microsoft.Office.Interop.Word Public Class AspNetWordAddTable Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim Wrd As New Microsoft.Office.Interop.Word.Application Dim WrdDoc As Microsoft.Office.Interop.Word.Document Dim WTable As Microsoft.Office.Interop.Word.Table Dim DocName As String = "MyDoc/MyWord.doc" Wrd.Application.Visible = False DocName = "MyDoc/MyWord.doc" WrdDoc = Wrd.Documents.Add() WTable = WrdDoc.Tables.Add(Wrd.Selection.Range, 3, 3) ' Colums, Rows WTable.Cell(1, 1).Range.Font.Name = "Times New Roman" WTable.Cell(1, 1).Range.Text = "ShotDev.Com 1" WTable.Cell(1, 2).Range.Font.Size = 18 WTable.Cell(1, 2).Range.Bold = True WTable.Cell(1, 2).Range.Font.Italic = True WTable.Cell(1, 2).Range.Text = "ShotDev.Com 2" WTable.Cell(2, 1).Range.ParagraphFormat.Alignment = 1 ' 0= Left, 1=Center, 2=Right WTable.Cell(2, 1).Range.Font.Name = "Arial" WTable.Cell(2, 1).Range.Font.Size = 12 WTable.Cell(2, 1).Range.Bold = False WTable.Cell(2, 1).Range.ParagraphFormat.Alignment = 2 WTable.Cell(3, 3).Range.Font.Name = "Times New Roman" WTable.Cell(3, 3).Range.Font.Size = 14 WTable.Cell(3, 3).Range.Bold = True WTable.Cell(3, 3).Range.Font.Underline = True WTable.Cell(3, 3).Range.ParagraphFormat.Alignment = 0 WTable.Cell(3, 2).Range.Text = "ShotDev.Com 3" Wrd.ActiveDocument.SaveAs(Server.MapPath(DocName)) Wrd.Application.Quit() Wrd = Nothing End Sub End Class
Screenshot