使用Aspose DLL我想找到特定的段落,并使用一个关键词在旧段落下面的文档中重复该段落。
Here is the example
---------------------------------
Document Content..................
.................................
.................................
..................................
Dated This [Date of Report]
[Name of all existing directors]
Director
here we need to create the documents for each directors here directors came dynamically from data base.
Document data is same for all the directors.
答案 0 :(得分:1)
你的例子不是很清楚。但是,使用IReplacingCallback,您可以找到键字符串的段落。以下是一个简单的代码:
static void Main(string[] args)
{
// Load in the document
Document doc = new Document("C:\\data\\Testing.doc");
//Regular expression for findinf Full Name string
Regex regex = new Regex("Full Name", RegexOptions.IgnoreCase);
//To find the text and insert the paragraph
doc.Range.Replace(regex, new ReplaceEvaluatorFindandHighlight(), true);
doc.Save("C:\\data\\document_new.doc");
}
//Class to find the text as per key string
private class ReplaceEvaluatorFindandHighlight : IReplacingCallback
{
/// <summary>
/// This method is called by the Aspose.Words find and replace engine for each match.
/// This method highlights the match string, even if it spans multiple runs.
/// </summary>
ReplaceAction IReplacingCallback.Replacing(ReplacingArgs e)
{
// This is a Run node that contains either the beginning or the complete match.
Node currentNode = e.MatchNode;
//Use Document Builder to Navigate to the paragraph
DocumentBuilder builder = new DocumentBuilder((Document)e.MatchNode.Document);
builder.MoveTo(currentNode.ParentNode);
//Insert a Paragraph break
builder.InsertParagraph();
//Insert the Paragraph for the Text we have search
builder.Writeln(currentNode.ParentNode.ToString(SaveFormat.Text)); // Inserts a string and a paragraph break into the document.
// Signal to the replace engine to do nothing because we have already done all what we wanted.
return ReplaceAction.Skip;
}
}
请参阅Aspose.Words文档,根据您的要求获得Finding Text或Extracting Paragraphs的深入细节。