Administrar comentarios y notas

Introducción

Los comentarios se utilizan para agregar información adicional a las celdas. Aspose.Cells proporciona dos métodos para agregar comentarios a las celdas. La primera es crear comentarios en un archivo de diseñador manualmente. Estos comentarios luego se importan usando Aspose.Cells. El segundo es agregar comentarios usando Aspose.Cells API en tiempo de ejecución. Este tema trata sobre la adición de comentarios a las celdas mediante Aspose.Cells API. También se explicará el formato de los comentarios.

Agregar un comentario

Agregue un comentario a una celda llamando alComentarios colecciónAgregar método (encapsulado en elHoja de cálculo objeto). El nuevoComentario Se puede acceder al objeto desde elComentarios colección pasando el índice de comentarios. Después de acceder a laComentario objeto, personalice la nota de comentario utilizando elComentario objetosNotapropiedad.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Create directory if it is not already present.
bool IsExists = System.IO.Directory.Exists(dataDir);
if (!IsExists)
System.IO.Directory.CreateDirectory(dataDir);
// Instantiating a Workbook object
Workbook workbook = new Workbook();
// Adding a new worksheet to the Workbook object
int sheetIndex = workbook.Worksheets.Add();
// Obtaining the reference of the newly added worksheet by passing its sheet index
Worksheet worksheet = workbook.Worksheets[sheetIndex];
// Adding a comment to "F5" cell
int commentIndex = worksheet.Comments.Add("F5");
// Accessing the newly added comment
Comment comment = worksheet.Comments[commentIndex];
// Setting the comment note
comment.Note = "Hello Aspose!";
// Saving the Excel file
workbook.Save(dataDir + "book1.out.xls");

Formato de comentario

También es posible dar formato a la apariencia de los comentarios configurando su altura, ancho y configuración de fuente.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Create directory if it is not already present.
bool IsExists = System.IO.Directory.Exists(dataDir);
if (!IsExists)
System.IO.Directory.CreateDirectory(dataDir);
// Instantiating a Workbook object
Workbook workbook = new Workbook();
// Adding a new worksheet to the Workbook object
int sheetIndex = workbook.Worksheets.Add();
// Obtaining the reference of the newly added worksheet by passing its sheet index
Worksheet worksheet = workbook.Worksheets[sheetIndex];
// Adding a comment to "F5" cell
int commentIndex = worksheet.Comments.Add("F5");
// Accessing the newly added comment
Comment comment = worksheet.Comments[commentIndex];
// Setting the comment note
comment.Note = "Hello Aspose!";
// Setting the font size of a comment to 14
comment.Font.Size = 14;
// Setting the font of a comment to bold
comment.Font.IsBold = true;
// Setting the height of the font to 10
comment.HeightCM = 10;
// Setting the width of the font to 2
comment.WidthCM = 2;
// Saving the Excel file
workbook.Save(dataDir + "book1.out.xls");

Agregar una imagen para comentar

Con Microsoft Excel 2007, también es posible tener una imagen como fondo de un comentario de celda. En Excel 2007 esto se logra siguiendo los siguientes pasos. (Suponen que ya ha agregado un comentario de celda).

  1. Haga clic derecho en la celda que contiene el comentario.
  2. SeleccioneMostrar/Ocultar comentariosy borre cualquier texto del comentario.
  3. Haga clic en el borde del comentario para seleccionarlo.
  4. SeleccioneFormato , despuésComentario.
  5. Sobre elColores y Líneas pestaña, expanda laColor lista.
  6. Hacer clicEfectos de relleno.
  7. Sobre elFotografía pestaña, haga clicSeleccionar imagen.
  8. Localiza y selecciona la imagen.
  9. Hacer clicDE ACUERDO hasta que todos los cuadros de diálogo se hayan cerrado.

Aspose.Cells también ofrece esta función. A continuación se muestra un ejemplo de código que crea un archivo XLSX desde cero, agregando un comentario a la celda “A1” con una imagen configurada como fondo.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Create directory if it is not already present.
bool IsExists = System.IO.Directory.Exists(dataDir);
if (!IsExists)
System.IO.Directory.CreateDirectory(dataDir);
// Instantiate a Workbook
Workbook workbook = new Workbook();
// Get a reference of comments collection with the first sheet
CommentCollection comments = workbook.Worksheets[0].Comments;
// Add a comment to cell A1
int commentIndex = comments.Add(0, 0);
Comment comment = comments[commentIndex];
comment.Note = "First note.";
comment.Font.Name = "Times New Roman";
// Load an image into stream
Bitmap bmp = new Bitmap(dataDir + "logo.jpg");
MemoryStream ms = new MemoryStream();
bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
// Set image data to the shape associated with the comment
comment.CommentShape.Fill.ImageData = ms.ToArray();
// Save the workbook
workbook.Save(dataDir + "book1.out.xlsx", Aspose.Cells.SaveFormat.Xlsx);

Temas avanzados