Exemplo 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 3
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);
 }
Exemplo n.º 4
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);
        }