Cómo cambiar el fondo del comentario en Excel con Node.js a través de C++
Cómo cambiar el color en el comentario en Excel
Cuando no necesitas el color de fondo predeterminado para los comentarios, tal vez quieras reemplazarlo por un color de tu interés. ¿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 ejemplo para ti. Este archivo se usa para inicializar el objeto Workbook en el código a continuación.
const path = require("path");
const AsposeCells = require("aspose.cells.node");
// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
// Initialize a new workbook.
const workbook = new AsposeCells.Workbook(path.join(dataDir, "example.xlsx"));
// Accessing the newly added comment
const comment = workbook.getWorksheets().get(0).getComments().get(0);
// change background color
const shape = comment.getCommentShape();
shape.getFill().getSolidFill().setColor(AsposeCells.Color.Red);
// Save the Excel file
workbook.save(path.join(dataDir, "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 el aspecto 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 opción estética o usarse para reforzar la marca.
El código de ejemplo a continuación crea un archivo XLSX desde cero usando la API de Aspose.Cells, y agrega un comentario con fondo de imagen en la celda A1.
const AsposeCells = require("aspose.cells.node");
const path = require("path");
// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
// Instantiate a Workbook
const workbook = new AsposeCells.Workbook();
// Get a reference of comments collection with the first sheet
const comments = workbook.getWorksheets().get(0).getComments();
// Add a comment to cell A1
const commentIndex = comments.add(0, 0);
const comment = comments.get(commentIndex);
comment.setNote("First note.");
comment.getFont().setName("Times New Roman");
// Load an image into stream
const fs = require("fs");
const bmp = fs.readFileSync(path.join(dataDir, "image2.jpg"));
const ms = Buffer.from(bmp);
// Set image data to the shape associated with the comment
comment.getCommentShape().getFill().setImageData(ms);
// Save the workbook
const outputFilePath = path.join(dataDir, "commentwithpicture1.out.xlsx");
workbook.save(outputFilePath, AsposeCells.SaveFormat.Xlsx);