Azzera filtri
Azzera filtri

Copying text from edit box in GUI to matlab report.

4 visualizzazioni (ultimi 30 giorni)
I have created a GUI in which there is an editbox where user enters certain text. This text is then required to be added in a report which is generated at a later stage. I am using a code which is something like this:
%%Code to get text entered in editbox
handles.text=get(handles.editbox,'string');
%%Code to add text to matlab report (via DOM API)
text_to_be_added=Paragraph(handles.text);
append(report,text_to_be_added);
Now my problem is as long as the text entered in editbox is a single line the result is fine (Text is copied as it is from editbox to report). But if I add a new line in the text which is to be entered in editbox (by pressing enter key), the text which is printed in report is totally disoriented.
Eg: If the text in edit box is: This month is july. Then the text saved in my report is: This month is july.
But if the text in edit box is:
This month is
july.
Then the text saved in report looks like this:
Tjhuilsy .m o n t h i s
Is their any way this problem can be fixed. I know adding '\n' rather than pressing enter key will add a new line in report but is their any other way in which matlab can recognize enter key press to add a new line automatically.
  2 Commenti
Shameer Parmar
Shameer Parmar il 29 Lug 2016
Are you sure, you can enter the data in multiple lines in single editbox ? I guess Its not possible... Single edit box is not allow to enter the data in multiple lines.. Please confirm this..
Geoff Hayes
Geoff Hayes il 30 Lug 2016
Shameer - Yes, multiple lines of text can be entered into an edit text box (so long as the Max property is greater than the Min property).

Accedi per commentare.

Risposta accettata

Geoff Hayes
Geoff Hayes il 30 Lug 2016
Sudhanshu - you mention that typing \n works. Can you perhaps inject this character after the user has typed in the text into the edit box? Note that
handles.text=get(handles.editbox,'string');
will be a cell array of strings, one for each line in the edit box. So you could create a single line string from these multiple strings, concatenating each together and separating each by a \n. For example,
strData = get(handles.edit1,'String');
handles.text = strData{1};
if size(strData,1) > 1
for k=2:size(strData,1)
handles.text = [handles.text '\n' strData{k}];
end
end
However, I don't know if this will be sufficient when adding it your report.
  1 Commento
Sudhanshu Goel
Sudhanshu Goel il 1 Ago 2016
Thanks a lot Geoff. Your approach works like a charm. The code needed minor tweaks.
strData = get(handles.edit1,'String');
handles.text = strData(1,:);
if size(strData,1) > 1
for k=2:size(strData,1)
handles.text = [handles.text '\n' strData(k,:)];
end
end
Once again thanks for your help.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Environment and Settings in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by