public void DocumentEnsureMinimum() { //ExStart //ExFor:Document.EnsureMinimum //ExSummary:Shows how to ensure the Document is valid (has the minimum nodes required to be valid). // Create a blank document then remove all nodes from it, the result will be a completely empty document. Aspose.Words.Document doc = new Aspose.Words.Document(); doc.RemoveAllChildren(); // Ensure that the document is valid. Since the document has no nodes this method will create an empty section // and add an empty paragraph to make it valid. doc.EnsureMinimum(); //ExEnd }
public void AppendDocumentFromAutomation() { //ExStart //ExId:AppendDocumentFromAutomation //ExSummary:Shows how to join multiple documents together. // The document that the other documents will be appended to. Aspose.Words.Document doc = new Aspose.Words.Document(); // We should call this method to clear this document of any existing content. doc.RemoveAllChildren(); int recordCount = 5; for (int i = 1; i <= recordCount; i++) { // Open the document to join. Aspose.Words.Document srcDoc = new Aspose.Words.Document(@"C:\DetailsList.doc"); // Append the source document at the end of the destination document. doc.AppendDocument(srcDoc, ImportFormatMode.UseDestinationStyles); // In automation you were required to insert a new section break at this point, however in Aspose.Words we // don't need to do anything here as the appended document is imported as separate sectons already. // If this is the second document or above being appended then unlink all headers footers in this section // from the headers and footers of the previous section. if (i > 1) doc.Sections[i].HeadersFooters.LinkToPrevious(false); } //ExEnd }
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(MyDir + "Section.CreateFromScratch Out.doc"); //ExEnd Assert.AreEqual("Hello World!\x000c", doc.GetText()); }
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()); }