本文整理汇总了C#中Aspose.Words.Document.GetText方法的典型用法代码示例。如果您正苦于以下问题:C# Document.GetText方法的具体用法?C# Document.GetText怎么用?C# Document.GetText使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Aspose.Words.Document
的用法示例。
在下文中一共展示了Document.GetText方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddRemove
public void AddRemove()
{
//ExStart
//ExFor:Document.Sections
//ExFor:Section.Clone
//ExFor:SectionCollection
//ExFor:NodeCollection.RemoveAt(Int32)
//ExSummary:Shows how to add/remove sections in a document.
// Open the document.
Aspose.Words.Document doc = new Aspose.Words.Document(ExDir + "Section.AddRemove.doc");
// This shows what is in the document originally. The document has two sections.
Console.WriteLine(doc.GetText());
// Delete the first section from the document
doc.Sections.RemoveAt(0);
// Duplicate the last section and append the copy to the end of the document.
int lastSectionIdx = doc.Sections.Count - 1;
Aspose.Words.Section newSection = doc.Sections[lastSectionIdx].Clone();
doc.Sections.Add(newSection);
// Check what the document contains after we changed it.
Console.WriteLine(doc.GetText());
//ExEnd
Assert.AreEqual("Hello2\x000cHello2\x000c", doc.GetText());
}
示例2: BodyEnsureMinimum
public void BodyEnsureMinimum()
{
//ExStart
//ExFor:Section.Body
//ExFor:Body.EnsureMinimum
//ExSummary:Clears main text from all sections from the document leaving the sections themselves.
// Open a document.
Aspose.Words.Document doc = new Aspose.Words.Document(MyDir + "Section.BodyEnsureMinimum.doc");
// This shows what is in the document originally. The document has two sections.
Console.WriteLine(doc.GetText());
// Loop through all sections in the document.
foreach (Aspose.Words.Section section in doc.Sections)
{
// Each section has a Body node that contains main story (main text) of the section.
Body body = section.Body;
// This clears all nodes from the body.
body.RemoveAllChildren();
// Technically speaking, for the main story of a section to be valid, it needs to have
// at least one empty paragraph. That's what the EnsureMinimum method does.
body.EnsureMinimum();
}
// Check how the content of the document looks now.
Console.WriteLine(doc.GetText());
//ExEnd
Assert.AreEqual("\x000c\x000c", doc.GetText());
}
示例3: DeleteSelection
public void DeleteSelection()
{
//ExStart
//ExFor:Node.Range
//ExFor:Range.Delete
//ExSummary:Shows how to delete a section from a Word document.
// Open Word document.
Aspose.Words.Document doc = new Aspose.Words.Document(MyDir + "Range.DeleteSection.doc");
// The document contains two sections. Each section has a paragraph of text.
Console.WriteLine(doc.GetText());
// Delete the first section from the document.
doc.Sections[0].Range.Delete();
// Check the first section was deleted by looking at the text of the whole document again.
Console.WriteLine(doc.GetText());
//ExEnd
Assert.AreEqual("Hello2\x000c", doc.GetText());
}
示例4: OpenFromStream
public void OpenFromStream()
{
//ExStart
//ExFor:Document.#ctor(Stream)
//ExId:OpenFromStream
//ExSummary:Opens a document from a stream.
// Open the stream. Read only access is enough for Aspose.Words to load a document.
Stream stream = File.OpenRead(MyDir + "Document.doc");
// Load the entire document into memory.
Aspose.Words.Document doc = new Aspose.Words.Document(stream);
// You can close the stream now, it is no longer needed because the document is in memory.
stream.Close();
// ... do something with the document
//ExEnd
Assert.AreEqual("Hello World!\x000c", doc.GetText());
}
示例5: DocumentGetText_ToString
public void DocumentGetText_ToString()
{
//ExStart
//ExFor:CompositeNode.GetText
//ExFor:Node.ToString(SaveFormat)
//ExId:NodeTxtExportDifferences
//ExSummary:Shows the difference between calling the GetText and ToString methods on a node.
Aspose.Words.Document doc = new Aspose.Words.Document();
// Enter a dummy field into the document.
DocumentBuilder builder = new DocumentBuilder(doc);
builder.InsertField("MERGEFIELD Field");
// GetText will retrieve all field codes and special characters
Console.WriteLine("GetText() Result: " + doc.GetText());
// ToString will export the node to the specified format. When converted to text it will not retrieve fields code
// or special characters, but will still contain some natural formatting characters such as paragraph markers etc.
// This is the same as "viewing" the document as if it was opened in a text editor.
Console.WriteLine("ToString() Result: " + doc.ToString(SaveFormat.Text));
//ExEnd
}
示例6: DocumentByteArray
public void DocumentByteArray()
{
//ExStart
//ExId:DocumentToFromByteArray
//ExSummary:Shows how to convert a document object to an array of bytes and back into a document object again.
// Load the document.
Aspose.Words.Document doc = new Aspose.Words.Document(MyDir + "Document.doc");
// Create a new memory stream.
MemoryStream outStream = new MemoryStream();
// Save the document to stream.
doc.Save(outStream, SaveFormat.Docx);
// Convert the document to byte form.
byte[] docBytes = outStream.ToArray();
// The bytes are now ready to be stored/transmitted.
// Now reverse the steps to load the bytes back into a document object.
MemoryStream inStream = new MemoryStream(docBytes);
// Load the stream into a new document object.
Aspose.Words.Document loadDoc = new Aspose.Words.Document(inStream);
//ExEnd
Assert.AreEqual(doc.GetText(), loadDoc.GetText());
}
示例7: ReplaceSimple
public void ReplaceSimple()
{
//ExStart
//ExFor:Range.Replace(String,String,Boolean,Boolean)
//ExSummary:Simple find and replace operation.
// Open the document.
Aspose.Words.Document doc = new Aspose.Words.Document(MyDir + "Range.ReplaceSimple.doc");
// Check the document contains what we are about to test.
Console.WriteLine(doc.FirstSection.Body.Paragraphs[0].GetText());
// Replace the text in the document.
doc.Range.Replace("_CustomerName_", "James Bond", false, false);
// Save the modified document.
doc.Save(MyDir + "Range.ReplaceSimple Out.doc");
//ExEnd
Assert.AreEqual("Hello James Bond,\r\x000c", doc.GetText());
}
示例8: ReplaceWithInsertHtml
//ExStart
//ExFor:Range.Replace(Regex,IReplacingCallback,Boolean)
//ExFor:ReplacingArgs.Replacement
//ExFor:IReplacingCallback
//ExFor:IReplacingCallback.Replacing
//ExFor:ReplacingArgs
//ExFor:DocumentBuilder.InsertHtml(string)
//ExSummary:Replaces text specified with regular expression with HTML.
public void ReplaceWithInsertHtml()
{
// Open the document.
Aspose.Words.Document doc = new Aspose.Words.Document(MyDir + "Range.ReplaceWithInsertHtml.doc");
doc.Range.Replace(new Regex(@"<CustomerName>"), new ReplaceWithHtmlEvaluator(), false);
// Save the modified document.
doc.Save(MyDir + "Range.ReplaceWithInsertHtml Out.doc");
Assert.AreEqual("Hello James Bond,\r\x000c", doc.GetText()); //ExSkip
}
示例9: CreateFromScratch
public void CreateFromScratch()
{
//ExStart
//ExFor:Node.GetText
//ExFor:CompositeNode.RemoveAllChildren
//ExFor:CompositeNode.AppendChild
//ExFor:Section
//ExFor:Section.#ctor
//ExFor:Section.PageSetup
//ExFor:PageSetup.SectionStart
//ExFor:PageSetup.PaperSize
//ExFor:SectionStart
//ExFor:PaperSize
//ExFor:Body
//ExFor:Body.#ctor
//ExFor:Paragraph
//ExFor:Paragraph.#ctor
//ExFor:Paragraph.ParagraphFormat
//ExFor:ParagraphFormat
//ExFor:ParagraphFormat.StyleName
//ExFor:ParagraphFormat.Alignment
//ExFor:ParagraphAlignment
//ExFor:Run
//ExFor:Run.#ctor(DocumentBase)
//ExFor:Run.Text
//ExFor:Inline.Font
//ExSummary:Creates a simple document from scratch using the Aspose.Words object model.
// Create an "empty" document. Note that like in Microsoft Word,
// the empty document has one section, body and one paragraph in it.
Aspose.Words.Document doc = new Aspose.Words.Document();
// This truly makes the document empty. No sections (not possible in Microsoft Word).
doc.RemoveAllChildren();
// Create a new section node.
// Note that the section has not yet been added to the document,
// but we have to specify the parent document.
Aspose.Words.Section section = new Aspose.Words.Section(doc);
// Append the section to the document.
doc.AppendChild(section);
// Lets set some properties for the section.
section.PageSetup.SectionStart = SectionStart.NewPage;
section.PageSetup.PaperSize = PaperSize.Letter;
// The section that we created is empty, lets populate it. The section needs at least the Body node.
Body body = new Body(doc);
section.AppendChild(body);
// The body needs to have at least one paragraph.
// Note that the paragraph has not yet been added to the document,
// but we have to specify the parent document.
// The parent document is needed so the paragraph can correctly work
// with styles and other document-wide information.
Paragraph para = new Paragraph(doc);
body.AppendChild(para);
// We can set some formatting for the paragraph
para.ParagraphFormat.StyleName = "Heading 1";
para.ParagraphFormat.Alignment = ParagraphAlignment.Center;
// So far we have one empty paragraph in the document.
// The document is valid and can be saved, but lets add some text before saving.
// Create a new run of text and add it to our paragraph.
Run run = new Run(doc);
run.Text = "Hello World!";
run.Font.Color = System.Drawing.Color.Red;
para.AppendChild(run);
// As a matter of interest, you can retrieve text of the whole document and
// see that \x000c is automatically appended. \x000c is the end of section character.
Console.WriteLine("Hello World!\x000c", doc.GetText());
// Save the document.
doc.Save(ExDir + "Section.CreateFromScratch Out.doc");
//ExEnd
Assert.AreEqual("Hello World!\x000c", doc.GetText());
}