필터 지우기
필터 지우기

Adding a newline character

조회 수: 24 (최근 30일)
Wilson Bardeskar
Wilson Bardeskar 2011년 4월 6일
I have a string array. I need to print all the strings in the array line by line in a word report through Matlab report Generation with Each string on a new line. I am not able to do it. Adding newline character '\n' generates a continuous string with the characters \n included in it. even char(10) does not work.
This is sample code
for i = 1:length(My_Array)
setParent(rptgen.cfr_text('Content',My_Array{i}), Paragraph_Block);
setParent(rptgen.cfr_text('Content',char(10)), Paragraph_Block);
Can anybody tell me what I need to do to get the right results?

채택된 답변

Fangjun Jiang
Fangjun Jiang 2011년 4월 6일
How about the carriage return, char(13)?
  댓글 수: 4
Wilson Bardeskar
Wilson Bardeskar 2011년 4월 6일
It works with paragraph, but my need is that I need to have two different blocks of texts with fifferent font and textsizes. I use paragraph for bigger text and TEXT for smaller one.
Using the stylesheet I can set the font for all paragrapha in the report or all text. do you know a way I can have some font properties for one paragraph and different font properties for another
Fangjun Jiang
Fangjun Jiang 2011년 4월 6일
See Andrew Newell's new post. That might be the answer. I think the "isLiteral" property might refer to "Retain space and carriage returns".
Regarding setting font for paragraph under stylesheet, I am not sure. I would guess it is possible. Just like you typing a Word document, you can always select a style first for the paragraph, then change the font of the whole or part of the paragraph later.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Andrew Newell
Andrew Newell 2011년 4월 6일
Try
sprintf('%s\n',My_Array{i})
  댓글 수: 1
Wilson Bardeskar
Wilson Bardeskar 2011년 4월 6일
thanks Andrew,
Tried that but same result. :(
I get all strings end to end. Not on new line.

댓글을 달려면 로그인하십시오.


Andrew Newell
Andrew Newell 2011년 4월 6일
Unfortunately, I don't have the Report Generator, and the online documentation about the rptgen classes is not very helpful. However, I notice that in the documentation for text, one of the Style options is Retain spaces and carriage returns. If you can figure out how to set this, you might get what you want. Try typing
h = rptgen.cfr_text;
set(h)
and see what you get.
It appears that the documentation is mostly for people using the GUI interface. Have you tried using that?
  댓글 수: 3
Wilson Bardeskar
Wilson Bardeskar 2011년 4월 6일
Andrew, Thanks a million!!
isLiteral parameter when set to true gives the right result. I formed a string using a loop with char(10) in between each string
and called the
setParent(rptgen.cfr_text('Content',formedstring,'isLiteral',true), Paragraph_Block);
It worked !!!
Andrew Newell
Andrew Newell 2011년 4월 6일
I'm glad I could help with my shots in the dark! You might want to send MATLAB some feedback on their help for this subject.

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by