Come cambiare lo sfondo nel commento in Excel
Come cambiare il colore nel commento in Excel
Quando non hai bisogno del colore di sfondo predefinito per i commenti, potresti voler sostituirlo con un colore di tuo interesse. Come cambio il colore di sfondo della casella Commenti in Excel?
Il codice seguente ti guiderà su come utilizzare Aspose.Cells per aggiungere il tuo colore di sfondo preferito ai commenti da scegliere.
Qui abbiamo preparato un file di esempio (exmaple.xlsx) per te. Questo file viene utilizzato per inizializzare l’oggetto Workbook nel codice sottostante.
// 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"); |
Esegui il codice sopra e otterrai un file di output (result.xlsx).
Come inserire un’immagine o una foto nel commento in Excel
Microsoft Excel consente agli utenti di personalizzare aspetto e sensazione dei fogli di calcolo in gran parte. È persino possibile aggiungere immagini di sfondo ai commenti. Aggiungere un’immagine di sfondo può essere una scelta estetica o essere utilizzata per rafforzare il marchio.
Il codice di esempio qui sotto crea un file XLSX da zero utilizzando l’API Aspose.Cells e aggiunge un commento con un’immagine di sfondo alla cella 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); |