How can I print any object into system clipboard just like printfn "%A" does?
it seems I cannot simply using clipboard.setdataobject().
views:
103answers:
1
+2
A:
You can use the spritnf function, which has the same formatting capabilities as printf but returns the formatted string as the result. To store the string in the clipboard once you have it, you can use the SetText method (you'll need a reference to System.Windows.Forms):
open System.Windows.Forms
let what = [1;2;3]
let str = sprintf "%A" what
Clipboard.SetText(str)
After running this code, the clipboard should contain a nicely formatted F# list "[1; 2; 3]".
Tomas Petricek
2010-03-03 19:02:44
beat me to it :)
Mauricio Scheffer
2010-03-03 19:03:31
thanks. this is very neat. if I want to quickly copy data into excel in fsi.exe, is there a better way than this?
ahala
2010-03-03 19:12:00
You can use office automation (e.g. reference Microsoft.Office.Interop.Excel) to programmatically poke data into the spreadsheet (but offhand I don't know all the details of how).
Brian
2010-03-03 19:25:38
I have an example that creates Excel spreadsheet and inserts some data into it in my functional programming book in Chapter 13. You can get the source code from: http://code.msdn.microsoft.com/realworldfp
Tomas Petricek
2010-03-03 19:49:27