Excluir todos os comentários de um autor
Contents
[
Hide
]
OpenXML SDK
string FilePath = @"..\..\..\..\Sample Files\";
string FileName = FilePath + "Delete all the comments by an author.pptx";
string author = "Zeeshan Shafqat";
DeleteCommentsByAuthorInPresentation(FileName, author);
// Remover todos os comentários nos slides de um determinado autor.
public static void DeleteCommentsByAuthorInPresentation(string fileName, string author)
{
if (String.IsNullOrEmpty(fileName) || String.IsNullOrEmpty(author))
throw new ArgumentNullException("File name or author name is NULL!");
using (PresentationDocument doc = PresentationDocument.Open(fileName, true))
{
// Obter o autor de comentário especificado.
IEnumerable<CommentAuthor> commentAuthors =
doc.PresentationPart.CommentAuthorsPart.CommentAuthorList.Elements<CommentAuthor>()
.Where(e => e.Name.Value.Equals(author));
// Percorrer todos os autores correspondentes.
foreach (CommentAuthor commentAuthor in commentAuthors)
{
UInt32Value authorId = commentAuthor.Id;
// Percorrer todos os slides e obter as partes do slide.
foreach (SlidePart slide in doc.PresentationPart.SlideParts)
{
SlideCommentsPart slideCommentsPart = slide.SlideCommentsPart;
// Obter a lista de comentários.
if (slideCommentsPart != null && slide.SlideCommentsPart.CommentList != null)
{
IEnumerable<Comment> commentList =
slideCommentsPart.CommentList.Elements<Comment>().Where(e => e.AuthorId == authorId.Value);
List<Comment> comments = new List<Comment>();
comments = commentList.ToList<Comment>();
foreach (Comment comm in comments)
{
// Excluir todos os comentários do autor especificado.
slideCommentsPart.CommentList.RemoveChild<Comment>(comm);
}
// Se a parte de comentário não tiver nenhum comentário existente.
if (slideCommentsPart.CommentList.ChildElements.Count == 0)
// Excluir esta parte.
slide.DeletePart(slideCommentsPart);
}
}
// Excluir o autor de comentário da parte de autores de comentário.
doc.PresentationPart.CommentAuthorsPart.CommentAuthorList.RemoveChild<CommentAuthor>(commentAuthor);
}
}
}
Aspose.Slides
string FilePath = @"..\..\..\..\Sample Files\";
string FileName = FilePath + "Delete all the comments by an author.pptx";
string author = "MZ";
DeleteCommentsByAuthorInPresentation(FileName, author);
// Remover todos os comentários nos slides de um determinado autor.
public static void DeleteCommentsByAuthorInPresentation(string fileName, string author)
{
if (String.IsNullOrEmpty(fileName) || String.IsNullOrEmpty(author))
throw new ArgumentNullException("File name or author name is NULL!");
//Instanciar um objeto PresentationEx que representa um arquivo PPTX
using (Presentation pres = new Presentation(fileName))
{
ICommentAuthor[] authors= pres.CommentAuthors.FindByName(author);
ICommentAuthor thisAuthor = authors[0];
for (int i = thisAuthor.Comments.Count - 1; i >= 0;i-- )
{
thisAuthor.Comments.RemoveAt(i);
}
pres.Save(fileName, Aspose.Slides.Export.SaveFormat.Pptx);
}
}