Copying text from edit box in GUI to matlab report.

4 次查看(过去 30 天)
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 个评论
Shameer Parmar
Shameer Parmar 2016-7-29
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 2016-7-30
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).

请先登录,再进行评论。

采纳的回答

Geoff Hayes
Geoff Hayes 2016-7-30
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 个评论
Sudhanshu Goel
Sudhanshu Goel 2016-8-1
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Environment and Settings 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by