示例#1
0
        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");
            }
        }