You probably already know that you can assign a text string to _CLIPTEXT to place text onto (or read text from) the Windows clipboard.
But what if you wanted to put record data, especially for more than one record? For example, you want to put some summary data that you compiled using SELECT...GROUP BY onto the Windows clipboard so that the user could paste it onto a spreadsheet or word processing program.
DataToClip to the rescue! This is a method of the VFP application object, so we'll need to prepend the _VFP object reference to any calls to it.
The syntax of DataToClip is:
[tab]_VFP.DataToClip(cAlias or nArea, nNumofRecs, nFormat)
All of these are optional; the default is the current work area/alias, all of the records, and fields separated by spaces. Use the nFormat of 3 to separate fields by tabs; this seems to work the best when pasting into Excel.
This example puts all records in the currently selected alias onto the Windows clipboard:
[tab]nNumRecsCopied = _vfp.datatoclip( , ,3)
notice the use of blanks/commas in place of the ommited first and second parameters. After issuing the above command (with a table already open), I can open Excel and ^V the data with each column placed appropriately. Cool.
Robert Bradley
But what if you wanted to put record data, especially for more than one record? For example, you want to put some summary data that you compiled using SELECT...GROUP BY onto the Windows clipboard so that the user could paste it onto a spreadsheet or word processing program.
DataToClip to the rescue! This is a method of the VFP application object, so we'll need to prepend the _VFP object reference to any calls to it.
The syntax of DataToClip is:
[tab]_VFP.DataToClip(cAlias or nArea, nNumofRecs, nFormat)
All of these are optional; the default is the current work area/alias, all of the records, and fields separated by spaces. Use the nFormat of 3 to separate fields by tabs; this seems to work the best when pasting into Excel.
This example puts all records in the currently selected alias onto the Windows clipboard:
[tab]nNumRecsCopied = _vfp.datatoclip( , ,3)
notice the use of blanks/commas in place of the ommited first and second parameters. After issuing the above command (with a table already open), I can open Excel and ^V the data with each column placed appropriately. Cool.
Robert Bradley