Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > ASP > ASP Word (Word.Application) > ASP & Word (Word.Application) - Convert and Send Email Attachment



Clound SSD Virtual Server

ASP & Word (Word.Application) - Convert and Send Email Attachment

ASP & Word (Word.Application) - Convert and Send Email Attachment ตัวอย่างนี้จะเป็นการเขียน ASP กับ Word โดยส่งออกในรูปแบบของ Word Document (*.doc) และทำการแนบไฟล์ไปพร้อมกับอีเมล์ (Send Email Attachment)

Config Word.Application


Send Email with CDONTS (CDONTS.NewMail)


Send Email with CDOSYS (CDO.Message)



AspWordSendEmailAttachment.asp

<% Option Explicit %>
<html>
<head>
<title>ThaiCreate.Com ASP & Word.Application</title>
</head>
<body>
<%
	Const wdAlignParagraphCenter = 1
	Const wdAlignParagraphRight = 2

	Dim Wrd,WrdDoc,DocName,objTable
	Dim Conn,strSQL,objRec,arrCus,intRows
	Dim MyRange1,MyRange2,MyRange3
	Set Wrd = CreateObject("Word.Application")
	DocName = "MyDoc/MyWord.doc"
	Wrd.Application.Visible = False

	Set WrdDoc = Wrd.Documents.Open(Server.MapPath("thaicreate.dot"))
	
	Set MyRange1 = WrdDoc.Paragraphs.Add.Range
	With MyRange1
		.ParagraphFormat.Alignment = wdAlignParagraphCenter
		.Font.Name = "Verdana"
		.Font.Size = "20"		
		.Font.Bold = True
		.InsertBefore("Customer Report"&vbCrLf)
	End With


	Set Conn = Server.Createobject("ADODB.Connection")
	Conn.Open "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("mydatabase.mdb"),"" , ""
	strSQL = "SELECT * FROM customer "
	Set objRec = Server.CreateObject("ADODB.Recordset")
	objRec.Open strSQL, Conn, 1,3

	If Not objRec.EOF and Not objRec.BOF Then
		arrCus = objRec.GetRows()
	End If 


	Set MyRange2 = WrdDoc.Paragraphs.Add.Range
	With MyRange2
		.Font.Size = "10"
	End With
	Set objTable = Wrd.ActiveDocument.Tables.Add(MyRange2,Ubound(arrCus),6,1,2) '** Range,Rows,Column **'
	
	'*** Header ***'
	objTable.Cell(1,1).Range.InsertAfter("CustomerID")
	objTable.Cell(1,1).Range.Bold = True
	objTable.Cell(1,1).Range.ParagraphFormat.Alignment = 1

	objTable.Cell(1,2).Range.InsertAfter("Name")
	objTable.Cell(1,2).Range.Bold = True
	objTable.Cell(1,2).Range.ParagraphFormat.Alignment = 1

	objTable.Cell(1,3).Range.InsertAfter("Email")
	objTable.Cell(1,3).Range.Bold = True
	objTable.Cell(1,3).Range.ParagraphFormat.Alignment = 1

	objTable.Cell(1,4).Range.InsertAfter("CountryCode")
	objTable.Cell(1,4).Range.Bold = True
	objTable.Cell(1,4).Range.ParagraphFormat.Alignment = 1

	objTable.Cell(1,5).Range.InsertAfter("Budget")
	objTable.Cell(1,5).Range.Bold = True
	objTable.Cell(1,5).Range.ParagraphFormat.Alignment = 1

	objTable.Cell(1,6).Range.InsertAfter("Used")
	objTable.Cell(1,6).Range.Bold = True
	objTable.Cell(1,6).Range.ParagraphFormat.Alignment = 1

	'*** Detail ***
	For intRows = 0 To Ubound(arrCus,2)
		objTable.Cell(intRows+2,1).Range.InsertAfter(arrCus(0,intRows))
		objTable.Cell(intRows+2,1).Range.ParagraphFormat.Alignment = 1

		objTable.Cell(intRows+2,2).Range.InsertAfter(arrCus(1,intRows))
		objTable.Cell(intRows+2,2).Range.ParagraphFormat.Alignment = 0

		objTable.Cell(intRows+2,3).Range.InsertAfter(arrCus(2,intRows))
		objTable.Cell(intRows+2,3).Range.ParagraphFormat.Alignment = 0

		objTable.Cell(intRows+2,4).Range.InsertAfter(arrCus(3,intRows))
		objTable.Cell(intRows+2,4).Range.ParagraphFormat.Alignment = 1

		objTable.Cell(intRows+2,5).Range.InsertAfter(FormatNumber(arrCus(4,intRows),2))
		objTable.Cell(intRows+2,5).Range.ParagraphFormat.Alignment = 2

		objTable.Cell(intRows+2,6).Range.InsertAfter(FormatNumber(arrCus(5,intRows),2))
		objTable.Cell(intRows+2,6).Range.ParagraphFormat.Alignment = 2
	Next


	Set MyRange3 = WrdDoc.Paragraphs.Add.Range
	With MyRange3
		.ParagraphFormat.Alignment = wdAlignParagraphRight
		.Font.Name = "Verdana"
		.Font.Size = "10"		
		.InsertBefore(vbCrLf&vbCrLf&vbCrLf&"..........................Manager"&vbCrLf&Now())
	End With

	WrdDoc.SaveAs(Server.MapPath(DocName))
	Wrd.Application.Quit
	Set Wrd = Nothing

	'**************** Send Email ******************'

	Dim myMail,HTML,strMsg


	Set myMail = Server.CreateObject("CDONTS.NewMail")

	If Trim(DocName) <> "" Then
	myMail.AttachFile Server.MapPath(DocName)
	End If

	myMail.From = "Webmaster <[email protected]>"
	myMail.Value("Reply-To") = "[email protected]"
	myMail.To = "[email protected]"
	myMail.Subject = "My Word"
	myMail.MailFormat = 0
	myMail.BodyFormat = 0
	myMail.Body = "Convert to Word Document"

	myMail.Send

	Set myMail = Nothing

	'*************** End Send Email ***************'

	Response.write"Generate Word and Email Sending."

%>
</body>
</html>


Screenshot

ASP & Word

ASP & Word






   
Share


ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท


ลองใช้ค้นหาข้อมูล


   


Bookmark.   
       
  By : ThaiCreate.Com Team (บทความเป็นลิขสิทธิ์ของเว็บไทยครีเอทห้ามนำเผยแพร่ ณ เว็บไซต์อื่น ๆ)
  Score Rating :  
  Create/Update Date : 2008-10-20 19:39:06 / 2009-05-10 23:24:44
  Download : Download  ASP & Word (Word.Application) - Convert and Send Email Attachment
 Sponsored Links / Related

 
ASP Word Response.ContentType = "application/vnd.ms-word"
Rating :

 
ASP Config Word (Word.Application)
Rating :

 
ASP Connect to Word.Application
Rating :

 
ASP & Word (Word.Application) - Create Word Document
Rating :

 
ASP & Word (Word.Application) - Page Setup
Rating :

 
ASP & Word (Word.Application) - BuiltInDocumentProperties
Rating :

 
ASP & Word (Word.Application) - Font & Style
Rating :

 
ASP & Word (Word.Application) - Paragraphs & Range
Rating :

 
ASP & Word (Word.Application) - Page Breaking
Rating :

 
ASP & Word (Word.Application) - Create/Insert Table (Tables.Add)
Rating :

 
ASP & Word (Word.Application) - Add/Insert Picture (AddPicture)
Rating :

 
ASP & Word (Word.Application) - Open Document (Documents.Open)
Rating :

 
ASP & Word (Word.Application) - Word Document Sample Report
Rating :


ThaiCreate.Com Forum


Comunity Forum Free Web Script
Jobs Freelance Free Uploads
Free Web Hosting Free Tools

สอน PHP ผ่าน Youtube ฟรี
สอน Android การเขียนโปรแกรม Android
สอน Windows Phone การเขียนโปรแกรม Windows Phone 7 และ 8
สอน iOS การเขียนโปรแกรม iPhone, iPad
สอน Java การเขียนโปรแกรม ภาษา Java
สอน Java GUI การเขียนโปรแกรม ภาษา Java GUI
สอน JSP การเขียนโปรแกรม ภาษา Java
สอน jQuery การเขียนโปรแกรม ภาษา jQuery
สอน .Net การเขียนโปรแกรม ภาษา .Net
Free Tutorial
สอน Google Maps Api
สอน Windows Service
สอน Entity Framework
สอน Android
สอน Java เขียน Java
Java GUI Swing
สอน JSP (Web App)
iOS (iPhone,iPad)
Windows Phone
Windows Azure
Windows Store
Laravel Framework
Yii PHP Framework
สอน jQuery
สอน jQuery กับ Ajax
สอน PHP OOP (Vdo)
Ajax Tutorials
SQL Tutorials
สอน SQL (Part 2)
JavaScript Tutorial
Javascript Tips
VBScript Tutorial
VBScript Validation
Microsoft Access
MySQL Tutorials
-- Stored Procedure
MariaDB Database
SQL Server Tutorial
SQL Server 2005
SQL Server 2008
SQL Server 2012
-- Stored Procedure
Oracle Database
-- Stored Procedure
SVN (Subversion)
แนวทางการทำ SEO
ปรับแต่งเว็บให้โหลดเร็ว


Hit Link
   







Load balance : Server 05
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่