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 Excel (Excel.Application) > ASP Convert to Excel and Send Email Attachment



Clound SSD Virtual Server

ASP Convert to Excel and Send Email Attachment

ASP Convert to Excel and Send Email Attachment ตัวอย่างนี้จะเป็นการเขียน ASP กับ Excel ทำการ Convert ในรูปแบบของ Excel (*.xls) และทำการแนบไฟล์ไปพร้อมกับอีเมล์

Config Excel.Application



Send Email with CDONTS (CDONTS.NewMail)



Send Email with CDOSYS (CDO.Message)




AspConvertToExcelSendEmailAttachment.asp

<% Option Explicit %>
<html>
<head>
<title>ThaiCreate.Com ASP Excel.Application Tutorial</title>
</head>
<body>
<%
		Dim Conn,strSQL,objRec
		Dim xlApp,xlBook,xlSheet1,FileName,intRows
		Dim Fso,MyFile

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

		If Not objRec.EOF Then
			
				FileName = "MyXls/MyReport.xls"

				'*** Create Exce.Application ***'
				Set xlApp = Server.CreateObject("Excel.Application")
				Set xlBook = xlApp.Workbooks.Add

				'*** Create Sheet 1 ***'
				xlBook.Worksheets(1).Name = "My Customer"								
				xlBook.Worksheets(1).Select

				'*** Width & Height (A1:A1) ***'
				With xlApp.ActiveSheet.Range("A1:A1")
					.ColumnWidth = 10.0
				End With
				With xlApp.ActiveSheet.Range("B1:B1")
					.ColumnWidth = 13.0
				End With
				With xlApp.ActiveSheet.Range("C1:C1")
					.ColumnWidth = 23.0
				End With
				With xlApp.ActiveSheet.Range("D1:D1")
					.ColumnWidth = 12.0
				End With
				With xlApp.ActiveSheet.Range("E1:E1")
					.ColumnWidth = 13.0
				End With
				With xlApp.ActiveSheet.Range("F1:F1")
					.ColumnWidth = 12.0
				End With

				With xlApp.ActiveSheet.Range("A1:F1")
					.BORDERS.Weight = 1  
					.MergeCells = True	
					.Font.Bold = True
					.Font.Size = 20
					.HorizontalAlignment = -4108 
				End With
				With xlApp.ActiveSheet.Cells(1,1)
					.Value = "Customer Report"
				End With

				'*** Header ***'
				With xlApp.ActiveSheet.Cells(3,1)
					.Value = "CustomerID"
					.Font.Bold = True
					.VerticalAlignment = -4108 
					.HorizontalAlignment = -4108 
					.BORDERS.Weight = 1
				End With
				With xlApp.ActiveSheet.Cells(3,2)
					.Value = "Name"
					.Font.Bold = True
					.VerticalAlignment = -4108 
					.HorizontalAlignment = -4108
					.BORDERS.Weight = 1
				End With	
				With xlApp.ActiveSheet.Cells(3,3)
					.Value = "Email"
					.Font.Bold = True
					.VerticalAlignment = -4108 
					.HorizontalAlignment = -4108 
					.BORDERS.Weight = 1
				End With
				With xlApp.ActiveSheet.Cells(3,4)
					.Value = "CountryCode"
					.Font.Bold = True
					.VerticalAlignment = -4108 
					.HorizontalAlignment = -4108 
					.BORDERS.Weight = 1
				End With
				With xlApp.ActiveSheet.Cells(3,5)
					.Value = "Budget"
					.Font.Bold = True
					.VerticalAlignment = -4108 
					.HorizontalAlignment = -4108 
					.BORDERS.Weight = 1
				End With
				With xlApp.ActiveSheet.Cells(3,6)
					.Value = "Used"
					.Font.Bold = True
					.VerticalAlignment = -4108 
					.HorizontalAlignment = -4108 
					.BORDERS.Weight = 1
				End With
				'***********'
			
			intRows = 4
			While Not objRec.EOF
				
				'*** Detail ***'
				With xlApp.ActiveSheet.Cells(intRows,1)
					.Value = objRec.Fields("CustomerID").Value
					.BORDERS.Weight = 1
					.HorizontalAlignment = -4108
				End With
				With xlApp.ActiveSheet.Cells(intRows,2)
					.Value = objRec.Fields("Name").Value
					.BORDERS.Weight = 1
				End With
				With xlApp.ActiveSheet.Cells(intRows,3)
					.Value = objRec.Fields("Email").Value
					.BORDERS.Weight = 1
				End With
				With xlApp.ActiveSheet.Cells(intRows,4)
					.Value = objRec.Fields("CountryCode").Value
					.HorizontalAlignment = -4108 
					.BORDERS.Weight = 1
				End With
				With xlApp.ActiveSheet.Cells(intRows,5)
					.Value = objRec.Fields("Budget").Value
					.BORDERS.Weight = 1
				End With
				With xlApp.ActiveSheet.Cells(intRows,6)
					.Value = objRec.Fields("Used").Value
					.BORDERS.Weight = 1
				End With

				intRows = intRows + 1
				objRec.MoveNext
			Wend

			'*** If Files Already Exist Delete files ***'
			Set Fso = CreateObject("Scripting.FileSystemObject")
			If (Fso.FileExists(Server.MapPath(FileName))) Then
			   Set MyFile = Fso.GetFile(Server.MapPath(FileName))
			   MyFile.Delete
			End If

			'*** Save Excel ***'
			'xlBook.PrintOut 1 '*** Print to printer ***'
			xlBook.SaveAs Server.MapPath(FileName)
			xlApp.Application.Quit

			'*** Quit and Clear Object ***'
			Set xlSheet1 = Nothing
			Set xlBook = Nothing
			Set xlApp = Nothing
			
			
			'**************** Send Email ******************'

			Dim myMail,HTML,strMsg

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

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

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

			myMail.Send

			Set myMail = Nothing

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

			Response.write"Generate Excel and Email Sending."

		End If

		objRec.Close()
		Conn.Close()
		Set objRec = Nothing
		Set Conn = Nothing		

%>
</body>
</html>


Screenshot

ASP & Excel


ASP & Excel






   
Share


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


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


   


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

 
ASP Excel Response.ContentType = "application/vnd.ms-excel"
Rating :

 
ASP Config Excel (Excel.Application)
Rating :

 
ASP Connect to Excel.Application
Rating :

 
ASP Write Excel (Excel.Application)
Rating :

 
ASP Delete Sheet Excel (Excel.Application)
Rating :

 
ASP Write Excel Multiple Sheet (Excel.Application)
Rating :

 
ASP Write Excel Style & Format (Excel.Application)
Rating :

 
ASP Excel Merge Cell (Excel Application)
Rating :

 
ASP Read Excel (Excel.Application)
Rating :

 
ASP Excel Cell Border (Excel Application)
Rating :

 
ASP Read Excel Multiple Sheet (Excel.Application)
Rating :

 
ASP Excel Draw Line (Excel Application)
Rating :

 
ASP ADO Excel (DRIVER={Microsoft Excel Driver (*.xls)})
Rating :

 
ASP Excel Insert Picture (Excel Application)
Rating :

 
ASP ADO Excel List Record Paging/Pagination (Microsoft Excel Driver (*.xls))
Rating :

 
ASP Excel Open Document (Excel Application)
Rating :

 
ASP Import Excel to Database (Excel.Application)
Rating :

 
ASP Upload Excel Import to Database (Excel.Application)
Rating :

 
ASP Export Database to Excel (Excel.Application)
Rating :

 
ASP Export Database to Excel Report/Print Format (Excel.Application)
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 03
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 อัตราราคา คลิกที่นี่