/// <summary> /// Called when a Comment is encountered in the document. /// </summary> public override VisitorAction VisitCommentStart(Aspose.Words.Comment comment) { if (isHidden(comment)) { comment.Remove(); } return(VisitorAction.Continue); }
public ReplaceAction Replacing(ReplacingArgs e) { Node currentNode = e.MatchNode; if (currentNode.NodeType != NodeType.Run || currentNode.Range.Text.Trim() == string.Empty) { return(ReplaceAction.Skip); } if (e.MatchOffset > 0) { currentNode = SplitRun((Run)currentNode, e.MatchOffset); } List <Node> runs = new List <Node>(); int remainingLength = e.Match.Value.Length; while ( (remainingLength > 0) && (currentNode != null) && (currentNode.GetText().Length <= remainingLength)) { runs.Add(currentNode); remainingLength = remainingLength - currentNode.GetText().Length; do { currentNode = currentNode.NextSibling; } while ((currentNode != null) && (currentNode.NodeType != NodeType.Run)); } if ((currentNode != null) && (remainingLength > 0)) { SplitRun((Run)currentNode, remainingLength); runs.Add(currentNode); } foreach (Run run in runs) { run.Text = string.Empty; run.Font.HighlightColor = CommentsQualifer.GetHighlightColor(); } ((Run)runs.First()).Text = CommentsQualifer.CommentErrorText; Aspose.Words.Comment comment = new Aspose.Words.Comment(runs.First().Document); comment.Paragraphs.Add(new Paragraph(comment.Document)); string text = e.Replacement; text = text.Replace(CommentsQualifer.CommentsBegin, string.Empty); text = text.Replace(CommentsQualifer.CommentsEnd, string.Empty); comment.FirstParagraph.SetText(text); runs.First().ParentNode.InsertBefore(new CommentRangeStart(comment.Document, comment.Id), runs.First()); runs.First().ParentNode.InsertAfter(new CommentRangeEnd(comment.Document, comment.Id), runs.Last()); runs.Last().ParentNode.AppendChild(comment); return(ReplaceAction.Skip); }
public void SetTextEx() { //ExStart //ExFor:Comment.SetText //ExSummary:Shows how to use SetText. Aspose.Words.Document doc = new Aspose.Words.Document(ExDir + "Document.doc"); DocumentBuilder builder = new DocumentBuilder(doc); Aspose.Words.Comment comment = new Aspose.Words.Comment(doc, "John Doe", "J.D.", DateTime.Now); builder.CurrentParagraph.AppendChild(comment); comment.SetText("My comment."); //ExEnd }
public void AddComment() { //ExStart //ExFor:Comment //ExFor:InlineStory //ExFor:InlineStory.Paragraphs //ExFor:InlineStory.FirstParagraph //ExFor:Comment.#ctor(DocumentBase, String, String, DateTime) //ExSummary:Shows how to add a comment to a paragraph in the document. Aspose.Words.Document doc = new Aspose.Words.Document(); DocumentBuilder builder = new DocumentBuilder(doc); builder.Write("Some text is added."); Aspose.Words.Comment comment = new Aspose.Words.Comment(doc, "Amy Lee", "AL", DateTime.Today); builder.CurrentParagraph.AppendChild(comment); comment.Paragraphs.Add(new Paragraph(doc)); comment.FirstParagraph.Runs.Add(new Run(doc, "Comment text.")); //ExEnd Assert.AreEqual("Comment text.\r", (doc.GetChildNodes(NodeType.Comment, true)[0]).GetText()); }
public string AsposePost(string docxPath, string cmt) { try { // Open an existing document to add comments to a paragraph. Aspose.Words.Document doc = new Aspose.Words.Document(docxPath); Node[] nodes = doc.GetChildNodes(NodeType.Paragraph, true).ToArray(); //E.g this is the Paragraph to which comments will added Aspose.Words.Paragraph paragraph = (Aspose.Words.Paragraph)nodes[1]; Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(doc); // Create a Comment. Aspose.Words.Comment comment = new Aspose.Words.Comment(doc); // Insert some text into the comment. Aspose.Words.Paragraph commentParagraph = new Aspose.Words.Paragraph(doc); commentParagraph.AppendChild(new Aspose.Words.Run(doc, cmt)); comment.AppendChild(commentParagraph); //Move to paragraph where comments will be added builder.MoveTo(paragraph); // Insert comment builder.InsertNode(comment); var newDocxPath = Path.GetTempFileName().Replace(".tmp", ".docx"); // Save output document. doc.Save(newDocxPath); return(newDocxPath); } catch (Exception) { return("undone"); } }