I have word document in that i need to apply below style property to heeding

Font:

14 pt, Bold, Dark Blue, Small caps

Indentation:

Left: 0

Hanging: 0.3

Space Before: 6 pt

Space After: 6 pt

Keep with next, Keep lines together

Tab stops: 0.4

List tab + Not at 0.4"

Style: Linked, Automatically update, Show in the Styles gallery

Style: Linked, Hide until used, Show in the Styles gallery

Don’t keep with next, Don’t keep lines together

Border:

Bottom: (Single solid line, Orange, 2.25 pt Line width)

Numbering Style:

Numbering Style: 1, 2, 3, … +

Start at: 1 +

Alignment: Left +

Aligned at: 0" +

Tab after: 0.4" +

Indent at: 0.4"

Style: Linked, Automatically update, Show in the Styles gallery

@Manasahr You can set the appropriate properties in the corresponding Style.Font, Style.ParagraphFormat and Style.ListFormat properties.
Also, please see our documentation to learn more about working with styles.

@alexey.noskov below mentioned property I didn’t get how to use. Kindly help me.

Indentation:

Left: 0

Hanging: 0.3

Keep with next, Keep lines together

Tab stops: 0.4

List tab + Not at 0.4"

Style: Linked, Automatically update, Show in the Styles gallery

Style: Linked, Hide until used, Show in the Styles gallery

Don’t keep with next, Don’t keep lines together

Border:

Bottom: (Single solid line, Orange, 2.25 pt Line width)

Numbering Style:

Numbering Style: 1, 2, 3, … +

Start at: 1 +

Alignment: Left +

Aligned at: 0" +

Tab after: 0.4" +

Indent at: 0.4"

Style: Linked, Automatically update, Show in the Styles gallery

@Manasahr Please see the following code example:

// Open the document.
Document doc = new Document(@"C:\Temp\in.docx");

// Get the heading style and set the required properties.
Style heading1 = doc.Styles[StyleIdentifier.Heading1];

// Chnage font properties
heading1.Font.Size = 14;
heading1.Font.Bold = true;
heading1.Font.Color = Color.DarkBlue;
heading1.Font.SmallCaps = true;
// set other font properties if required
// ..............

// Change paragraph properties.
heading1.ParagraphFormat.LeftIndent = 0;
heading1.ParagraphFormat.FirstLineIndent = -0.3; // negative value of FirstLineIndent sets hanging indent.
heading1.ParagraphFormat.SpaceBefore = 6;
heading1.ParagraphFormat.SpaceAfter = 6;
heading1.ParagraphFormat.KeepWithNext = true;
heading1.ParagraphFormat.KeepTogether = true;
heading1.ParagraphFormat.TabStops.Add(0.4, TabAlignment.Left, TabLeader.None);
// set other paragraph properties if required
// ..............

// Set paragraph border.
heading1.ParagraphFormat.Borders[BorderType.Bottom].LineStyle = LineStyle.Single;
heading1.ParagraphFormat.Borders[BorderType.Bottom].Color = Color.Orange;
heading1.ParagraphFormat.Borders[BorderType.Bottom].LineWidth = 2.25;
// set other paragraph border properties if required
// ..............

// Configure numbering of heading paragraph.
heading1.ListFormat.List = doc.Lists.Add(ListTemplate.NumberDefault);
heading1.ListFormat.ListLevel.TabPosition = 0.4;
heading1.ListFormat.ListLevel.NumberPosition = 0;
// set other list and list levels properties if required
// ..............

doc.Save(@"C:\Temp\out.docx");

@alexey.noskov Kindly help me below property how to use.

Heading / Numbering Style

Aligned at: 0" +

Indent at: 0.3"

Style: Linked, Automatically update, Show in the Styles gallery

List Bullet /Sage List Bullet Font

Line spacing single

Bulleted

Tab stops: 0.75"

List tab

Outline numbered + Level: 1 +

Numbering Style: Bullet

  • Aligned at: 0.75"

  • Tab after: 0.25"

@Manasahr Could you please attach your input and the expected output documents here. Also, please check the code I have provided in my previous answer and the documentation links provided earlier.

@alexey.noskov
I am trying to add hanging indent=-0.3 and LeftIndent=0 but it’s not applying in the document. But it’s showing hanging indent=0 and LeftIndent=-0.

I used below mentioned code and please find the screenshot.

NodeCollection nodes = doc.GetChildNodes(NodeType.Paragraph, true);
foreach (Paragraph para in nodes)
{
    if (para.ParagraphFormat.StyleIdentifier == StyleIdentifier.Heading1)
    {
        para.ParagraphFormat.LeftIndent = 0;
        para.ParagraphFormat.FirstLineIndent = -0.3;

    }
}

@Manasahr Aspose.Words uses Points as the default measurement units. In your case MS Word is configured to use Inches. 1 Inch = 72 Points, so 0.3pt=0.3/72in, which is rounded to zero in MS Word UI. You can use ConvertUtil.InchToPoint to convert inches to points. Please see our documentation for more information:
https://docs.aspose.com/words/net/convert-between-measurement-units/

@alexey.noskov Thanks for your suggestion it’s working for me but after setting the firstlineIndent =0.3 and leftIndent=0 after setting the leftIndent and firstlineIndent I am getting same 0.3 value.

para.ParagraphFormat.FirstLineIndent = ConvertUtil.InchToPoint(-0.3);
para.ParagraphFormat.LeftIndent = 0/;
1 Like

Any update on this?

@Manasahr Excuse me, I supposed that you managed to resolve the issue. If you need hanging indentation set and the indentation set to zero you should use code like this:

para.ParagraphFormat.FirstLineIndent = ConvertUtil.InchToPoint(-0.3);
para.ParagraphFormat.LeftIndent = -para.ParagraphFormat.FirstLineIndent;

@alexey.noskov Kindly help me how to enable the below property as I mentioned in the screen shot.

  1. style type :Linked
  2. style based on: Sage List Bullet
  3. Automatically Update

@Manasahr

  1. You should specify linked style using Style.LinkedStyleName.

  2. Use Style.BaseStyleName to specify name of the style, the current style is based on.

  3. There is no public property to get or set Automatically Update options of the style. I have logged as feature request WORDSNET-24686. We will consider exposing this property in one of future releases.

@alexey.noskov Kindly help me how to use below property.

NodeCollection paragraphs = doc.GetChildNodes(NodeType.Paragraph, true);
foreach (Paragraph para in paragraphs)
{
    if (para.ParagraphFormat.StyleIdentifier == StyleIdentifier.Heading1)
    {
        para.ParagraphFormat.Style.BaseStyleName = "Sage List Bullet";
        para.ParagraphFormat.Style.LinkedStyleName.
}

@Manasahr Unfortunately, this property is read-only and allows only check whether style is linked or not. I have logged a feature request WORDSNET-24691 to allow setting the linked style. We will let you know once it is implemented.

The issues you have found earlier (filed as WORDSNET-24686) have been fixed in this Aspose.Words for .NET 23.2 update also available on NuGet.

The issues you have found earlier (filed as WORDSNET-24691) have been fixed in this Aspose.Words for .NET 24.4 update also available on NuGet.