Hur man ändrar bakgrund i kommentar i Excel
Hur man ändrar färg i kommentar i Excel
När du inte behöver standardbakgrundsfärg för kommentarer vill du kanske ersätta den med en färg som du är intresserad av. Hur ändrar jag bakgrundsfärgen på kommentarsrutan i Excel?
Följande kod kommer att guida dig hur du använder Aspose.Cells för att lägga till din favoritbakgrundsfärg till kommentarer efter eget val.
Här har vi förberett en provfil åt dig. Denna fil används för att initialisera arbetsboksobjektet i koden nedan.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string path = ""; | |
//Initialize a new workbook. | |
Workbook book = new Workbook(path + "exmaple.xlsx"); | |
// Accessing the newly added comment | |
Comment comment = book.Worksheets[0].Comments[0]; | |
// change background color | |
Shape shape = comment.CommentShape; | |
shape.Fill.SolidFill.Color = Color.Red; | |
// Save the Excel file | |
book.Save(path + "result.xlsx"); |
Kör ovanstående kod så får du en utdatafil.
Hur man infogar bild eller bild i kommentar i Excel
Microsoft Excel låter användare anpassa utseendet på kalkylblad i stor utsträckning. Det är till och med möjligt att lägga till bakgrundsbilder i kommentarer. Att lägga till en bakgrundsbild kan vara ett estetiskt val eller användas för att stärka varumärket.
Den provkod nedan skapar en XLSX-fil från grunden med Aspose.Cells-API och lägger till en kommentar med en bildbakgrund till cell A1.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = ""; | |
// Create directory if it is not already present. | |
bool IsExists = System.IO.Directory.Exists(dataDir); | |
if (!IsExists) | |
System.IO.Directory.CreateDirectory(dataDir); | |
// Instantiate a Workbook | |
Workbook workbook = new Workbook(); | |
// Get a reference of comments collection with the first sheet | |
CommentCollection comments = workbook.Worksheets[0].Comments; | |
// Add a comment to cell A1 | |
int commentIndex = comments.Add(0, 0); | |
Comment comment = comments[commentIndex]; | |
comment.Note = "First note."; | |
comment.Font.Name = "Times New Roman"; | |
// Load an image into stream | |
Bitmap bmp = new Bitmap(dataDir + "image2.jpg"); | |
MemoryStream ms = new MemoryStream(); | |
bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Png); | |
// Set image data to the shape associated with the comment | |
comment.CommentShape.Fill.ImageData = ms.ToArray(); | |
dataDir = dataDir + "commentwithpicture1.out.xlsx"; | |
// Save the workbook | |
workbook.Save(dataDir, Aspose.Cells.SaveFormat.Xlsx); |