-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enhanced Word Document Element Manipulation #3
Labels
enhancement
New feature or request
Comments
Resolved in 23.10.0. Public methods Below is an example of inserting a new paragraph after every paragraph containing text "Heading" in an existing word document: using System;
using System.IO;
using System.Collections.Generic;
using Openize.Words;
using Openize.Words.IElements;
namespace Openize.Words.Examples
{
class Program
{
static void Main(string[] args)
{
Document doc = new Document("WordDocumentWithParas.docx");
Paragraph paragraphToInsert;
List<Paragraph> paragraphsToFind = new List<Paragraph>();
List<Paragraph> paragraphsToInsert = new List<Paragraph>();
int num=0;
foreach (IElement element in doc.GetElements())
{
if (element is Paragraph para && para.Text.Contains("Heading"))
{
paragraphsToFind.Add(para);
paragraphToInsert = new Paragraph();
paragraphToInsert.Runs.Add(new Run { Text = $"Normal Paragraph {num + 1} inserted by FileFormat.Words" });
paragraphsToInsert.Add(paragraphToInsert);
num++;
}
}
num = 0;
foreach (Paragraph para in paragraphsToInsert)
{
doc.InsertAfter(para, paragraphsToFind[num]);
num++;
}
doc.Save("WordDocumentWithParasInsertedAfter.docx");
}
}
} The issue will be closed after adding docs and examples. |
Already resolved. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
We're offering the following element manipulation functions:
The text was updated successfully, but these errors were encountered: