We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Align to the center all lines that contain "CHAPTER"

I want to find all lines that contain “CHAPTER”
or “***” and make their alignmment center.
Visual Studio. Windows 10. C#.

@granite61

Please use the following code example to get the desired output. If you still face problem, please ZIP and attach your input and expected output documents here for our reference. We will then provide you more information about your query.

Document doc = new Document(MyDir + "input.docx");

foreach (Paragraph paragraph in doc.GetChildNodes(NodeType.Paragraph, true))
{
    if (paragraph.ToString(SaveFormat.Text).Trim().Contains("CHAPTER") || paragraph.ToString(SaveFormat.Text).Trim().Contains("***"))
        paragraph.ParagraphFormat.Alignment = ParagraphAlignment.Center;

    if(paragraph.IsListItem && paragraph.ListLabel.LabelString.Contains("CHAPTER"))
        paragraph.ParagraphFormat.Alignment = ParagraphAlignment.Center;
}
doc.Save(MyDir + "21.8.docx");