How to select more than 1 selection using Listdlg and export the output to excel?
3 次查看(过去 30 天)
显示 更早的评论
Hello Guys,
This is my code to select an option
Weight_lbs={'1234','4561','4556','4545','3345'};
[indx1,tf1] = listdlg('PromptString',{'Select weight'},'SelectionMode','multiple','ListString',Weight_lbs);
s1=evalin('base','indx1');
if s1 == 1
Weight_lbs = 1234;
elseif s1 == 2
Weight_lbs = 4561;
elseif s1 == 3
Weight_lbs = 4556;
elseif s1 == 4
Weight_lbs = 4545;
elseif s1 == 5
Weight_lbs = 3345;
else
Weight_lbs = 3345;
end
Trailer={'pen','pencil','scale','eraser'};
[indx2,tf2] = listdlg('PromptString',{'Select weight'},'SelectionMode','multiple','ListString',Trailer);
s2=evalin('base','indx2');
if s2 == 1
Trailer = "pen";
elseif s2 == 2
Trailer ="pencil";
elseif s2 == 3
Trailer = "pencil";
elseif s2 == 4
Trailer = "scale";
else
Trailer = "pen";
end
I need to export the selected options to excelsheet.
I could able to export single selection but when I select more than 1 it is exporting the first selected ones. I know I cannot export both options because indx2 can take only one value.
For example, If I select 1234 and 4556 under weight and pen and pencil under Trailer. I should see 1234,4556 and pen,pencil in excel.
How to export both selected options ? Any ideas or suggestions greatly appreciated.
Thank you in advance
0 个评论
回答(1 个)
Benjamin Thompson
2022-2-15
Your code can be simplified quite a bit. Then use xlswrite to write out to Excel:
Weight_lbs={'1234','4561','4556','4545','3345'};
[indx1,tf1] = listdlg('PromptString',{'Select weight'},'SelectionMode','multiple','ListString',Weight_lbs);
Weight_lbs_selected = Weight_lbs(indx1);
xlswrite('sampleExcelFile', Weight_lbs_selected);
Trailer={'pen','pencil','scale','eraser'};
[indx2,tf2] = listdlg('PromptString',{'Select weight'},'SelectionMode','multiple','ListString',Trailer);
s2=evalin('base','indx2');
Trailor_selected = Trailer(indx2);
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!