web 2.0

ASP.NET(vb.net) & Read Excel file (Excel.Application)

ASP.NET(vb.net) & Read Excel file (Excel.Application) - This article example scripts you will learn how to  Read excel file using ASP.NET Scripts.

ShotDev Focus:
- ASP.NET(vb.net) & Read Excel file (Excel.Application)

Example

AspNetReadExcel.aspx

<%@ Import Namespace="System.Data"%>
<%@ Import Namespace="Excel"%>
<%@ Page Language="VB" %>
<script runat="server">
Sub Page_Load(sender As Object, e As EventArgs)
Dim OpenFile As String
Dim i As Integer
OpenFile = "MyXls/MyExcelDB.xls"

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

xlBook = xlApp.Workbooks.Open(Server.MapPath(OpenFile))
xlBook.Application.Visible = False

xlSheet1 = xlBook.Worksheets(1)

'*** Create DataTable ***'
Dim dt As New System.Data.DataTable
Dim dr As System.Data.DataRow

'*** Column ***'
dt.Columns.Add("Cloumn1")
dt.Columns.Add("Cloumn2")
dt.Columns.Add("Cloumn3")
dt.Columns.Add("Cloumn4")

i = 2
Do While Not Trim(xlSheet1.Cells.Item(i, 1).Value) = ""
'*** Rows ***'
dr = dt.NewRow
dr("Cloumn1") = xlSheet1.Cells.Item(i, 1).Value
dr("Cloumn2") = xlSheet1.Cells.Item(i, 2).Value
dr("Cloumn3") = xlSheet1.Cells.Item(i, 3).Value
dr("Cloumn4") = xlSheet1.Cells.Item(i, 4).Value
dt.Rows.Add(dr)
i = i + 1
Loop

'*** End DataTable ***'

'*** BindData To GridView ***'
Me.myGridView.DataSource = dt
Me.myGridView.DataBind()

'*** Quit and Clear Object ***'
xlApp.Application.Quit()
xlApp.Quit()
xlSheet1 = Nothing
xlBook = Nothing
xlApp = Nothing

End Sub

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

Screenshot

ASP.NET(vb.net) & Read Excel file (Excel.Application)

ASP.NET(vb.net) & Read Excel file (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.