Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Adds a comment.
        /// </summary>
        /// <param name="cell">The cell to which the comment is added.</param>
        /// <param name="text">The text of the comment.</param>
        /// <param name="author">The author of the comment.</param>
        public ExcelComment Add(ExcelRangeBase cell, string text, string author)
        {
            var element = this.CommentXml.CreateElement("comment", ExcelPackage.schemaMain);
            // Make sure the nodes are sorted, by column and then by row.
            int nextCommentRow    = cell._fromRow;
            int nextCommentColumn = cell._fromCol;

            if (this.Comments.Count == 0 || !this.Worksheet._commentsStore.NextCell(ref nextCommentRow, ref nextCommentColumn))
            {
                this.CommentXml.SelectSingleNode("d:comments/d:commentList", this.NameSpaceManager).AppendChild(element);
            }
            else
            {
                ExcelComment nextComment = this.Comments[Worksheet._commentsStore.GetValue(nextCommentRow, nextCommentColumn)];
                nextComment.CommentHelper.TopNode.ParentNode.InsertBefore(element, nextComment.CommentHelper.TopNode);
            }
            ExcelComment comment = new ExcelComment(this.NameSpaceManager, element, cell);

            comment.Reference = new ExcelAddress(cell._fromRow, cell._fromCol, cell._fromRow, cell._fromCol).Address;
            comment.RichText.Add(text);
            if (author != string.Empty)
            {
                comment.Author = author;
            }
            this.Comments.Add(comment);
            this.Worksheet._commentsStore.SetValue(cell.Start.Row, cell.Start.Column, this.Comments.Count - 1);
            if (!this.Worksheet.ExistsValueInner(cell._fromRow, cell._fromCol))
            {
                this.Worksheet.SetValueInner(cell._fromRow, cell._fromCol, null);
            }
            return(comment);
        }
Ejemplo n.º 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);
            int          i = -1;
            ExcelComment c = null;

            if (Worksheet._commentsStore.Exists(comment.Range._fromRow, comment.Range._fromCol, ref i))
            {
                c = _list[i];
            }
            if (comment == c)
            {
                comment.TopNode.ParentNode.RemoveChild(comment.TopNode);                               //Remove VML
                comment._commentHelper.TopNode.ParentNode.RemoveChild(comment._commentHelper.TopNode); //Remove Comment

                Worksheet.VmlDrawingsComments._drawings.Delete(id);
                _list.RemoveAt(i);
                Worksheet._commentsStore.Delete(comment.Range._fromRow, comment.Range._fromCol, 1, 1, false);   //Issue 15549, Comments should not be shifted
                var ci = new CellsStoreEnumerator <int>(Worksheet._commentsStore);
                while (ci.Next())
                {
                    if (ci.Value > i)
                    {
                        ci.Value -= 1;
                    }
                }
            }
            else
            {
                throw (new ArgumentException("Comment does not exist in the worksheet"));
            }
        }
Ejemplo n.º 4
0
 private void AddCommentsFromXml()
 {
     foreach (XmlElement node in this.CommentXml.SelectNodes("//d:commentList/d:comment", NameSpaceManager))
     {
         var comment = new ExcelComment(NameSpaceManager, node, new ExcelRangeBase(this.Worksheet, node.GetAttribute("ref")));
         this.Comments.Add(comment);
         this.Worksheet._commentsStore.SetValue(comment.Range._fromRow, comment.Range._fromCol, this.Comments.Count - 1);
     }
 }
 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);
 }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Adds a comment that is styled the same as the specified <paramref name="copyComment"/>.
        /// </summary>
        /// <param name="cell">The cell to which the comment is added.</param>
        /// <param name="copyComment">The comment to copy.</param>
        public void Add(ExcelRangeBase cell, ExcelComment copyComment)
        {
            var element = this.CommentXml.CreateElement("comment", ExcelPackage.schemaMain);
            // Make sure the nodes come in order.
            int nextCommentRow    = cell._fromRow;
            int nextCommentColumn = cell._fromCol;

            if (this.Comments.Count == 0 || !this.Worksheet._commentsStore.NextCell(ref nextCommentRow, ref nextCommentColumn))
            {
                this.CommentXml.SelectSingleNode("d:comments/d:commentList", this.NameSpaceManager).AppendChild(element);
            }
            else
            {
                ExcelComment nextComment = this.Comments[Worksheet._commentsStore.GetValue(nextCommentRow, nextCommentColumn)];
                nextComment.CommentHelper.TopNode.ParentNode.InsertBefore(element, nextComment.CommentHelper.TopNode);
            }
            ExcelComment comment = new ExcelComment(this.NameSpaceManager, element, cell);

            comment.RichText = copyComment.RichText;
            // Copy text styling.
            comment.CommentHelper.TopNode.SelectSingleNode(".//d:text", this.NameSpaceManager).InnerXml = copyComment.CommentHelper.TopNode.SelectSingleNode(".//d:text", this.NameSpaceManager).InnerXml;
            string author = copyComment.Author;

            if (string.IsNullOrEmpty(author))
            {
                author = Thread.CurrentPrincipal.Identity.Name;
            }
            comment.Reference = new ExcelAddress(cell._fromRow, cell._fromCol, cell._fromRow, cell._fromCol).Address;
            comment.Author    = author;
            float rowMarginOffset = 0, columnMarginOffset = 0;
            int   rowDirection = comment.Range._fromRow.CompareTo(copyComment.Range._fromRow);
            var   fromRow      = Math.Min(comment.Range._fromRow, copyComment.Range._fromRow);
            var   toRow        = Math.Max(comment.Range._fromRow, copyComment.Range._fromRow);

            for (int i = fromRow; i < toRow; i++)
            {
                rowMarginOffset += (float)this.Worksheet.Row(i).Height;
            }
            int columnDirection = comment.Range._fromCol.CompareTo(copyComment.Range._fromCol);
            var fromColumn      = Math.Min(comment.Range._fromCol, copyComment.Range._fromCol);
            var toColumn        = Math.Max(comment.Range._fromCol, copyComment.Range._fromCol);

            for (int i = fromColumn; i < toColumn; i++)
            {
                columnMarginOffset += (float)this.Worksheet.Column(i).Width;
            }
            this.Comments.Add(comment);
            this.Worksheet._commentsStore.SetValue(cell._fromRow, cell._fromCol, this.Comments.Count - 1);
            // Check if a value exists otherwise add one so it is saved when the cells collection is iterated.
            if (!this.Worksheet.ExistsValueInner(cell._fromRow, cell._fromCol))
            {
                this.Worksheet.SetValueInner(cell._fromRow, cell._fromCol, null);
            }
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Removes the comment
 /// </summary>
 /// <param name="comment">The comment to remove</param>
 public void Remove(ExcelComment comment)
 {
     if (comment != null && this.Comments.Contains(comment))
     {
         comment.CommentHelper.TopNode.ParentNode.RemoveChild(comment.CommentHelper.TopNode);                 //Remove Comment
         this.Comments.Remove(comment);
     }
     else
     {
         throw (new ArgumentException("Comment does not exist in the worksheet"));
     }
 }
Ejemplo n.º 9
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);
         _list.Add(comment);
         Worksheet._commentsStore.SetValue(comment.Range._fromRow, comment.Range._fromCol, _list.Count - 1);
     }
     //_comments = new RangeCollection(lst);
 }
Ejemplo n.º 10
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"));
            }
        }
Ejemplo n.º 11
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.
            int          row = cell.Start.Row, column = cell.Start.Column;
            ExcelComment nextComment = null;

            if (Worksheet._commentsStore.NextCell(ref row, ref column))
            {
                nextComment = _list[Worksheet._commentsStore.GetValue(row, column)];
            }
            if (nextComment == null)
            {
                CommentXml.SelectSingleNode("d:comments/d:commentList", NameSpaceManager).AppendChild(elem);
            }
            else
            {
                nextComment._commentHelper.TopNode.ParentNode.InsertBefore(elem, nextComment._commentHelper.TopNode);
            }
            elem.SetAttribute("ref", cell.Start.Address);
            ExcelComment comment = new ExcelComment(NameSpaceManager, elem, cell);

            comment.RichText.Add(Text);
            if (author != "")
            {
                comment.Author = author;
            }
            _listIndex.Add(_list.Count);
            Worksheet._commentsStore.SetValue(cell.Start.Row, cell.Start.Column, _list.Count);
            _list.Add(comment);
            //Check if a value exists otherwise add one so it is saved when the cells collection is iterated
            if (!Worksheet.ExistsValueInner(cell._fromRow, cell._fromCol))
            {
                Worksheet.SetValueInner(cell._fromRow, cell._fromCol, null);
            }
            return(comment);
        }
Ejemplo n.º 12
0
        internal void Remove(ExcelComment comment, bool shift)
        {
            int          i = -1;
            ExcelComment c = null;

            if (Worksheet._commentsStore.Exists(comment.Range._fromRow, comment.Range._fromCol, ref i))
            {
                c = _list[i];
            }
            if (comment == c)
            {
                comment.TopNode.ParentNode.RemoveChild(comment.TopNode);                               //Remove VML
                comment._commentHelper.TopNode.ParentNode.RemoveChild(comment._commentHelper.TopNode); //Remove Comment

                Worksheet.VmlDrawingsComments._drawings.Delete(comment.Range._fromRow, comment.Range._fromCol, 1, 1, shift);
                Worksheet._commentsStore.Delete(comment.Range._fromRow, comment.Range._fromCol, 1, 1, shift);
                _list[i] = null;
                _listIndex.Remove(i);
            }
            else
            {
                throw (new ArgumentException("Comment does not exist in the worksheet"));
            }
        }
Ejemplo n.º 13
0
 public ExcelElementInfo(string value, Color color, ExcelComment excelComment
                         , int fontSize) : this(value, color, excelComment)
 {
     FontSize = fontSize;
 }
Ejemplo n.º 14
0
 public ExcelElementInfo(string value, ExcelComment excelComment) : this(value)
 {
     ExcelComment = excelComment;
 }
Ejemplo n.º 15
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);
     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;
 }
Ejemplo n.º 16
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.
     int row=cell.Start.Row, column= cell.Start.Column;
     ExcelComment nextComment = null;
     if (Worksheet._commentsStore.NextCell(ref row, ref column))
     {
         nextComment = _list[Worksheet._commentsStore.GetValue(row, column)];
     }
     if(nextComment==null)
     {
         CommentXml.SelectSingleNode("d:comments/d:commentList", NameSpaceManager).AppendChild(elem);
     }
     else
     {
         nextComment._commentHelper.TopNode.ParentNode.InsertBefore(elem, nextComment._commentHelper.TopNode);
     }
     elem.SetAttribute("ref", cell.Start.Address);
     ExcelComment comment = new ExcelComment(NameSpaceManager, elem , cell);
     comment.RichText.Add(Text);
     if(author!="")
     {
         comment.Author=author;
     }
     _list.Add(comment);
     Worksheet._commentsStore.SetValue(cell.Start.Row, cell.Start.Column, _list.Count-1);
     //Check if a value exists otherwise add one so it is saved when the cells collection is iterated
     if (!Worksheet.ExistsValueInner(cell._fromRow, cell._fromCol))
     {
         Worksheet.SetValueInner(cell._fromRow, cell._fromCol, null);
     }
     return comment;
 }
Ejemplo n.º 17
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);
            int i = -1;
            ExcelComment c=null;
            if (Worksheet._commentsStore.Exists(comment.Range._fromRow, comment.Range._fromCol, ref i))
            {
                c = _list[i];
            }
            if (comment==c)
            {
                comment.TopNode.ParentNode.RemoveChild(comment.TopNode); //Remove VML
                comment._commentHelper.TopNode.ParentNode.RemoveChild(comment._commentHelper.TopNode); //Remove Comment

                Worksheet.VmlDrawingsComments._drawings.Delete(id);
                _list.RemoveAt(i);
                Worksheet._commentsStore.Delete(comment.Range._fromRow, comment.Range._fromCol, 1, 1);
                var ci = new CellsStoreEnumerator<int>(Worksheet._commentsStore);
                while(ci.Next())
                {
                    if(ci.Value>i)
                    {
                        ci.Value -= 1;
                    }
                }
            }
            else
            {
                throw (new ArgumentException("Comment does not exist in the worksheet"));
            }
        }
Ejemplo n.º 18
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);
         _list.Add(comment);
         Worksheet._commentsStore.SetValue(comment.Range._fromRow, comment.Range._fromCol, _list.Count-1);
     }
     //_comments = new RangeCollection(lst);
 }
        /// <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"));
            }
        }
 /// <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;
 }
Ejemplo n.º 21
0
 /// <summary>
 /// Removes the comment
 /// </summary>
 /// <param name="comment">The comment to remove</param>
 public void Remove(ExcelComment comment)
 {
     Remove(comment, false);
 }
Ejemplo n.º 22
0
 public ExcelElementInfo(string value, Color color
                         , ExcelComment excelComment) : this(value, excelComment)
 {
     Color = color;
 }