@@ -26,11 +26,22 @@ def read_clipboard(**kwargs): # pragma: no cover
26
26
return read_table (StringIO (text ), ** kwargs )
27
27
28
28
29
- def to_clipboard (obj , sep = None , ** kwargs ): # pragma: no cover
29
+ def to_clipboard (obj , excel = None , sep = None , ** kwargs ): # pragma: no cover
30
30
"""
31
31
Attempt to write text representation of object to the system clipboard
32
32
The clipboard can be then pasted into Excel for example.
33
33
34
+ Parameters
35
+ ----------
36
+ obj : the object to write to the clipboard
37
+ excel : boolean, defaults to True
38
+ if True, use the provided separator, writing in a csv
39
+ format for allowing easy pasting into excel.
40
+ if False, write a string representation of the object
41
+ to the clipboard
42
+ sep : optional, defaults to tab
43
+ other keywords are passed to to_csv
44
+
34
45
Notes
35
46
-----
36
47
Requirements for your platform
@@ -39,12 +50,19 @@ def to_clipboard(obj, sep=None, **kwargs): # pragma: no cover
39
50
- OS X:
40
51
"""
41
52
from pandas .util .clipboard import clipboard_set
42
- try :
43
- if sep is None :
44
- sep = '\t '
45
- buf = StringIO ()
46
- obj .to_csv (buf ,sep = sep , ** kwargs )
47
- clipboard_set (buf .getvalue ())
48
- except :
49
- clipboard_set (str (obj ))
53
+ if excel is None :
54
+ excel = True
55
+
56
+ if excel :
57
+ try :
58
+ if sep is None :
59
+ sep = '\t '
60
+ buf = StringIO ()
61
+ obj .to_csv (buf ,sep = sep , ** kwargs )
62
+ clipboard_set (buf .getvalue ())
63
+ return
64
+ except :
65
+ pass
66
+
67
+ clipboard_set (str (obj ))
50
68
0 commit comments