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.