- Adjust the 'ColumnEditable' property of the 'uitable' to be true.
- Adjust the 'ColumnWidth' property of the 'uitable' to 'fit'.
- Wrap the data within each cell of the 'uitable' using 'textwrap' function.
Read and show multiline XLS in App Designer
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I tried to find a solution to this, but failed. The situation is simple: I have an excel file with a lots of data, and I have an App Designer table, where I want to show them.
The problem is, that inside some cells there are very short or very long strings and designing a table with a huge cell is just looks ugly when there is only one or two words inside. Two idea came to my mind:
1) Word wrap - As I can found, App Designer's table is unable to wrap long texts into a new line automatically.
2) Put newline inside the XLS cells - This idea whould be also good, but it seems to me that App Designer's table is omitting any whitespace character.
I think I read the excel properly, since if I do
myXLSinput = readtable(myXLSlocation)
disp(myXLSinput)
inside the command window the "new line/carriage return" arrow appears where my new line is. I try to put it inside the table like this:
app.UITable.Data{rowIndex,colIndex} = myXLSinput{rowIndex,colIndex};
My data appears but everything inside the cell in is one line, where inside the XLS is in multiple lines.
Do you have any idea how can I complete this simple task?
0 commentaires
Réponses (1)
Rahul
le 12 Fév 2025
I understand that there is no direct workaround for the issue mentioned which involves multiple lines to be displayed while displaying the 'uitable' in MATLAB App Designer.
A possible workaround in this situation would be to:
Here is an example:
function ButtonPushed(app, event)
app.UITable.ColumnEditable = true;
app.UITable.ColumnWidth = {'fit'};
data = readtable('Book1.xls');
% Convert the table to a cell array
dataCell = table2cell(data);
for i = 1:size(dataCell, 1)
for j = 1:size(dataCell, 2)
if ischar(dataCell{i, j}) % Check if the content is a string
wrappedText = textwrap({dataCell{i, j}}, 50);
dataCell{i, j} = strjoin(wrappedText, '\n'); % Join lines with newline character
end
end
end
% Set the UITable Data property to the cell array
app.UITable.Data = dataCell;
% Optionally, set the column names of the UITable
app.UITable.ColumnName = data.Properties.VariableNames;
end
This would provide a scrollbar within the 'uitable' which can be used to read all the text content in a particular row horizontally as well as a scrollbar to go through different rows vertically.
NOTE: The attached 'table_app.mlapp' can be referred.
The following MathWorks documentations can be referred to know more:
'uitable.ColumnWidth': https://www.mathworks.com/help/matlab/ref/uitable.html#namevaluepairarguments
Hope this helps. Thanks.
0 commentaires
Voir également
Catégories
En savoir plus sur Develop Apps Using App Designer dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!