p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Visual Basic 2005 Basics (http://p2p.wrox.com/forumdisplay.php?f=137)
-   -   excel (http://p2p.wrox.com/showthread.php?t=41003)

mustang April 9th, 2006 09:45 AM

excel
 
i have a few excel sheets , how can i view them in my app.

or import them in a database


john.glenn965 July 18th, 2013 08:05 AM

Re: excel
 
Hi, to me the easiest way would be to export Excel to DataGridView like this:
Code:

' Load Excel (XLSX) from a file.
Dim workbook = ExcelFile.Load("Workbook.xlsx")

' Export active worksheet to DataGridView.
DataGridViewConverter.ExportToDataGridView(
    workbook.Worksheets.ActiveWorksheet,
    dataGridView,
    New ExportToDataGridViewOptions() With {.ColumnHeaders = True})

Also here is how to import Excel sheets to a DataSet, every sheet is a new DataTable:
Code:

Dim dataSet = New DataSet()

' Load Excel file.
Dim workbook = ExcelFile.Load("Workbook.xls")

' Export all worksheets to DataSet.
For Each worksheet In workbook.Worksheets
    ' Extract the data from the worksheet to newly created DataTable starting at
    ' first row and first column for 10 rows or until the first empty row appears.
    Dim dataTable = worksheet.CreateDataTable(New CreateDataTableOptions() With
        {
            .StartRow = 0,
            .StartColumn = 0,
            .NumberOfRows = 10,
            .ExtractDataOptions = ExtractDataOptions.StopAtFirstEmptyRow
        })
    dataTable.TableName = worksheet.Name

    ' Add DataTable to DataSet.
    dataSet.Tables.Add(dataTable)
Next



All times are GMT -4. The time now is 05:45 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.