Comment changer l arrière plan d un commentaire dans Excel avec C++
Comment changer la couleur dans le commentaire dans Excel
Lorsque vous n’avez pas besoin de la couleur de fond par défaut pour les commentaires, vous pouvez la remplacer par une couleur qui vous intéresse. Comment puis-je changer la couleur de l’arrière-plan de la boîte de commentaires dans Excel ?
Le code suivant vous guidera sur la façon d’utiliser Aspose.Cells pour ajouter votre couleur d’arrière-plan préférée aux commentaires de votre choix.
Voici un fichier d’exemple préparé pour vous. Ce fichier sert à initialiser l’objet Workbook dans le code ci-dessous.
#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;
int main()
{
Aspose::Cells::Startup();
U16String srcDir(u"..\\Data\\01_SourceDirectory\\");
U16String outDir(u"..\\Data\\02_OutputDirectory\\");
U16String inputPath = srcDir + u"exmaple.xlsx";
Workbook book(inputPath);
Worksheet worksheet = book.GetWorksheets().Get(0);
Comment comment = worksheet.GetComments().Get(0);
CommentShape shape = comment.GetCommentShape();
shape.GetFill().GetSolidFill().SetColor(Color::Red());
U16String outputPath = outDir + u"result.xlsx";
book.Save(outputPath);
std::cout << "Comment color changed successfully." << std::endl;
Aspose::Cells::Cleanup();
return 0;
}
Exécutez le code ci-dessus, et vous obtiendrez un fichier de sortie.
Comment insérer une image ou une photo dans le commentaire dans Excel
Microsoft Excel permet aux utilisateurs de personnaliser considérablement l’apparence des feuilles de calcul. Il est même possible d’ajouter des images de fond aux commentaires. L’ajout d’une image d’arrière-plan peut être un choix esthétique ou utilisé pour renforcer la marque.
Le code d’exemple ci-dessous crée un fichier XLSX à partir de zéro en utilisant l’API Aspose.Cells, et ajoute un commentaire avec une image d’arrière-plan à la cellule A1.
#include <iostream>
#include "Aspose.Cells.h"
#include <vector>
#include <cstdint>
using namespace Aspose::Cells;
using namespace Aspose::Cells::Drawing;
int main()
{
Aspose::Cells::Startup();
// Source directory path
U16String srcDir(u"..\\Data\\01_SourceDirectory\\");
// Output directory path
U16String outDir(u"..\\Data\\02_OutputDirectory\\");
// Instantiate a Workbook
Workbook workbook;
// Get a reference of comments collection with the first sheet
WorksheetCollection worksheets = workbook.GetWorksheets();
Worksheet worksheet = worksheets.Get(0);
CommentCollection comments = worksheet.GetComments();
// Add a comment to cell A1
int32_t commentIndex = comments.Add(0, 0);
Comment comment = comments.Get(commentIndex);
comment.SetNote(u"First note.");
Font font = comment.GetFont();
font.SetName(u"Times New Roman");
// Load an image into stream
U16String imagePath = srcDir + u"image2.jpg";
std::vector<uint8_t> imageData;
// Assume image loading logic here
// For simplicity, we assume imageData is populated with the image bytes
// Set image data to the shape associated with the comment
CommentShape commentShape = comment.GetCommentShape();
commentShape.GetFill().SetImageData(Aspose::Cells::Vector<uint8_t>(imageData.data(), imageData.size()));
// Save the workbook
U16String outputPath = outDir + u"commentwithpicture1.out.xlsx";
workbook.Save(outputPath, SaveFormat::Xlsx);
std::cout << "Workbook saved successfully with comment and image!" << std::endl;
Aspose::Cells::Cleanup();
}