Cómo cambiar el fondo en un comentario en Excel

Cómo cambiar el color en un 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 Comentarios en Excel?

El siguiente código le guiará cómo utilizarAspose.Cells para agregar su color de fondo favorito a los comentarios de su elección.

Aquí hemos preparado unarchivo de muestra para usted. Este archivo se usa para inicializar el objeto Workbook en el código a continuación.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// The path to the documents directory.
String path = "";
//Initialize a new workbook.
Workbook book = new Workbook(path + "exmaple.xlsx");
// Accessing the newly added comment
com.aspose.cells.Comment comment = book.getWorksheets().get(0).getComments().get(0);
// change background color
Shape shape = comment.getCommentShape();
shape.getFill().getSolidFill().setColor(Color.getRed());
// Save the Excel file
book.save(path + "result.xlsx");

Ejecute el código anterior y obtendrá unarchivo de salida.

Cómo insertar una imagen o imagen en un comentario en Excel

Microsoft Excel permite a los usuarios personalizar en gran medida la apariencia de las hojas de cálculo. Incluso es posible agregar imágenes de fondo a los comentarios. Agregar una imagen de fondo puede ser una opción estética o usarse para fortalecer la marca.

El código de muestra a continuación crea un archivo XLSX desde cero usandoAspose.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-Java
// The path to the documents directory.
String dataDir = "";
// Create directory if it is not already present.
File file = new File(dataDir);
if(!file.exists())
file.mkdir();
// Instantiate a Workbook
Workbook workbook = new Workbook();
// Get a reference of comments collection with the first sheet
com.aspose.cells.CommentCollection comments = workbook.getWorksheets().get(0).getComments();
// Add a comment to cell A1
int commentIndex = comments.add(0, 0);
com.aspose.cells.Comment comment = comments.get(commentIndex);
comment.setNote("First note.");
comment.getFont().setName("Times New Roman");
// Load an image
String filename = dataDir + "image.jpg";
byte[] result = null;
java.nio.channels.FileChannel fc = null;
try {
fc = new java.io.RandomAccessFile(filename, "r").getChannel();
java.nio.MappedByteBuffer byteBuffer = fc.map(java.nio.channels.FileChannel.MapMode.READ_ONLY, 0,
fc.size()).load();
System.out.println(byteBuffer.isLoaded());
result = new byte[(int) fc.size()];
if (byteBuffer.remaining() > 0) {
byteBuffer.get(result, 0, byteBuffer.remaining());
}
} catch (IOException e) {
throw e;
} finally {
try {
fc.close();
} catch (IOException e) {
throw e;
}
}
// Set image data to the shape associated with the comment
comment.getCommentShape().getFill().setImageData(result);
// Save the workbook
String resDataDir = dataDir + "commentwithpicture1.out.xlsx";
workbook.save(resDataDir);