Paragraph

Updated at:

This topic describes the APIs for the Paragraph object in a text document.

Paragraphs

ActiveDocument.Range(Start, End).Paragraphs

Retrieves all paragraphs in the specified range.

Important
  • This feature is supported in JS-SDK V1.1.14 and later.

  • This feature is supported only on PCs.

  • Syntax

    expression.ActiveDocument.Range(Start, End).Paragraphs

    Expression: Document Type Object

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Get all paragraphs in the specified range.
      const paragraphs = app.ActiveDocument.Range(0, 100).Paragraphs;
    }

Methods

ActiveDocument.Range(Start, End).Paragraphs.Item()

Use the Item() method to retrieve a single Paragraph object.

Important

This feature is supported in JS-SDK V1.1.14 and later.

  • Syntax

    expression.ActiveDocument.Range(Start, End).Paragraphs.Item(Index)

    Expression: Application Object for the Document Type

  • Parameters

    Property

    Data type

    Required

    Description

    Index

    Number

    Yes

    The paragraph at the specified index.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Get all paragraphs in the specified range.
      const paragraphs = app.ActiveDocument.Range(0, 100).Paragraphs;
    
      // Get the first Paragraph object.
      const paragraph = paragraphs.Item(1);
    }

Properties

ActiveDocument.Range(Start, End).Paragraphs.Count

Use the Count property to retrieve the total number of paragraphs in the specified range.

Important

This feature is supported in JS-SDK V1.1.14 and later.

  • Syntax

    expression.ActiveDocument.Range(Start, End).Paragraphs.Count

    Expression: application object of the document type

  • Return value

    Returns a Number that indicates the total number of paragraphs.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Get the total number of paragraphs in the specified range.
      const count = await app.ActiveDocument.Range(0, 100).Paragraphs.Count;
      console.log(count);
    }

ActiveDocument.Range(Start, End).Paragraphs.Item(Index).Range

Use the Range property to retrieve the portion of the document that is contained in a single Paragraph object.

Important

This feature is supported in JS-SDK V1.1.14 and later.

  • Syntax

    expression.ActiveDocument.Range(Start, End).Paragraphs.Item(Index).Range

    Expression: Application Object for the Document Type

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
      
      // Get all paragraphs in the specified range.
      const paragraphs = app.ActiveDocument.Range(0, 100).Paragraphs;
    
      // Get the first Paragraph object.
      const paragraph = paragraphs.Item(1);
    
      // Get the part of the document that is contained in this paragraph.
      const range = await paragraph.Range;
    }

ParagraphFormat

ActiveDocument.Range(Start, End).ParagraphFormat

Retrieves the paragraph settings for the specified range.

Important

This feature is supported in JS-SDK V1.1.10 and later.

  • Syntax

    expression.ActiveDocument.Range(Start, End).ParagraphFormat

    or expression.ActiveDocument.ActiveWindow.Selection.ParagraphFormat

    expression: An Application object.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
    
      // Get the paragraph settings for the specified range.
      const paragraphFormat = await app.ActiveDocument.Range(0, 20).ParagraphFormat;
    }

Methods

ActiveDocument.Range(Start, End).ParagraphFormat.SetFixedLineSpacing(Value, Unit)

Use the SetFixedLineSpacing() method to set a fixed line spacing.

  • Syntax

    expression.ActiveDocument.Range(Start, End).ParagraphFormat.SetFixedLineSpacing

    or expression.ActiveDocument.ActiveWindow.Selection.ParagraphFormat

    Expression: Application object for the document type

  • Parameters

    Properties

    Data type

    Required

    Description

    Value

    Number

    Yes

    The line spacing. The value range is 0 to 1000 in points, 0 to 55 in centimeters, 0 to 550 in millimeters, or 0 to 22 in inches.

    Unit

    Enum

    Yes

    The unit for the spacing.

  • Example

    //@file=base.docx
    async function example() {
      await instance.ready();
    
      const app = instance.Application;
    
      // The ParagraphFormat object.
      const paragraphFormat = await app.ActiveDocument.Range(0, 20).ParagraphFormat;
    
      // Set the fixed line spacing to 18 points.
      await paragraphFormat.SetFixedLineSpacing(18, 0);
    }

ActiveDocument.Range(Start, End).ParagraphFormat.setParagraphAlignment

Use the setParagraphAlignment() method to set the paragraph alignment.

Important

This feature is supported in JS-SDK V1.1.19 and later.

  • Syntax

    expression.ActiveDocument.Range(Start, End).ParagraphFormat.setParagraphAlignment

    expression: An Application object.

  • Parameters

    Properties

    Data type

    Required

    Description

    Value

    Enum

    Yes

    The paragraph alignment.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
    
      // The ParagraphFormat object.
      const paragraphFormat = await app.ActiveDocument.Range(0, 20).ParagraphFormat;
    
      // Align center.
      paragraphFormat.setParagraphAlignment(app.Enum.WdAlignmentMode.wdCenter);
    }

Properties

ActiveDocument.Range(Start, End).ParagraphFormat.CharacterUnitFirstLineIndent

Use the CharacterUnitFirstLineIndent property to set the first-line indent for a paragraph.

Important

This feature is supported in JS-SDK V1.1.10 and later.

  • Syntax

    expression.ActiveDocument.Range(Start, End).ParagraphFormat.CharacterUnitFirstLineIndent

    or expression.ActiveDocument.ActiveWindow.Selection.ParagraphFormat

    Expression: Object for a document type application

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
    
      // Get the paragraph settings for the specified range.
      const paragraphFormat = await app.ActiveDocument.Range(0, 20).ParagraphFormat;
     
      // Set the first-line indent to 2 units.
      paragraphFormat.CharacterUnitFirstLineIndent = 2;
    }

ActiveDocument.Range(Start, End).ParagraphFormat.LineSpacingRule

Use the LineSpacingRule property to set the line spacing for a paragraph. For more information, see WdLineSpacing.

Important

This feature is supported in JS-SDK V1.1.10 and later.

  • Syntax

    expression.ActiveDocument.Range(Start, End).ParagraphFormat.LineSpacingRule

    or expression.ActiveDocument.ActiveWindow.Selection.ParagraphFormat

    expression: An Application object.

  • Example

    async function example() {
      await instance.ready();
    
      const app = instance.Application;
    
      // Get the paragraph settings for the specified range.
      const paragraphFormat = await app.ActiveDocument.Range(0, 20).ParagraphFormat;
     
      // Set the line spacing to 1.5 lines.
      paragraphFormat.LineSpacingRule = 1;
    }