如何将MSFlexGrid表格里面的数据复制出来?
如何将MSFlexGrid表格里面的数据复制出来?用了下,发现这个控件没有这个功能,望高手能指导!!!!
自己把所需要的数据拼起来,然后放到剪切板 上去就可是复制.
放上数据后,清掉原数据就是 剪切.
需要你自己操作剪切板,就是最简单的,置文本功能放数据上去吧.
你好,给你提供函数,非常容易的做到: Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long Public Function ExportToExcel(objMsg As MSFlexGrid) As Boolean '********************************************************************* ' 将MSFlexGrid的查询结果保存到Excel里。调用 CallExportToExcel(objMsg As MSFlexGrid) ' 完全可以保存查询的结果到Excel里。 'Purpose: Export data on grid to an Excel file 'Input : 'Output : True if successful, else return False 'Others : Global variable used: ' Module variable used: '******************************************************************** On Error GoTo ExportToExcel_ErrorHandler Dim objExcelApp As Object Dim objExcelBook As Object Dim objExcelSheet As Object 'Whether Excel exists, if not, try to create On Error Resume Next Set objExcelApp = GetObject(, "Excel.Application") If Err.Number <> 0 Then Set objExcelApp = CreateObject("Excel.Application") End If On Error GoTo ExportToExcel_ErrorHandler Set objExcelBook = objExcelApp.Workbooks.Add Set objExcelSheet = objExcelBook.Worksheets(1) If Val(objExcelApp.Application.Version) >= 8 Then Set objExcelSheet = objExcelApp.ActiveSheet Else Set objExcelSheet = objExcelApp End If Dim lngRowsCount As Long, lngColumnsCount As Long, lngRow As Long, lngColumn As Long Dim strText As String lngRowsCount = objMsg.Rows lngColumnsCount = objMsg.Cols For lngRow = 1 To lngRowsCount For lngColumn = 1 To lngColumnsCount strText = objMsg.TextMatrix(lngRow - 1, lngColumn - 1) If IsNull(strText) = False And strText <> "" Then objExcelSheet.Cells(lngRow, lngColumn) = strText End If Next Next objExcelApp.Visible = True Set objExcelSheet = Nothing Set objExcelBook = Nothing Set objExcelApp = Nothing ExportToExcel = True ErrorHandler: Exit Function ExportToExcel_ErrorHandler: MsgBox Err.Description Resume ErrorHandler End Function