In Octave, I have a string
outstr = 'Line1 \n Line2 \n Line3 \n'
which I like to copy to the clipboard and then insert it into an Excel-sheet by pasting from the clipboard.
The clipboard
function of octave does not work at all, even for simplest strings. I don't know why. And directly storing to Excel is not an option as not suffiently flexible.
As I am already using vbscript with Octave with other tasks, I'd like to use it in this case as well. So here is what I came up with:
Vbscript (borrowed from the final answer here:
Set objShell1 = WScript.CreateObject("WScript.Shell")
objShell1.Run "cmd /c echo " & Trim(WScript.Arguments(0)) & "|clip"
Set objShell1 = Nothing
which works great for one-line strings.
Then I use this wrapper function in octave:
function copy2clipboard(outstr)
pathWrapper = fileparts(mfilename('fullpath'));
system( [pathWrapper '\copy2clipboard.vbs "' outstr '"'] );
end
For one-line strings this all works as desired, but VBscript is not able to process the newline character \n
. I couldn't manage to substitute it with the VBscript equivalents like VbCrLf.
Solutions working for Matlab are fine, but only using octave-compatible syntax.
What do you suggest?