Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > ASP.NET > ASP.NET Excel (EPPlus) , VB.Net,C# > ASP.Net Excel & EPPlus Read Excel/Cell file



Clound SSD Virtual Server

ASP.Net Excel & EPPlus Read Excel/Cell file

ASP.Net Excel & EPPlus Read Excel/Cell file นอกจาก EPPlus จะสามารถใช้เขียนไฟล์ Excel แล้ว อีกความสามารถหนึ่งคือการอ่านข้อมูลที่อยู่ใน Excel บน โดยรูปแบบการอ่านข้อมูลนั้นจะใช้การ อ่านจาก Cell แต่ล่ะช่อง ซึ่งเรราสามารถที่จะอ่านได้ทีละ Cell หรือจะ Loop แล้วไปสร้างเป็นพวก DataTable , List<T> หรืออื่นๆ ก็ได้เช่นเดียวกัน

Language Code : VB.NET || C#

Framework : 1,2,3,4

Example 1 : การอ่าน Cell แบบง่าย ๆ

ASP.NET Excel EPPlus

Code (VB.Net)

        Dim excel As New FileInfo(Server.MapPath("Xls/myData.xlsx"))
        Using package = New ExcelPackage(excel)
            Dim workbook = package.Workbook

            '*** Sheet 1
            Dim worksheet = workbook.Worksheets.First()

            '*** Result
            Me.lblResult1.Text = worksheet.Cells("A1").Text
            Me.lblResult2.Text = worksheet.Cells("B2").Text
            Me.lblResult3.Text = worksheet.Cells("C3").Text
        End Using


Screenshot

ASP.NET Excel EPPlus


Example 2 : การอ่าน Cell ด้วยการลูปข้อมูล

ASP.NET Excel EPPlus

Code (VB.Net)

    Public Class ExcelData
        Public Property Col1() As String
            Get
                Return m_Col1
            End Get
            Set
                m_Col1 = Value
            End Set
        End Property
        Private m_Col1 As String
        Public Property Col2() As String
            Get
                Return m_Col2
            End Get
            Set
                m_Col2 = Value
            End Set
        End Property
        Private m_Col2 As String
        Public Property Col3() As String
            Get
                Return m_Col3
            End Get
            Set
                m_Col3 = Value
            End Set
        End Property
        Private m_Col3 As String
        Public Property Col4() As String
            Get
                Return m_Col4
            End Get
            Set
                m_Col4 = Value
            End Set
        End Property
        Private m_Col4 As String
        Public Property Col5() As String
            Get
                Return m_Col5
            End Get
            Set
                m_Col5 = Value
            End Set
        End Property
        Private m_Col5 As String
    End Class

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim excel As New FileInfo(Server.MapPath("Xls/myData.xlsx"))
        Using package = New ExcelPackage(excel)
            Dim workbook = package.Workbook

            '*** Sheet 1
            Dim worksheet = workbook.Worksheets.First()

            '*** Retrieve to List
            Dim ls = New List(Of ExcelData)()
            Dim totalRows As Integer = worksheet.Dimension.End.Row
            For i As Integer = 1 To totalRows
                ls.Add(New ExcelData() With {
                    .Col1 = worksheet.Cells(i, 1).Text.ToString(),
                    .Col2 = worksheet.Cells(i, 2).Text.ToString(),
                    .Col3 = worksheet.Cells(i, 3).Text.ToString(),
                    .Col4 = worksheet.Cells(i, 4).Text.ToString(),
                    .Col5 = worksheet.Cells(i, 5).Text.ToString()
            })
            Next

            '*** Display to GridView
            Me.myGridView.DataSource = ls
            Me.myGridView.DataBind()
        End Using

    End Sub


Screenshot

ASP.NET Excel EPPlus

ในตัวอย่างที่ 2 สามารถใช้ GridView เพื่อมาแสดงค่าที่อยู่ในรูปแบบ DataSource ของ List






   
Share


ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท


ลองใช้ค้นหาข้อมูล


   


Bookmark.   
       
  By : ThaiCreate.Com Team (บทความเป็นลิขสิทธิ์ของเว็บไทยครีเอทห้ามนำเผยแพร่ ณ เว็บไซต์อื่น ๆ)
  Score Rating :  
  Create/Update Date : 2017-03-20 22:08:49 / 2017-03-20 22:46:29
  Download : No files
 Sponsored Links / Related

 
ASP.Net Excel & EPPlus Generate Excel file
Rating :

 
ASP.Net Excel & EPPlus Cell Ranges/Border
Rating :

 
ASP.Net Excel & EPPlus Cell styling (Color, Font, Alignments)
Rating :

 
ASP.Net Excel & EPPlus Open Excel and Write Excel (Template)
Rating :

 
ASP.Net Excel & EPPlus Convert Excel DataTable
Rating :

 
ASP.Net Excel & EPPlus Import Excel To Database
Rating :

 
ASP.Net Excel & EPPlus Generate Excel Report from Database
Rating :


ThaiCreate.Com Forum


Comunity Forum Free Web Script
Jobs Freelance Free Uploads
Free Web Hosting Free Tools

สอน PHP ผ่าน Youtube ฟรี
สอน Android การเขียนโปรแกรม Android
สอน Windows Phone การเขียนโปรแกรม Windows Phone 7 และ 8
สอน iOS การเขียนโปรแกรม iPhone, iPad
สอน Java การเขียนโปรแกรม ภาษา Java
สอน Java GUI การเขียนโปรแกรม ภาษา Java GUI
สอน JSP การเขียนโปรแกรม ภาษา Java
สอน jQuery การเขียนโปรแกรม ภาษา jQuery
สอน .Net การเขียนโปรแกรม ภาษา .Net
Free Tutorial
สอน Google Maps Api
สอน Windows Service
สอน Entity Framework
สอน Android
สอน Java เขียน Java
Java GUI Swing
สอน JSP (Web App)
iOS (iPhone,iPad)
Windows Phone
Windows Azure
Windows Store
Laravel Framework
Yii PHP Framework
สอน jQuery
สอน jQuery กับ Ajax
สอน PHP OOP (Vdo)
Ajax Tutorials
SQL Tutorials
สอน SQL (Part 2)
JavaScript Tutorial
Javascript Tips
VBScript Tutorial
VBScript Validation
Microsoft Access
MySQL Tutorials
-- Stored Procedure
MariaDB Database
SQL Server Tutorial
SQL Server 2005
SQL Server 2008
SQL Server 2012
-- Stored Procedure
Oracle Database
-- Stored Procedure
SVN (Subversion)
แนวทางการทำ SEO
ปรับแต่งเว็บให้โหลดเร็ว


Hit Link
   







Load balance : Server 05
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่