hello
i want to select a line that have special character then delete it , please any idea
thanks
Please note that Aspose.Words’ model is quite different from the Microsoft Word’s Object Model in that it represents the document as a tree of objects more like an XML DOM tree. If you worked with any XML DOM library you will find it is easy to understand and work with Aspose.Words. When you load a Word document into Aspose.Words, it builds its DOM and all document elements and formatting are simply loaded into memory. Please read the following article for more information on DOM:
Aspose.Words Document Object Model
The Aspose.Words.Layout namespace provides classes that allow to access information such as on what page and where on a page particular document elements are positioned, when the document is formatted into pages.
You can use the DocumentLayoutHelper utility to get the text of line and remove it using find and replace feature. You can remove line’s text by replacing it with empty string using Range.Replace method.
If you still face problem, please ZIP and attach your input and expected output documents. We will then provide you more information about your query.
hi
i dont undrstand i am new to aspose api , i tried some code but it gets an overload error , i want to delete lines that have (#) char i attached in and out docx and some code
best regards
attach.zip (21.4 KB)
i tried the code below it works but it delets a whole paragraph not only a line
public void delete()
{
Document doc = new Document("C:\\temp6.docx");
FindReplaceOptions fro = new FindReplaceOptions(new RemoveAddressLine());
doc.Range.Replace(new Regex(Regex.Escape("#")), "", fro);
doc.Save("C:\\temp6.docx");
}
private class RemoveAddressLine : IReplacingCallback
{
ReplaceAction IReplacingCallback.Replacing(ReplacingArgs e)
{
DocumentBuilder builder = new DocumentBuilder(e.MatchNode.Document as Document);
Node currentNode = e.MatchNode;
builder.MoveTo(currentNode);
builder.CurrentParagraph.Remove();
return ReplaceAction.Replace;
}
}
Please use the following code example to remove the line that contains # character. Please make sure that the fonts used in your document are installed on the system where you are using Aspose.Words.
Document doc = new Document(MyDir + "input.docx");
// Create a new RenderedDocument class from a Document object.
RenderedDocument layoutDoc = new RenderedDocument(doc);
// Loop through each page in the document and print how many lines appear on each page.
foreach (RenderedPage page in layoutDoc.Pages)
{
LayoutCollection<LayoutEntity> lines = page.GetChildEntities(LayoutEntityType.Line, true);
foreach (RenderedLine line in lines)
{
if (line.Text.Contains("#"))
{
Console.WriteLine("line {0} ", line.Text);
doc.Range.Replace(line.Text, "", new FindReplaceOptions());
}
}
}
doc.Save(MyDir + "19.9.docx");
sorry to bother you but i can not find renderedDocument class for aspose.words for .net
now it works i did some mods then it worked
thanks a lot.
It is nice to hear from you that your problem has been solved. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.