01.
Imports
System.IO
02.
Imports
System.Data
03.
Imports
Excel
04.
05.
Public
Class
ExcelColumn
06.
Public
Property
Col1
As
String
07.
Get
08.
Return
m_Col1
09.
End
Get
10.
Set
11.
m_Col1 = Value
12.
End
Set
13.
End
Property
14.
Private
m_Col1
As
String
15.
Public
Property
Col2()
As
String
16.
Get
17.
Return
m_Col2
18.
End
Get
19.
Set
20.
m_Col2 = Value
21.
End
Set
22.
End
Property
23.
Private
m_Col2
As
String
24.
Public
Property
Col3()
As
String
25.
Get
26.
Return
m_Col3
27.
End
Get
28.
Set
29.
m_Col3 = Value
30.
End
Set
31.
End
Property
32.
Private
m_Col3
As
String
33.
Public
Property
Col4()
As
String
34.
Get
35.
Return
m_Col4
36.
End
Get
37.
Set
38.
m_Col4 = Value
39.
End
Set
40.
End
Property
41.
Private
m_Col4
As
String
42.
Public
Property
Col5()
As
String
43.
Get
44.
Return
m_Col5
45.
End
Get
46.
Set
47.
m_Col5 = Value
48.
End
Set
49.
End
Property
50.
Private
m_Col5
As
String
51.
End
Class
52.
53.
Public
Class
myWebForm
54.
Inherits
System.Web.UI.Page
55.
56.
Protected
Sub
Page_Load(
ByVal
sender
As
Object
,
ByVal
e
As
System.EventArgs)
Handles
Me
.Load
57.
Using stream
As
FileStream = File.Open(Server.MapPath(
"Xls/myExcel.xlsx"
), FileMode.Open, FileAccess.Read)
58.
Dim
excelReader
As
IExcelDataReader = ExcelReaderFactory.CreateOpenXmlReader(stream)
59.
excelReader.IsFirstRowAsColumnNames =
True
60.
Dim
ls =
New
List(Of ExcelColumn)()
61.
While
excelReader.Read()
62.
63.
64.
65.
66.
67.
ls.Add(
New
ExcelColumn()
With
{
68.
.Col1 = excelReader.GetString(0),
69.
.Col2 = excelReader.GetString(1),
70.
.Col3 = excelReader.GetString(2),
71.
.Col4 = excelReader.GetString(3),
72.
.Col5 = excelReader.GetString(4)})
73.
End
While
74.
75.
Me
.myGridView.DataSource = ls
76.
Me
.myGridView.DataBind()
77.
End
Using
78.
End
Sub
79.
80.
End
Class