web 2.0

ASP.NET(vb.net) & Write/Create Excel Multiple sheet into excel (Excel.Application)

ASP.NET(vb.net) & Write/Create Excel Multiple sheet into excel (Excel.Application) - This article example scripts you will learn how to Create excel multiple sheet in excel using ASP.NET Scripts.

ShotDev Focus:
- ASP.NET(vb.net) & Write/Create Excel Multiple sheet into excel (Excel.Application)

Example

AspNetCreateMultipleSheet.aspx

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

Dim FileName As String = "MyXls/MyExcel.xls"

'*** Create Excel.Application ***'
Dim xlApp As New Excel.Application
Dim xlBook As Excel.Workbook

xlBook = xlApp.Workbooks.Add()
xlBook.Application.Visible = False

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

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

'*** Write text to Row 1 Column 2 ***'
With xlApp.ActiveSheet.Cells(1, 2)
.Value = "Mr.Weerachai Nukitram 1"
End With

'*** Create Sheet 2 ***'
xlBook.Worksheets(2).Name = "My Sheet2"
xlBook.Worksheets(2).Select()

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

'*** Write text to Row 1 Column 2 ***'
With xlApp.ActiveSheet.Cells(1, 2)
.Value = "Mr.Weerachai Nukitram 2"
End With

'*** Create Sheet 3 ***'
xlBook.Worksheets(3).Name = "My Sheet3"
xlBook.Worksheets(3).Select()

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

'*** Write text to Row 1 Column 2 ***'
With xlApp.ActiveSheet.Cells(1, 3)
.Value = "Mr.Weerachai Nukitram 3"
End With

xlBook.Worksheets(1).Select() '*** Focus Sheet 1 ***'

'*** 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 ***'
xlBook.SaveAs(Server.MapPath(FileName))
xlApp.Application.Quit()

'*** Quit and Clear Object ***'
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) & Write/Create Excel Multiple sheet into excel (Excel.Application)

ASP.NET(vb.net) & Write/Create Excel Multiple sheet into excel (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.