/// <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); }
/// <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); }