Effacer les filtres
Effacer les filtres

Writing on multiple lines inside a uitable

37 vues (au cours des 30 derniers jours)
Alexander
Alexander le 9 Oct 2023
Commenté : dpb le 16 Oct 2023
I am creating a report generator and attempting to add an AdobeSign block to the end of the generated report (which is then saved as a pdf). I am trying to replicate the text used in a Word Document that AdobeSign replaces to input signatures. One of the fields is intended to be a double line as seen in the signature field below:
I have generated a uitable that contains all of this information, but I am struggling to move the {{Em_es_:signer1:email }} to the second line. I am using \n in the fprintf to add a new line, but it does not appear in the table using the code below:
numSigs = input("How many signatories are there? ");
for i = 1:numSigs
name{i} = sprintf('{{ n%1d_es_:signer%1d:fullname }}', i, i);
sigEmail{i} = sprintf('{{ Sig%1d_es_:signer%1d:signature }}\n{{ Em_es_:signer%1d:email }}',i,i,i);
date{i} = sprintf('{{d1_es_:signer%1d:date}}',i);
title{i} = sprintf('{{ !nodename%1d }}',i);
end
t = table(name', sigEmail', date', title');
t.Properties.VariableNames = {'Name', 'Signature', 'Date', 'Title'}
f = uifigure('Units','inches','pos',[0.5,0.5,8,10.5],'numbertitle','off',...
'Name','FFD','color','w','visible','on');
ax = uiaxes(f);
uit = uitable(f, 'Data', table2cell(t), 'ColumnWidth', 'fit','ColumnName',t.Properties.VariableNames,...
'Units', 'inches', 'Position',[0.0,.25,8,.5*numSigs]);
This is probably a very roundabout solution to my problem, but it has worked so far...
Is this possible in uitable? or is there another option that would be simpler? Any advice on this issue would be appreciated.
  2 commentaires
dpb
dpb le 9 Oct 2023
The display formatting for a uitable doesn't honor \n and you can't change the row height...the newline is embedded in the string data displayed, but it's treated as just another character in the string, not as a control character.
I am unaware of any way to accomplish the above other than with an text control -- with a uitable as your overall interaction now, I think probably the simplest expedient will be to insert another row in the table.
Alexander
Alexander le 10 Oct 2023
Okay I will give that a shot. It won't be too difficult to do I just wanted to see if there was another way. Thanks for the help.

Connectez-vous pour commenter.

Réponses (1)

SAI SRUJAN
SAI SRUJAN le 16 Oct 2023
Hi Alexandar,
I understand that you are trying to figure out the appropiate approach incorporating multiple lines within a "uitable".
To split long strings into a multi-line string, this can easily be done by adding the "<br/>" wherever we wish the line to be split.To maintain the readability of the uitable, fontsize can be changed accordingly.You can follow the below given example to resolve the issue.
data = {'<html> Line1 <br/> Line 2 </html>', '<html> Line3 <br/> Line 4 </html>'};
uitable('Data', data);
Kindly refer to the following MATLAB Answer thread. This resource should provide you with valuable insights on how to proceed further.
You can refer to the below documentation to understand more about "uitable” in MATLAB.
  1 commentaire
dpb
dpb le 16 Oct 2023
@SAI SRUJAN -- read ALL the following discussion in the subject Answers thread -- it notes the uitable component is NOT the same as a child of an uiaxes which OP is using as in a regular figure axes; the most significant difference concerning this thread is that the uiaxes version does NOT support/use html rendering so the above data line will be rendered as the literal text in his app, not as multiple-line text.
On top of which, if one uses newline (char(10)) instead, the uitable in the uifigure doesn't honor the \n character; it is simply another embedded character inside the data string displayed as I noted in the above comment.
Interestingly, as the subject Answer thread notes since it was the actual subject of the Question, the newline is recognized and the column heading names will show multiple lines and the header row will automagically expand its height to display them. Unfortunately, that doesn't work with the data cells themselves...it just can't be done inside a uifigure, at least so far...

Connectez-vous pour commenter.

Catégories

En savoir plus sur Migrate GUIDE Apps dans Help Center et File Exchange

Produits


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by