private static void GenerateWorksheetCommentsPartContent(WorksheetCommentsPart worksheetCommentsPart, XLWorksheet xlWorksheet) { var comments = new Comments(); var commentList = new CommentList(); var authorsDict = new Dictionary<String, Int32>(); foreach (var c in xlWorksheet.Internals.CellsCollection.GetCells(c => c.HasComment)) { var comment = new Comment {Reference = c.Address.ToStringRelative()}; var authorName = c.Comment.Author; Int32 authorId; if (!authorsDict.TryGetValue(authorName, out authorId)) { authorId = authorsDict.Count; authorsDict.Add(authorName, authorId); } comment.AuthorId = (UInt32)authorId; var commentText = new CommentText(); foreach (var rt in c.Comment) { commentText.Append(GetRun(rt)); } comment.Append(commentText); commentList.Append(comment); } var authors = new Authors(); foreach (var author in authorsDict.Select(a => new Author {Text = a.Key})) { authors.Append(author); } comments.Append(authors); comments.Append(commentList); worksheetCommentsPart.Comments = comments; }
// Generates content of worksheetCommentsPart1. private void GenerateWorksheetCommentsPart1Content(WorksheetCommentsPart worksheetCommentsPart1) { Comments comments1 = new Comments(); Authors authors1 = new Authors(); Author author1 = new Author(); author1.Text = "Author"; authors1.Append(author1); CommentList commentList1 = new CommentList(); Comment comment1 = new Comment() { Reference = "V10", AuthorId = (UInt32Value)0U, ShapeId = (UInt32Value)0U }; CommentText commentText1 = new CommentText(); Run run14 = new Run(); RunProperties runProperties14 = new RunProperties(); Bold bold1 = new Bold(); FontSize fontSize1 = new FontSize() { Val = 9D }; Color color1 = new Color() { Indexed = (UInt32Value)81U }; RunFont runFont1 = new RunFont() { Val = "Tahoma" }; RunPropertyCharSet runPropertyCharSet1 = new RunPropertyCharSet() { Val = 1 }; runProperties14.Append(bold1); runProperties14.Append(fontSize1); runProperties14.Append(color1); runProperties14.Append(runFont1); runProperties14.Append(runPropertyCharSet1); Text text14 = new Text(); text14.Text = "Author:"; run14.Append(runProperties14); run14.Append(text14); Run run15 = new Run(); RunProperties runProperties15 = new RunProperties(); FontSize fontSize2 = new FontSize() { Val = 9D }; Color color2 = new Color() { Indexed = (UInt32Value)81U }; RunFont runFont2 = new RunFont() { Val = "Tahoma" }; RunPropertyCharSet runPropertyCharSet2 = new RunPropertyCharSet() { Val = 1 }; runProperties15.Append(fontSize2); runProperties15.Append(color2); runProperties15.Append(runFont2); runProperties15.Append(runPropertyCharSet2); Text text15 = new Text() { Space = SpaceProcessingModeValues.Preserve }; text15.Text = "\nThis is a comment"; run15.Append(runProperties15); run15.Append(text15); commentText1.Append(run14); commentText1.Append(run15); comment1.Append(commentText1); commentList1.Append(comment1); comments1.Append(authors1); comments1.Append(commentList1); worksheetCommentsPart1.Comments = comments1; }