Hi Team,
We are doing a small POC where we are getting the content for that paragraph using style defined for that paragraph using Aspose.Word.
We are getting the exact paragraph like below:
foreach (Paragraph paragraphtest in paragraphs)
{
if (paragraphtest.ParagraphFormat.Style.Name.ToLower() == “TestDescription”)
{
//Require Code inside here
}
}
Here we found that while user press “Enter” key from keyboard , then that paragraph is coming in the next line, however the style is still present in the last line and also appended to the next new line also. However we want the style needs to be present only for that paragraph only.
Similarly if user is pressing “Delete” or “Back Space”, then some time the style is also get deleted.
So again when we run that above so in case of “Enter” button, 2-3 or multiple times the style name is coming depending on how many times you have pressed the “Enter” button.
In case of Delete button, the style may be absent and the condition never satisfies.
PFA for the sample word document where we have two paragraphs and we have applied the style in the header/subject of the paragraph.
Could you please suggest on this?
Please revert in case of any issue.
Regards,
Rajesh
Hi Rajesh,
Thanks for your inquiry.
Rajesh@123:
Here we found that while user press “Enter” key from keyboard , then that paragraph is coming in the next line, however the style is still present in the last line and also appended to the next new line also. However we want the style needs to be present only for that paragraph only.
In this case, I suggest you please set the style of second paragraph by using ParagraphFormat.Style property. This property is used to get or set the paragraph style applied to this formatting.
Rajesh@123:
Similarly if user is pressing “Delete” or “Back Space”, then some time the style is also get deleted.
In case of Delete button, the style may be absent and the condition never satisfies.
If you remove all paragraphs of attached document, the styles TestDescription and TestSummary will not remove from the output document. Could you please share some more detail about this query? We will then provide you more information on this.
Hello Tahir,
Thanks for replying.
When we are pressing the “Enter” button actually the style is repeated, hence if we are trying to getting the text/node details using that style while comparing the Paragraph style name, then it is not performing as expected as it satisfies for two condition as now two paragraphs present with the same style name.
In case of Delete, when you select the entire paragraph on which you defined the style and then delete completely, then in that scenario the paragraph, its contain and also the style is getting deleted. When I view the style after deleting, I got the style as “Normal”.
Please let me know, in case any more information required on this.
Regards,
Rajesh
Hi Rajesh,
Thanks for your inquiry.
Rajesh@123:
When we are pressing the “Enter” button actually the style is repeated, hence if we are trying to getting the text/node details using that style while comparing the Paragraph style name, then it is not performing as expected as it satisfies for two condition as now two paragraphs present with the same style name.
Please note that Aspose.Words mimics the same behavior as MS Word does. You are facing the expected behavior of MS Word and Aspose.Words.
It would be great if you please share following detail here for our reference. We will then provide you more information on this along with code.
- Please attach your input Word document.
- Please attach the output Word file that shows the undesired behavior.
- Please
attach your target Word document showing the desired behavior. You can
use Microsoft Word to create your target Word document. I will
investigate as to how you are expecting your final document be generated
like.
Rajesh@123:
In case of Delete, when you select the entire paragraph on which you defined the style and then delete completely, then in that scenario the paragraph, its contain and also the style is getting deleted. When I view the style after deleting, I got the style as “Normal”.
I have tested this scenario using MS Word 2013 and Aspose.Words and have noticed that the styles do not remove from the output document. I have used the shared document (Test.docx) to test this issue. Could you please share which MS Word version you are using along with the document which you are using to check this issue?
Moreover, please share some detail what exact you want to achieve using Aspose.Words. We will then provide you more information on this along with code.