web 2.0

ASP.NET(vb.net) & Open excel/template on specified Worksheet (.xls) (Excel.Application)

ASP.NET(vb.net) & Open excel on specified Worksheet (.xls) (Excel.Application) - This article example scripts you will learn how to Open excel on specified Worksheet using ASP.NET Scripts.

ShotDev Focus:
- ASP.NET(vb.net) & Open excel on specified Worksheet (.xls) (Excel.Application)

Example

AspNetExcelOpenDoc.aspx

<%@ Import Namespace="System.IO"%>
<%@ Import Namespace="Microsoft.Office.Interop.Excel"%>
<%@ Page Language="VB" %>
<script runat="server">
Sub Page_Load(sender As Object, e As EventArgs)

Dim OpenDoc As String = "Excel.xls"
Dim FileName As String = "MyXls/MyExcel.xls"
Dim i As Integer
'*** Create Excel.Application ***'
Dim xlApp As New Microsoft.Office.Interop.Excel.Application
Dim xlSheet1 As Microsoft.Office.Interop.Excel.Worksheet
Dim xlBook As Microsoft.Office.Interop.Excel.Workbook

xlBook = xlApp.Workbooks.Open(Server.MapPath(OpenDoc))

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

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

For i = 3 To 10

With xlApp.ActiveSheet.Cells(i,1)
.Value = "Data 1"
End With

With xlApp.ActiveSheet.Cells(i,2)
.Value = "Data 2"
End With

With xlApp.ActiveSheet.Cells(i,3)
.Value = "Data 3"
End With

With xlApp.ActiveSheet.Cells(i,4)
.Value = "Data 4"
End With

Next

'*** If Files Already Exist Delete files ***'
Dim MyFile As New FileInfo(Server.MapPath(FileName))
If MyFile.Exists Then
MyFile.Delete()
End IF
MyFile = Nothing

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

'*** Quit and Clear Object ***'
xlSheet1 = Nothing
xlBook = Nothing
xlApp = Nothing

Me.lblText.Text = "Excel Created <a href="& FileName & ">Click here</a> to Download."

End Sub

</script>
<html>
<head>
<title>ShotDev.Com Tutorial</title>
</head>
<body>
<form id="form1" runat="server">
<asp:Label id="lblText" runat="server"></asp:Label>
</form>
</body>
</html>

Screenshot

ASP.NET(vb.net) & Open excel on specified Worksheet (.xls) (Excel.Application)

ASP.NET(vb.net) & Open excel on specified Worksheet (.xls) (Excel.Application)
.
.
.
Download this script.
Download

1 Star2 Stars3 Stars4 Stars5 Stars6 Stars7 Stars8 Stars9 Stars10 Stars (No Ratings Yet)
Loading ... Loading ...

Leave a Reply

You must be logged in to post a comment.