[Test] //ExSkip public void CreateCommentsAndPrintAllInfo() { Document doc = new Document(); doc.RemoveAllChildren(); Section sect = (Section)doc.AppendChild(new Section(doc)); Body body = (Body)sect.AppendChild(new Body(doc)); // Create a commented text with several comment replies for (int i = 0; i <= 10; i++) { Comment newComment = CreateComment(doc, "VDeryushev", "VD", DateTime.Now, "My test comment " + i); Paragraph para = (Paragraph)body.AppendChild(new Paragraph(doc)); para.AppendChild(new CommentRangeStart(doc, newComment.Id)); para.AppendChild(new Run(doc, "Commented text " + i)); para.AppendChild(new CommentRangeEnd(doc, newComment.Id)); para.AppendChild(newComment); for (int y = 0; y <= 2; y++) { newComment.AddReply("John Doe", "JD", DateTime.Now, "New reply " + y); } } // Look at information of our comments PrintAllCommentInfo(ExtractComments(doc)); }
public override VisitorAction VisitBuildingBlockStart(BuildingBlock block) { // Change values by default of created BuildingBlock block.Behavior = BuildingBlockBehavior.Paragraph; block.Category = "My custom building blocks"; block.Description = "Using this block in the Quick Parts section of word will place its contents at the cursor."; block.Gallery = BuildingBlockGallery.QuickParts; block.Guid = Guid.NewGuid(); // Add content for the BuildingBlock to have an effect when used in the document Section section = new Section(mGlossaryDoc); block.AppendChild(section); Body body = new Body(mGlossaryDoc); section.AppendChild(body); Paragraph paragraph = new Paragraph(mGlossaryDoc); body.AppendChild(paragraph); // Add text that will be visible in the document Run run = new Run(mGlossaryDoc, "Text inside " + block.Name); block.FirstSection.Body.FirstParagraph.AppendChild(run); return(VisitorAction.Continue); }
private Paragraph CreateParagraph(Document doc, StyleNames styleName = StyleNames.None) { var section = new Section(doc); _ = doc.AppendChild(section); var body = new Body(doc); _ = section.AppendChild(body); var paragraph = new Paragraph(doc); _ = body.AppendChild(paragraph); switch (styleName) { case StyleNames.Heading1: _ = paragraph.ParagraphFormat.StyleName = "Heading 1"; break; case StyleNames.Quote: _ = paragraph.ParagraphFormat.StyleName = "Quote"; break; case StyleNames.Heading2: _ = paragraph.ParagraphFormat.StyleName = "Heading 2"; break; default: break; } return(paragraph); }
/// <summary> /// Converts plain text to a <see cref="Section"/>. /// </summary> /// <param name="key">The key. It is neccessary here because text files do not neccessarily contain the key, so that the key is used as title here.</param> /// <param name="content">The content in plain text format.</param> /// <returns>A <see cref="Section"/> that represents the plain text content.</returns> public Section ConvertTextContentToSection(string key, string content) { var doc = new Section(); var para = new Paragraph(); var run = new Run(key); run.FontSize = 22; para.AppendChild(run); doc.AppendChild(para); para = new Paragraph(); run = new Run(content); para.AppendChild(run); doc.AppendChild(para); return(doc); }
/// <summary> /// 给文档创建一个新的节 /// </summary> /// <param name="doc"></param> /// <returns></returns> public Section CreateSection(Document doc) { Section section = new Section(doc); section.PageSetup.PaperSize = PaperSize.A4; section.PageSetup.TopMargin = ConvertUtil.MillimeterToPoint(2.5 * 10); section.PageSetup.BottomMargin = ConvertUtil.MillimeterToPoint(2.5 * 10); section.PageSetup.LeftMargin = ConvertUtil.MillimeterToPoint(2.3 * 10); section.PageSetup.RightMargin = ConvertUtil.MillimeterToPoint(2.3 * 10); section.AppendChild(new Body(doc)); return(section); }
public bool Add_Named(string name, string key, string value) { try { var count = Section.GetElementsByTagName(name).Cast <XmlElement>() .Where(a => a.GetAttribute("key") == key && a.GetAttribute("value") == value).Count(); if (count != 0) { throw new DuplicateWaitObjectException(); } Section.AppendChild(new XElement(name, new XAttribute("key", key), new XAttribute("value", value)).ToXmlElement(Doc)); Doc.Save(ConfigFile.Full_Path); return(true); } catch (Exception ex) { throw ex; } }
public void BodyEnsureMinimum() { //ExStart //ExFor:Section.Body //ExFor:Body.EnsureMinimum //ExSummary:Clears main text from all sections from the document leaving the sections themselves. Document doc = new Document(); // A blank document contains one section, one body and one paragraph. // Call the "RemoveAllChildren" method to remove all those nodes, // and end up with a document node with no children. doc.RemoveAllChildren(); // This document now has no composite child nodes that we can add content to. // If we wish to edit it, we will need to repopulate its node collection. // First, create a new section, and then append it as a child to the root document node. Section section = new Section(doc); doc.AppendChild(section); // A section needs a body, which will contain and display all its contents // on the page between the section's header and footer. Body body = new Body(doc); section.AppendChild(body); // This body has no children, so we cannot add runs to it yet. Assert.AreEqual(0, doc.FirstSection.Body.GetChildNodes(NodeType.Any, true).Count); // Call the "EnsureMinimum" to make sure that this body contains at least one empty paragraph. body.EnsureMinimum(); // Now, we can add runs to the body, and get the document to display them. body.FirstParagraph.AppendChild(new Run(doc, "Hello world!")); Assert.AreEqual("Hello world!", doc.GetText().Trim()); //ExEnd }
/// <summary> /// Add a section to the end of a document, give it a body and a paragraph, then add text and an endnote to that paragraph /// </summary> private void InsertSection(Document doc, string sectionBodyText, string endnoteText) { Section section = new Section(doc); doc.AppendChild(section); Body body = new Body(doc); section.AppendChild(body); Assert.AreEqual(section, body.ParentNode); Paragraph para = new Paragraph(doc); body.AppendChild(para); Assert.AreEqual(body, para.ParentNode); DocumentBuilder builder = new DocumentBuilder(doc); builder.MoveTo(para); builder.Write(sectionBodyText); builder.InsertFootnote(FootnoteType.Endnote, endnoteText); }
public void CreateManually() { //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:Shows how to construct an Aspose.Words document by hand. Document doc = new Document(); // A blank document contains one section, one body and one paragraph. // Call the "RemoveAllChildren" method to remove all those nodes, // and end up with a document node with no children. doc.RemoveAllChildren(); // This document now has no composite child nodes that we can add content to. // If we wish to edit it, we will need to repopulate its node collection. // First, create a new section, and then append it as a child to the root document node. Section section = new Section(doc); doc.AppendChild(section); // Set some page setup properties for the section. section.PageSetup.SectionStart = SectionStart.NewPage; section.PageSetup.PaperSize = PaperSize.Letter; // A section needs a body, which will contain and display all its contents // on the page between the section's header and footer. Body body = new Body(doc); section.AppendChild(body); // Create a paragraph, set some formatting properties, and then append it as a child to the body. Paragraph para = new Paragraph(doc); para.ParagraphFormat.StyleName = "Heading 1"; para.ParagraphFormat.Alignment = ParagraphAlignment.Center; body.AppendChild(para); // Finally, add some content to do the document. Create a run, // set its appearance and contents, and then append it as a child to the paragraph. Run run = new Run(doc); run.Text = "Hello World!"; run.Font.Color = Color.Red; para.AppendChild(run); Assert.AreEqual("Hello World!", doc.GetText().Trim()); doc.Save(ArtifactsDir + "Section.CreateManually.docx"); //ExEnd }
/// <summary> /// Converts TEI XML content to a <see cref="Section"/>. /// </summary> /// <param name="content">The content to convert. It must be in TEI XML format (see README.md of <see href="https://github.com/freedict/fd-dictionaries"/>).</param> /// <returns>A <see cref="Section"/> that represents the TEI XML content.</returns> public Section ConvertTeiContentToSection(string content) { var doc = new Section(); using (var tr = System.Xml.XmlReader.Create(new StringReader(content))) { tr.MoveToContent(); tr.ReadToDescendant("orth"); var orth = tr.ReadElementContentAsString(); if (null != orth) { var para = new Paragraph(); para.AppendChild(new Run(orth) { FontSize = 23 }); doc.AppendChild(para); } if (tr.Name == "pron") { var pron = tr.ReadElementContentAsString(); var para = new Paragraph(); para.AppendChild(new Run(pron) { FontSize = 18 }); doc.AppendChild(para); } tr.ReadToFollowing("sense"); tr.ReadStartElement("sense"); var sensePara = new Paragraph(); doc.AppendChild(sensePara); while (tr.Name == "cit") { string quote = null; tr.ReadStartElement("cit"); if (tr.Name == "quote") { quote = tr.ReadElementContentAsString(); } if (null != quote) { if (sensePara.Childs.Count != 0) { sensePara.AppendChild(new Run("; ") { FontSize = 15 }); } sensePara.AppendChild(new Run(quote) { FontSize = 15 }); } tr.ReadToFollowing("cit"); } } return(doc); }
private void tsmiEditItems_Click(object sender, EventArgs e) { if (tvwItem.SelectedNode == null) { return; } XmlNode Item = (XmlNode)tvwItem.SelectedNode.Tag; frmAddItemData frm = new frmAddItemData(); frm.funStart(); frm._InputItem = Item; frm._xmlDoc = xmlDoc; if (frm.ShowDialog() == DialogResult.Yes) { XmlNode Section; string ID = tvData.SelectedNode.Name.Split(new char[] { ':' }).GetValue(0).ToString(); if (tvwItem.SelectedNode.Parent == null) { Section = xmlDoc.SelectSingleNode("//Document/Data/Section[@ID='" + ID + "']"); } else { Section = ((XmlNode)tvwItem.SelectedNode.Tag).ParentNode; } Section.RemoveChild(Item); XmlNode Items = xmlDoc.CreateElement("Items"); XmlAttribute att = xmlDoc.CreateAttribute("Name"); att.Value = frm.getName; Items.Attributes.Append(att); att = xmlDoc.CreateAttribute("Type"); att.Value = frm.getType; Items.Attributes.Append(att); if (frm._nodeOut != null) { Items.AppendChild(frm._nodeOut); } if (frm._ListItem == null) { Items.AppendChild(frm._nodeOutItem); } else { XmlNodeList Item2 = frm._ListItem.SelectNodes("./Item"); for (int i = 0; i < Item2.Count; i++) { Items.AppendChild(Item2[i]); } } Section.AppendChild(Items); tvwItem.SelectedNode.Name = frm.getName + ":" + frm.getType; tvwItem.SelectedNode.Text = "Item Name:" + frm.getName + " Type:" + frm.getType; tvwItem.SelectedNode.Tag = Items; if (frm.getType == "FIX") { tvwItem.SelectedNode.Nodes.Clear(); } } if (!frm.IsDisposed) { frm.Close(); frm.Dispose(); } funDrawMainTree(); }
private void AddItem(string sCommand) { if (tvData.SelectedNode == null) { return; } if (sCommand == "Root") { XmlNode node = (XmlNode)tvData.SelectedNode.Tag; frmAddItemData frm = new frmAddItemData(); frm._xmlDoc = xmlDoc; frm._nodeMeans = node; frm.funStart(); if (frm.ShowDialog() == DialogResult.Yes) { TreeNode nodeT = new TreeNode(); nodeT.Name = frm.getName + ":" + frm.getType; nodeT.Text = "Item Name:" + frm.getName + " Type:" + frm.getType; XmlNode Section; string ID = tvData.SelectedNode.Name.Split(new char[] { ':' }).GetValue(0).ToString(); if (tvwItem.SelectedNode == null) { Section = xmlDoc.SelectSingleNode("//Document/Data/Section[@ID='" + ID + "']"); } else { if (tvwItem.SelectedNode.Parent != null) { Section = (XmlNode)tvwItem.SelectedNode.Parent.Tag; } else { Section = xmlDoc.SelectSingleNode("//Document/Data/Section[@ID='" + ID + "']"); } } XmlNode Items = xmlDoc.CreateElement("Items"); XmlAttribute att = xmlDoc.CreateAttribute("Name"); att.Value = frm.getName; Items.Attributes.Append(att); att = xmlDoc.CreateAttribute("Type"); att.Value = frm.getType; Items.Attributes.Append(att); if (frm._nodeOut != null) { Items.AppendChild(frm._nodeOut); } if (frm._ListItem == null) { Items.AppendChild(frm._nodeOutItem); } else { XmlNodeList Item = frm._ListItem.SelectNodes("./Item"); for (int i = 0; i < Item.Count; i++) { Items.AppendChild(Item[i]); } } Section.AppendChild(Items); nodeT.Tag = Items; if (tvwItem.SelectedNode == null) { tvwItem.Nodes.Add(nodeT); } else { if (tvwItem.SelectedNode.Parent != null) { tvwItem.SelectedNode.Parent.Nodes.Add(nodeT); } else { tvwItem.Nodes.Add(nodeT); } } } if (!frm.IsDisposed) { frm.Close(); frm.Dispose(); } } else { if (sCommand != "Root") { if (tvwItem.SelectedNode.Name.Split(new char[] { ':' }).GetValue(1).ToString().ToUpper() == "FIX") { MSG.Error("äÁèÊÒÁÒöà¾ÔèÁ Item ä´éà¹×èͧ¨Ò¡ Item ¹ÕéÁÕ Type à»ç¹ FIX â»Ã´á¡éä¢ Type ¡è͹", "¢éͼԴ¾ÅÒ´"); return; } } XmlNode node = (XmlNode)tvData.SelectedNode.Tag; frmAddItemData frm = new frmAddItemData(); frm._xmlDoc = xmlDoc; frm._nodeMeans = node; frm.funStart(); if (frm.ShowDialog() == DialogResult.Yes) { TreeNode nodeT = new TreeNode(); nodeT.Name = frm.getName + ":" + frm.getType; nodeT.Text = "Item Name:" + frm.getName + " Type:" + frm.getType; XmlNode Section; XmlNode SelectItem = (XmlNode)tvwItem.SelectedNode.Tag; Section = SelectItem.SelectSingleNode("./Item"); XmlNode Items = xmlDoc.CreateElement("Items"); XmlAttribute att = xmlDoc.CreateAttribute("Name"); att.Value = frm.getName; Items.Attributes.Append(att); att = xmlDoc.CreateAttribute("Type"); att.Value = frm.getType; Items.Attributes.Append(att); if (frm._nodeOut != null) { Items.AppendChild(frm._nodeOut); } if (frm._ListItem == null) { Items.AppendChild(frm._nodeOutItem); } else { XmlNodeList Item = frm._ListItem.SelectNodes("./Item"); for (int i = 0; i < Item.Count; i++) { Items.AppendChild(Item[i]); } } Section.AppendChild(Items); nodeT.Tag = Items; tvwItem.SelectedNode.Nodes.Add(nodeT); } } tvwItem.ExpandAll(); funDrawMainTree(); }
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. Document doc = new 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. Section section = new 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 = 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"); // Save the document. doc.Save(ArtifactsDir + "Section.CreateFromScratch.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:Shows how to construct an Aspose Words document node by node. Document doc = new Document(); // A newly created blank document still comes one section, one body and one paragraph // Calling this method will remove all those nodes to completely empty the document doc.RemoveAllChildren(); // This document now has no composite nodes that content can be added to // If we wish to edit it, we will need to repopulate its node collection, // which we will start to do with by creating a new Section node Section section = new Section(doc); // Append the section to the document doc.AppendChild(section); // Set some properties for the section section.PageSetup.SectionStart = SectionStart.NewPage; section.PageSetup.PaperSize = PaperSize.Letter; // A section needs a body, which will contain all other nodes that can be edited 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; // Now we can begin adding content to the document Run run = new Run(doc); run.Text = "Hello World!"; run.Font.Color = Color.Red; para.AppendChild(run); Assert.AreEqual("Hello World!" + ControlChar.SectionBreakChar, doc.GetText()); doc.Save(ArtifactsDir + "Section.CreateFromScratch.docx"); //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. Document doc = new 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. Section section = new 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()); }