Cómo cambiar el fondo en el comentario en Excel
Cómo cambiar el color en el comentario en Excel
Cuando no necesite el color de fondo predeterminado para los comentarios, es posible que desee reemplazarlo con un color que le interese. ¿Cómo cambio el color de fondo del cuadro de comentarios en Excel?
El siguiente código le guiará sobre cómo usar Aspose.Cells para agregar su color de fondo favorito a los comentarios de su elección.
Aquí hemos preparado un archivo de muestra para usted. Este archivo se usa para inicializar el objeto Workbook en el siguiente código.
// 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 path = ""; | |
//Initialize a new workbook. | |
Workbook book = new Workbook(path + "exmaple.xlsx"); | |
// Accessing the newly added comment | |
Comment comment = book.Worksheets[0].Comments[0]; | |
// change background color | |
Shape shape = comment.CommentShape; | |
shape.Fill.SolidFill.Color = Color.Red; | |
// Save the Excel file | |
book.Save(path + "result.xlsx"); |
Ejecute el código anterior y obtendrá un archivo de salida.
Cómo insertar una imagen en el comentario en Excel
Microsoft Excel permite a los usuarios personalizar la apariencia de las hojas de cálculo en gran medida. Incluso es posible agregar imágenes de fondo a los comentarios. Agregar una imagen de fondo puede ser una elección estética o utilizarse para fortalecer la marca.
El código de muestra a continuación crea un archivo XLSX desde cero utilizando Aspose.Cells API, y agrega un comentario con una imagen de fondo a la celda A1.
// 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 = ""; | |
// 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 + "image2.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(); | |
dataDir = dataDir + "commentwithpicture1.out.xlsx"; | |
// Save the workbook | |
workbook.Save(dataDir, Aspose.Cells.SaveFormat.Xlsx); |