Copy utiable to Excel

I have populated a uitable created in GUIDE with some data. I want to be able to click a button and have the uitable data copied to clipboard so I can then paste into Excel. So far I have the following code for a button callback:
s=get(handles.uitable1,'data');
clipboard('copy', s);
However, this just creates one large string in excel and not each uitable cell to an exel cell. any suggestions. Thanks Jason

回答 (1 件)

Robert Cumming
Robert Cumming 2011 年 2 月 24 日

0 投票

you will see in the clipboard help that clipboard converts your matrix to a string using MAT2STR.
In the past I've had a similar issue and in that case I created the string myself with delimiter between each number (build it with sprintf and formatting).

7 件のコメント

Jason
Jason 2011 年 2 月 24 日
Thanks Robert, could you share how you did it.
Thanks
Robert Cumming
Robert Cumming 2011 年 2 月 24 日
%% Something like this would do it:
d = rand(5,2);
size_d = size(d);
str = '';
for i=1:size_d(1)
for j=1:size_d(2)
str = sprintf ( '%s%f\t', str, d(i,j) );
end
str = sprintf ( '%s\n', str );
end
clipboard ( 'copy', str );
Jason
Jason 2011 年 2 月 24 日
Thankyou.
Augustine Bui
Augustine Bui 2013 年 5 月 7 日
Thank you so much!
Paolo Minotti
Paolo Minotti 2017 年 9 月 21 日
Thank you very much!
I suggest an edit
function f_clipboard(d)
size_d = size(d);
str = '';
for i = 1:size_d(1)
for j = 1:size_d(2)
if j == size_d(2)
str = sprintf('%s%f',str,d(i,j));
else
str = sprintf('%s%f\t',str,d(i,j));
end
end
str = sprintf('%s\n',str);
end
clipboard ('copy',str);
end
so that there's no empty column on the right. :)
Jay Basingerja
Jay Basingerja 2020 年 4 月 2 日
Thank you Paolo and Robert, this worked for me as well.
Frustrating that it isn't already something addressed by Mathworks, because that was a key reason I was building my GUI in the first place, to provide data that could be copied out to Excel and pasted where the user wanted it, but this will serve as an acceptable workaround.
Ding Cloud
Ding Cloud 2020 年 12 月 18 日
thanks, Paolo Minotti, your method is really useful.

サインインしてコメントする。

質問済み:

2011 年 2 月 23 日

コメント済み:

2020 年 12 月 18 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by