web 2.0

How to use ASP & Word (Word.Application) - Create/Insert Table (Tables.Add)

How to use ASP & Word (Word.Application) - Create/Insert Table (Tables.Add) This is learn/tutorial asp developers how to using ASP script Create Word document and Insert Table (Tables.Add)

ShotDev Focus:
- ASP & Create Word document and Insert Table (Tables.Add)

Example

asp_word_table.asp


<% OptionĀ  Explicit %>
<html>
<head>
<title>ShotDev.Com Tutorial</title>
</head>
<body>
<%
Dim Wrd,WrdDoc,DocName,WTable
Set Wrd = CreateObject("Word.Application")
Wrd.Application.Visible = False
DocName = "MyDoc/MyWord.doc"

Set WrdDoc = Wrd.Documents.Add()

Set 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
Set Wrd = Nothing

%>
Word Created <a href="<%=DocName%>">Click here</a> to Download.
</body>
</html>

Create a asp file and save to path root-path/myasp/

Run
http://localhost/myasp/asp_word_table.asp

Screenshot

ASP & Create Word document and Insert Table (Tables.Add).
.
.
.
Download this script.
Download

1 Star2 Stars3 Stars4 Stars5 Stars6 Stars7 Stars8 Stars9 Stars10 Stars (1 votes, average: 1.00 out of 10)
Loading ... Loading ...

Leave a Reply

You must be logged in to post a comment.