How can I copy values from UITABLE placed in UIFIGURE to clipboard?

I created matlab application using App Designer and it contains uitable. I am trying to copy selected values from the table to Excel using CTRL + C command. It worked with uitable created using GUIDE.

 채택된 답변

Achyutha Hosahalli
Achyutha Hosahalli 2017년 11월 21일

0 개 추천

App Designer uitable does not support copy and paste to clipboard in both R2017a and R2017b. As a workaround, one can use the following method:
  1. Use clipboard function inside UITableCellSelection, note that this would not retain table format when paste the data to excel or notepad etc;
  2. Use a button, and call functions like xlswrite or writetable inside the button callback

댓글 수: 4

David
David 2019년 5월 9일
편집: David 2019년 5월 9일
Is this still necessary in 2019a? Or is copy and pasting to / from the clipboard supported "for free"? (appears to not be the case) In meantime we've written our own paste code using the clipboard command in a callback (UIFigureKeyPress, because there's only one table where it could happen).
Is it possible to copy the data in uitable with the format retained?The Clipboard Fcn seems unable to achieve the goal.
Hamze Msheik
Hamze Msheik 2022년 1월 26일
편집: Hamze Msheik 2022년 1월 26일
First create (KeyPress) for your table
if mixed data is in it
key = event.Key;
if(strcmp(key,'c') || strcmp(key,'C') )
if(strcmp (app.previouskey,'control'))
asd=cell2str(app.YOURTABLE.Data);
asd=strrep(asd,';',newline);
asd=strrep(asd,[char(39) ',' char(39)],' ');
clipboard('copy',asd)
end
end
app.previouskey=key;
OR if purely Numbers
key = event.Key;
if(strcmp(key,'c') || strcmp(key,'C') )
if(strcmp (app.previouskey,'control'))
asd=num2str(app.YOURTABLE.Data);
asd=strrep(asd,';',newline);
asd=strrep(asd,[char(39) ',' char(39)],' ');
clipboard('copy',asd)
end
end
app.previouskey=key;
Can you explain case 1 with an example?

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Y.S.
Y.S. 2022년 6월 22일

0 개 추천

I'm using Matlab R2021a
If you define a ContextMenu, you can assign 'Accelerators'
when I select the accelerator 'C', the keypress CTRL-C automatically initiales the callback (see screenshot)
as for the actual copy-paste; I followed https://nl.mathworks.com/matlabcentral/answers/1854-copy-utiable-to-excel, which read uitable as a string. using e,.g. textscan you can format the string with tabs ('\t') or linebreaks ('\n') to make it suited to copy in a nice formatted way directly (and into e.g. Excel).

카테고리

질문:

2017년 11월 9일

답변:

2022년 6월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by