2014-03-28 30 views
0

使用Aspose DLL我想查找特定的段落并使用一个关键字在旧段落下面的文档中重复该段落。使用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

张贴您尝试过的任何代码。 – foxtrotZulu

回答

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 TextExtracting Paragraphs深入的细节按您的要求。

+0

谢谢@Nausherwan Aslam它会帮助我... – Chintu