本文整理汇总了C#中Aspose.Words.Document.Accept方法的典型用法代码示例。如果您正苦于以下问题:C# Document.Accept方法的具体用法?C# Document.Accept怎么用?C# Document.Accept使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Aspose.Words.Document
的用法示例。
在下文中一共展示了Document.Accept方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ToText
//ExStart
//ExFor:Document.Accept
//ExFor:Body.Accept
//ExFor:DocumentVisitor
//ExFor:DocumentVisitor.VisitRun
//ExFor:DocumentVisitor.VisitFieldStart
//ExFor:DocumentVisitor.VisitFieldEnd
//ExFor:DocumentVisitor.VisitFieldSeparator
//ExFor:DocumentVisitor.VisitBodyStart
//ExFor:DocumentVisitor.VisitBodyEnd
//ExFor:DocumentVisitor.VisitParagraphEnd
//ExFor:DocumentVisitor.VisitHeaderFooterStart
//ExFor:VisitorAction
//ExId:ExtractContentDocToTxtConverter
//ExSummary:Shows how to use the Visitor pattern to add new operations to the Aspose.Words object model. In this case we create a simple document converter into a text format.
public void ToText()
{
// Open the document we want to convert.
Aspose.Words.Document doc = new Aspose.Words.Document(ExDir + "Visitor.ToText.doc");
// Create an object that inherits from the DocumentVisitor class.
MyDocToTxtWriter myConverter = new MyDocToTxtWriter();
// This is the well known Visitor pattern. Get the model to accept a visitor.
// The model will iterate through itself by calling the corresponding methods
// on the visitor object (this is called visiting).
//
// Note that every node in the object model has the Accept method so the visiting
// can be executed not only for the whole document, but for any node in the document.
doc.Accept(myConverter);
// Once the visiting is complete, we can retrieve the result of the operation,
// that in this example, has accumulated in the visitor.
Console.WriteLine(myConverter.GetText());
}
示例2: RemoveHiddenContentFromDocument
//ExStart
//ExFor:Font.Hidden
//ExFor:Paragraph.Accept
//ExFor:DocumentVisitor.VisitParagraphStart(Aspose.Words.Paragraph)
//ExFor:DocumentVisitor.VisitFormField(Aspose.Words.Fields.FormField)
//ExFor:DocumentVisitor.VisitTableEnd(Aspose.Words.Tables.Table)
//ExFor:DocumentVisitor.VisitCellEnd(Aspose.Words.Tables.Cell)
//ExFor:DocumentVisitor.VisitRowEnd(Aspose.Words.Tables.Row)
//ExFor:DocumentVisitor.VisitSpecialChar(Aspose.Words.SpecialChar)
//ExFor:DocumentVisitor.VisitGroupShapeStart(Aspose.Words.Drawing.GroupShape)
//ExFor:DocumentVisitor.VisitShapeStart(Aspose.Words.Drawing.Shape)
//ExFor:DocumentVisitor.VisitCommentStart(Aspose.Words.Comment)
//ExFor:DocumentVisitor.VisitFootnoteStart(Aspose.Words.Footnote)
//ExFor:SpecialChar
//ExFor:Node.Accept
//ExFor:Paragraph.ParagraphBreakFont
//ExFor:Table.Accept
//ExSummary:Implements the Visitor Pattern to remove all content formatted as hidden from the document.
public void RemoveHiddenContentFromDocument()
{
// Open the document we want to remove hidden content from.
Aspose.Words.Document doc = new Aspose.Words.Document(ExDir + "Font.Hidden.doc");
// Create an object that inherits from the DocumentVisitor class.
RemoveHiddenContentVisitor hiddenContentRemover = new RemoveHiddenContentVisitor();
// This is the well known Visitor pattern. Get the model to accept a visitor.
// The model will iterate through itself by calling the corresponding methods
// on the visitor object (this is called visiting).
// We can run it over the entire the document like so:
doc.Accept(hiddenContentRemover);
// Or we can run it on only a specific node.
Paragraph para = (Paragraph)doc.GetChild(NodeType.Paragraph, 4, true);
para.Accept(hiddenContentRemover);
// Or over a different type of node like below.
Table table = (Table)doc.GetChild(NodeType.Table, 0, true);
table.Accept(hiddenContentRemover);
doc.Save(ExDir + "Font.Hidden Out.doc");
Assert.AreEqual(13, doc.GetChildNodes(NodeType.Paragraph, true).Count); //ExSkip
Assert.AreEqual(1, doc.GetChildNodes(NodeType.Table, true).Count); //ExSkip
}