Vb. NET Exporting Excel Principles

Source: Internet
Author: User

In the VB version of the room we have been exposed to the export of Excel function, again contact This function has a different understanding
First, the principle
    To implement the ability to export Excel, you first refer to the namespace in order to use the methods and classes under that namespace
Imports Microsoft.Office.Interop

    Then you need to create an instance of the classes you need to export in Excel, create an Excel app, workbooks, and tables
    
Dim xlapp, Xlbook, xlsheet as Object        xlapp = CreateObject ("Excel.Application")        xlbook = XlApp.Workbooks.Add        xlsheet = Xlbook.worksheets ()

    Once created, you can write the data you want to go to an Excel-instantiated table
Second, the Code
    In the engine room, we're all going to export the data from the DataGridView.
 
        Dim xlapp, Xlbook, xlsheet as Object        xlapp = CreateObject ("Excel.Application")        xlbook = XlApp.Workbooks.Add        xlsheet = xlbook.worksheets ()        ' make sheet visible        xlapp.visible = True        ' export title in DataGridView        Dim Cols as Integer for        Cols = 1 to DataGrid.Columns.Count            xlapp.cells (1, Cols) = Datagrid.columns (Cols-1). HeaderText        Next        ' exports data in DataGridView by line        Dim i As Integer for        i = 0 to datagrid.rowcount-1            Dim J A S Integer            for j = 0 to Datagrid.columncount-1                ' determines whether the data in the DataGridView is exported                if Me.datagrid (j, i). Value is System.DBNull.Value then                    xlapp.cells (i = 2, j = 1) = "" "                Else                    xlapp.cells (i + 2, j + 1) = DataGrid ( J, i). Value.tostring                End If            next        Next

    So that we can achieve the export of Excel function, know the principle, and then encounter similar problems will be easy to solve
Iii. Summary
    Such technology will need to go back to study after implementation, the impression and experience are more profound

Vb. NET Exporting Excel Principles

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.