When using Replace as below, can I make it work only in a specific section, not all sections?.
- Code: Select all
Document word = new Document();
word.LoadFromFile(filePath);
word.Replace($"t1", temp.Trim(), false, true);
Document word = new Document();
word.LoadFromFile(filePath);
word.Replace($"t1", temp.Trim(), false, true);
Document word = new Document();
word.LoadFromFile(@"Sample.docx");
TextSelection[] textSelections = word.FindAllString("Word", true, true);
foreach (TextSelection ts in textSelections)
{
Spire.Doc.Fields.TextRange textRange = ts.GetAsOneRange();
Paragraph p = textRange.OwnerParagraph;
Body ownerTextBody = p.OwnerTextBody;
Section sec = (Section)ownerTextBody.Owner;
int index = word.ChildObjects.IndexOf(sec);
//set specipic section
if (index == 0)
{
textRange.Text = "newText";
}
}
word.SaveToFile("newText.docx", FileFormat.Docx);