Vb.Net-Informations.com



     VB.NET Excel 2007 Tutorials

 * Read entire worksheet in an Excel workbook


Read entire worksheet in an Excel workbook

In the following section you can see How to find the last row data in Excel worksheet or How to find the Used area in a worksheet. For finding last row we are using WorkSheet.UsedRange . It will return the last cell . The follwoing code open an Excel file and read the entire content.


         VB.NET Source Code Download           Print Source Code
         Read entire worksheet in an Excel workbook - Download
        
Vb.Net Help

Imports Excel = Microsoft.Office.Interop.Excel
Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, _
  ByVal e As System.EventArgs) Handles Button1.Click

        Dim xlApp As Excel.Application
        Dim xlWorkBook As Excel.Workbook
        Dim xlWorkSheet As Excel.Worksheet
        Dim range As Excel.Range
        Dim rCnt As Integer
        Dim cCnt As Integer
        Dim Obj As Object

        xlApp = New Excel.ApplicationClass
        xlWorkBook = xlApp.Workbooks.Open("c:\vbexcel.xlsx")
        xlWorkSheet = xlWorkBook.Worksheets("sheet1")

        range = xlWorkSheet.UsedRange

        For rCnt = 1 To range.Rows.Count
            For cCnt = 1 To range.Columns.Count
                Obj = CType(range.Cells(rCnt, cCnt), Excel.Range)
                MsgBox(Obj.value)
            Next
        Next

        xlWorkBook.Close()
        xlApp.Quit()

        releaseObject(xlApp)
        releaseObject(xlWorkBook)
        releaseObject(xlWorkSheet)
    End Sub

    Private Sub releaseObject(ByVal obj As Object)
        Try
            System.Runtime.InteropServices.Marshal.ReleaseComObject(obj)
            obj = Nothing
        Catch ex As Exception
            obj = Nothing
        Finally
            GC.Collect()
        End Try
    End Sub
End Class

When you execute this source code the program read all content from Excel file.
VB.NET 2005 Excel 2007 Related Contents
*     How to create an Excel 2007 file in VB.NET 2005
*     How to open or read an existing Excel 2007 file in VB.NET 2005
*     How to Format Excel 2007 Page in VB.NET
*     How to insert a Picture in Excel 2007 through programing on VB.NET 2005
*     How to insert a background Picture in Excel 2007 through VB.NET 2005
*     How to create a Chart in Excel 2007 in VB.NET
*     How to export a Chart in Excel 2007 as Picture file from VB.NET
*     How to Excel 2007 Chart in VB.NET Picture Box
*     How to Excel 2007 DataBar in VB.NET
*     How to Excel 2007 Data Validation Input Message
*     How to read data from excel using OLEDB
*     How to insert cell data in an Excel file using OLEDB
*     How to update cell data in an Excel file using OLEDB
*     How to export from database to excel
*     How to export from DataGridView to excel

VB.Net Related Topics
*     Microsoft .Net Framework Tutorials
*     VB.NET Language Basics Tutorials
*     VB.NET Program Flow Control Tutorials
*     VB.NET Collections Tutorials
*     VB.NET String Tutorials
*     VB.NET Files Tutorials
*     VB.NET Excel 2007 Tutorials
*     VB.NET Crystal Reports Tutorials
*     VB.NET Communications Tutorial
*     VB.NET ADO.NET Tutorial with source code
*     ADO.NET Data Providers help and Tutorial
*     VB.NET ADO.NET Dataset Tutorial
*     ADO.NET DataAdapter and Dataset
*     VB.NET ADO.NET DataView Tutorial
*     VB.NET Remoting Tutorial
*     VB.NET XML Tutorial
Search here for more Vb.Net Source Code :


   Categories

    HOME
    VB.NET
    CSHARP

 
 
   













  |  Home   |  SiteMap   |  About   |
net-informations.com (C) 2010 All Rights Reserved