Comment changer l'arrière-plan d'un commentaire dans Excel
Comment changer la couleur d’un commentaire dans Excel
Lorsque vous n’avez pas besoin de la couleur d’arrière-plan par défaut pour les commentaires, vous pouvez la remplacer par une couleur qui vous intéresse. Comment modifier la couleur d’arrière-plan de la zone Commentaires dans Excel ?
Le code suivant vous guidera dans l’utilisationAspose.Cells pour ajouter votre couleur d’arrière-plan préférée aux commentaires de votre choix.
Ici, nous avons préparé unexemple de fichier pour vous. Ce fichier est utilisé pour initialiser l’objet Workbook dans le code ci-dessous.
// 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"); |
Exécutez le code ci-dessus et vous obtiendrez unfichier de sortie.
Comment insérer une image ou une image dans un commentaire dans Excel
Microsoft Excel permet aux utilisateurs de personnaliser dans une large mesure l’apparence des feuilles de calcul. Il est même possible d’ajouter des images d’arrière-plan aux commentaires. L’ajout d’une image d’arrière-plan peut être un choix esthétique ou être utilisé pour renforcer l’image de marque.
L’exemple de code ci-dessous crée un fichier XLSX à partir de zéro en utilisantAspose.Cells API et ajoute un commentaire avec une image d’arrière-plan à la cellule 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); |