Hi,
I have an existing word document and I need to remove paragraph/sentence/line.
stream input = File.OpenRead(filepath);
RadFlowDocument document = provider.Import(input);
RadFlowDocumentEditor editor = new RadFlowDocumentEditor(document);
editor.ReplaceText("<Expr2>", ltr.Expr2));
editor.ReplaceText("<Expr3>", ltr.Expr3));
If ltr.Expr2 is blank, then it should remove blank lines from document where <Expr2> exists, otherwise replace text with ltr.Expr2 value.
Any help would be greatly appreciated.
4 Answers, 1 is accepted
The ReplaceText() method replaces only the Run elements in the document and cannot delete a paragraph. To achieve this behavior, I would suggest you to manually remove the run and, according to the value of ltr.Expr2, delete the underlying paragraph or insert the value of the variable as the Text of the Run object:
foreach
(var run
in
this
.document.EnumerateChildrenOfType<Run>().ToList())
{
if
(run.Text ==
"<Expr2>"
)
{
if
(
string
.IsNullOrEmpty(ltr.Expr2))
{
var section = run.Paragraph.Parent
as
Section;
section.Blocks.Remove(run.Paragraph);
}
else
{
run.Text = ltr.Expr2;
}
}
}
Regards,
Tanya
Progress Telerik
Hi Admins,
I have a question regarding formatted text to insert in a document using RadFlowDocument editor.
I m using this line of code
editor.ReplaceText("<LetterFieldInsert>", initltr.LetterFieldInsert)
problem is, sometimes text can have line feed (i.e. CrLf or Lf) in it and I want to show it with formatting if there is any.
Currently, RadFlowDocument editor isn't recognizing line feed and lumped all together or in other words, wrapped in a single sentence.
Would you please advise, how can I fix this issue?
Your help is greatly appreciated.
Thanks
Hi Khawar,
With the current implementation of the ReplaceText() method, only plain text can be inserted. The content passed as a parameter to the method is stripped from the formatting and line feeds as it needs to be added as content to a single Run element. We have a request to provide you with the ability to replace with different elements and you can vote for its implementation using the related public item: WordsProcessing: Introduce a way to replace text with other document elements. You can also follow this item if you would like to receive updates about status changes on it.
Regards,
Tanya
Progress Telerik