ApplyParagraphFormat

FindReplaceOptions.ApplyParagraphFormat property

Mise en forme du paragraphe appliquée au nouveau contenu.

public ParagraphFormat ApplyParagraphFormat { get; }

Exemples

Montre comment ajouter une mise en forme aux paragraphes dans lesquels une opération de recherche et de remplacement a trouvé des correspondances.

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

builder.Writeln("Every paragraph that ends with a full stop like this one will be right aligned.");
builder.Writeln("This one will not!");
builder.Write("This one also will.");

ParagraphCollection paragraphs = doc.FirstSection.Body.Paragraphs;

Assert.AreEqual(ParagraphAlignment.Left, paragraphs[0].ParagraphFormat.Alignment);
Assert.AreEqual(ParagraphAlignment.Left, paragraphs[1].ParagraphFormat.Alignment);
Assert.AreEqual(ParagraphAlignment.Left, paragraphs[2].ParagraphFormat.Alignment);

// Nous pouvons utiliser un objet "FindReplaceOptions" pour modifier le processus de recherche et de remplacement.
FindReplaceOptions options = new FindReplaceOptions();

// Définissez la propriété "Alignment" sur "ParagraphAlignment.Right" pour aligner chaque paragraphe à droite
// qui contient une correspondance trouvée par l'opération de recherche et de remplacement.
options.ApplyParagraphFormat.Alignment = ParagraphAlignment.Right;

// Remplacez chaque point situé juste avant un saut de paragraphe par un point d'exclamation.
int count = doc.Range.Replace(".&p", "!&p", options);

Assert.AreEqual(2, count);
Assert.AreEqual(ParagraphAlignment.Right, paragraphs[0].ParagraphFormat.Alignment);
Assert.AreEqual(ParagraphAlignment.Left, paragraphs[1].ParagraphFormat.Alignment);
Assert.AreEqual(ParagraphAlignment.Right, paragraphs[2].ParagraphFormat.Alignment);
Assert.AreEqual("Every paragraph that ends with a full stop like this one will be right aligned!\r" +
                "This one will not!\r" +
                "This one also will!", doc.GetText().Trim());

Voir également