Export uitable's data to a spreadsheet Excel
조회 수: 6 (최근 30일)
이전 댓글 표시
I have designed a GUI which has an uitable and a push button which, when is pressed, allows to export the uitable's data to an Excel spreadsheet. My problem is that I want to add the uitable's headers to the matrix Select which has the numeric values. This matrix is used by the pushbutton callback, as seen below:
htable = uitable(...);
...
SelecY = get(htable,'Data');
Callback of the pushbutton
function hExpExcelCallback(src,evt)
FileName = uiputfile('*.xls','Save as');
xlswrite(FileName,SelecY),
end
댓글 수: 0
채택된 답변
Fangjun Jiang
2011년 11월 9일
You need to do some processing in the case that the table data is all numerical, because the column header is returned in a cell array. The following example uses a uitable, but should apply to the table you have in your GUI as long as you have the handle.
h=uitable('Data',rand(2,3),'ColumnName',{'a','b','c'});
Data=get(h,'Data');
ColumnName=get(h,'ColumnName');
NewData=mat2cell(Data,ones(size(Data,1),1),ones(size(Data,2),1));
CombData=[ColumnName';NewData];
xlswrite(FileName,CombData);
댓글 수: 3
Hector Prieto
2014년 2월 2일
Dear @Fangjun Jiang,
I tried your example, but unfortunately it only works on Windows pc and I am using Macintosh. Can you please tell me how to implement this code on Macintosh?
Cheers
Héctor
Vito Marangelli
2015년 1월 1일
I have the same problem and I would like to know if Excel for Mac can be used with the command xlswrite
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!