How to export data in the MSFlexGrid control of the data room charging system to Excel

Source: Internet
Author: User
There are many ways to export data from the MSFlexGrid control to an Excel table. I think they are all the same. In general, vb first calls Excel and then imports the data into it. In the process of data export, I learned the following: Below is the procedure for exporting the data of the MSFlexGrid control to Excel. 1 first make sure that Microsoft

There are many ways to export data from the MSFlexGrid control to an Excel table. I think they are all the same. In general, vb first calls Excel and then imports the data into it. In the process of data export, I learned the following: Below is the procedure for exporting the data of the MSFlexGrid control to Excel. 1 first make sure that Microsoft

There are many ways to export data from the MSFlexGrid control to an Excel table. I think they are all the same. In general, vb first calls Excel and then imports the data into it. In the process of data export, I learned the following: Below is the procedure for exporting the data of the MSFlexGrid control to Excel.

1 first make sure that Microsoft Excel 14.0 Object Library and Microsoft ActiveX Data Objects 2.6 Libray are referenced in the project

Code section,

Private Sub Command2_Click () Dim xlsApp As Excel. application 'defines the Excel program Dim xlsBook As Excel. workbook' defines the Workbook Dim xlsSheet As Excel. worksheet 'defines the Worksheet Dim I As Long Dim j As Long Set xlsApp = CreateObject ("Excel. application ") 'create the Application Set xlsBook = xlsApp. workbooks. add Set xlsSheet = xlsBook. worksheets (1) 'sets the application table With xlsApp. rows (1 ). font. bold = True End With 'write the content of MSFlexGrid1 To the workbook For I = 0 To MSFlexGrid1.Rows-1 For j = 0 To MSFlexGrid1.Cols-1 xlsSheet. cells (I + 1, j + 1) = "'" & MSFlexGrid1.TextMatrix (I, j) Next j Next I xlsApp. visible = True 'Show the workbook xlsSheet. printOut preview: = True 'to enter the print preview page xlsBook. saveAs App. path & "\ Test.xls" 'Save Path and file name Set xlsApp = Nothing' release control End Sub

The above Code directly enters the print preview interface. If you want to directly obtain a workbook, you can comment out xlsSheet. PrintOut preview: = True.

In my opinion, the procedure for vb to call Excel to import data from the MSFlexGrid control to Excel is similar to that of using ADO objects. The object is declared first, then an object is created, and finally a series of operations are performed on it.

It is not yet complete and needs to be mined by other methods.


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.