How to retian the style defined in the text using the Aspose.Word

Hi Team,

We are creating a word document using document template file (dotx) file.
Let us take we have a mail merge field “FailureDescription” and we are writing the information reading from database.

Let us assume the value present in database is “This is Failure Description testing Only. Please ignore this.”

After generation of document let us assume we have modified the text style of “Failure Description testing” ( from the total text “This is Failure Description testing Only. Please ignore this.”) to bold

So now the text present is
“This is Failure Description testing Only. Please ignore this.”.

Then we are trying to get the text present between the two styles we defined in the word document and saving again back to database.

We are getting the text fine as “This is Failure Description testing Only. Please ignore this.”. However lost the formatting.
So again if we are writing back to report after saving that to database, the styling is not present. It coming as

“This is Failure Description testing Only. Please ignore this.” instead of

"This is Failure Description testing Only. Please ignore this.

ArrayList failureDescFAArray = DAL.ParagraphsByStyleName(doc, "Failure FADescription");
ArrayList summaryFAAnalysis = DAL.ParagraphsByStyleName(doc, "Summary FAAnalysis");

ArrayList failureDescFANodes = DAL.ExtractContent((Node)failureDescFAArray[0], (Node)summaryFAAnalysis[0], false);
failDesc = DAL.GenerateDocument(doc, failureDescFANodes).GetText();

Could you please help me on this?

Regards,
Rajesh

Hi Team,

We attaching a small web application which we have developed for this.

In side the code if we see while reading the text present in side the styles, then the plain test is only coming instead of the style.

In the referred coded we have the “Fetch Report” button and on its click it fetching the text present in side the two style nodes ( TestDescStart, ItemDeatilsStart).

We are writing the fetched information to a label.

However we are not getting text along with style.
Could you please help me on this.
Regards.
Rajesjh

Hi Rajesh,

Thanks for your inquiry. Please note that CompositeNode.GetText method returns the text of this node and of all its children. The output text is simple plain text without formatting.

Please use Document.ToString(SaveFormat.Html) method as shown below to get the required output.

ArrayList testdeatilstart = ParagraphsByStyleName(doc, "TestDescStart");
ArrayList itemdetailstart = ParagraphsByStyleName(doc, "ItemDeatilsStart");
ArrayList failureDescFANodes = ExtractContent((Node)testdeatilstart[0], (Node)itemdetailstart[0], false);
Document finalDoc = GenerateDocument(doc, failureDescFANodes);
string failDesc = finalDoc.ToString(SaveFormat.Html);
lblDesc.Text = failDesc;