web 2.0

How to use ASP & Insert Picture in excel (Excel.Application)

How to use ASP & Insert Picture in excel (Excel.Application) This is learn/tutorial asp developers how to using ASP script Insert picture in excel sheet.

ShotDev Focus:
- ASP & Insert picture in excel sheet.

Example

asp_excel_picture.asp


<%Option Explicit%>
<html>
<head>
<title>ShotDev.Com Tutorial</title>
</head>
<body>
<%
Dim xlApp,xlBook,xlSheet1,FileName
Dim Fso,MyFile
FileName = "MyXls/MyExcel.xls"

Const xlEdgeLeft = 7
Const xlEdgeTop = 8
Const xlEdgeBottom = 9
Const xlEdgeRight = 10

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

'*** Create Sheet 1 ***'
Set xlSheet1 = xlBook.Worksheets(1)
xlSheet1.Name = "My Sheet1"
xlApp.Application.Visible = False

'*** Write text to Row 1 Column 1 ***'
With xlApp.ActiveSheet.Cells(1,1)
.Value = "ShotDev.Com"
End With

'*** Insert Picture (1) ***'
xlApp.Range("B3").Select()
xlApp.ActiveSheet.Pictures.Insert(Server.MapPath("logo.gif")).Select()

'*** Insert Picture (2) ***'
Dim Pic
xlApp.Range("I3").Select
Set Pic = xlApp.ActiveSheet.Pictures.Insert(Server.MapPath("logo.gif"))
With Pic
.Width = "300"
.Height = "150"
End With

'*** 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 ***'
'xlSheet1.PrintOut 1 '*** Print to printer ***'
xlSheet1.SaveAs Server.MapPath(FileName)
xlApp.Application.Quit

'*** Quit and Clear Object ***'
Set xlSheet1 = Nothing
Set xlBook = Nothing
Set xlApp = Nothing
%>
Excel Created <a href="<%=FileName%>">Click here</a> to Download.
</body>
</html>

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

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

Screenshot

ASP & Insert picture in excel sheet.
.
.
.
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 ...

One Response to “How to use ASP & Insert Picture in excel (Excel.Application)”

  1. 1microscopic…

Leave a Reply

You must be logged in to post a comment.