예제 #1
0
        /// <summary>
        /// Adds a comment to the top left cell of the range
        /// </summary>
        /// <param name="cell">The cell</param>
        /// <param name="Text">The comment text</param>
        /// <param name="author">Author</param>
        /// <returns>The comment</returns>
        public ExcelComment Add(ExcelRangeBase cell, string Text, string author)
        {
            var elem = CommentXml.CreateElement("comment", ExcelPackage.schemaMain);
            int ix   = _comments.IndexOf(ExcelAddress.GetCellID(Worksheet.SheetID, cell._fromRow, cell._fromCol));

            //Make sure the nodes come on order.
            if (ix < 0 && (~ix < _comments.Count))
            {
                ix = ~ix;
                var preComment = _comments[ix] as ExcelComment;
                preComment._commentHelper.TopNode.ParentNode.InsertBefore(elem, preComment._commentHelper.TopNode);
            }
            else
            {
                CommentXml.SelectSingleNode("d:comments/d:commentList", NameSpaceManager).AppendChild(elem);
            }
            elem.SetAttribute("ref", cell.Start.Address);
            ExcelComment comment = new ExcelComment(NameSpaceManager, elem, cell);

            comment.RichText.Add(Text);
            if (author != "")
            {
                comment.Author = author;
            }
            _comments.Add(comment);
            return(comment);
        }
예제 #2
0
        private void AddCommentsFromXml()
        {
            var lst = new List <IRangeID>();

            foreach (XmlElement node in CommentXml.SelectNodes("//d:commentList/d:comment", NameSpaceManager))
            {
                var comment = new ExcelComment(NameSpaceManager, node, new ExcelRangeBase(Worksheet, node.GetAttribute("ref")));
                lst.Add(comment);
            }
            _comments = new RangeCollection(lst);
        }
예제 #3
0
        /// <summary>
        /// Removes the comment
        /// </summary>
        /// <param name="comment">The comment to remove</param>
        public void Remove(ExcelComment comment)
        {
            ulong id = ExcelAddress.GetCellID(Worksheet.SheetID, comment.Range._fromRow, comment.Range._fromCol);
            int   ix = _comments.IndexOf(id);

            if (ix >= 0 && comment == _comments[ix])
            {
                comment.TopNode.ParentNode.RemoveChild(comment.TopNode);                               //Remove VML
                comment._commentHelper.TopNode.ParentNode.RemoveChild(comment._commentHelper.TopNode); //Remove Comment

                Worksheet.VmlDrawingsComments._drawings.Delete(id);
                _comments.Delete(id);
            }
            else
            {
                throw (new ArgumentException("Comment does not exist in the worksheet"));
            }
        }