Hur man använder färgpaletten
Färger och Palett
En palett är antalet färger som är tillgängliga för att skapa en bild. Användningen av en standardiserad palett i en presentation gör att användaren kan skapa en enhetlig look. Varje Microsoft Excel (97-2003) fil har en palett med 56 färger som kan tillämpas på celler, teckensnitt, rutnät, grafiska objekt, fyllningar och linjer i en graf.
Med Aspose.Cells är det möjligt att inte bara använda palettens befintliga färger utan också anpassade färger. Innan du använder en anpassad färg, lägg till den först i paletten.
Detta ämne diskuterar hur man lägger till anpassade färger i paletten.
Lägg till anpassade färger i paletten
Aspose.Cells stöder Microsoft Excels 56-färgspalett. För att använda en anpassad färg som inte är definierad i paletten, lägg till färgen i paletten.
Aspose.Cells tillhandahåller en klass, Workbook, som representerar en Microsoft Excel-fil. Klassen Workbook tillhandahåller en ChangePalette-metod som tar följande parametrar för att lägga till en anpassad färg för att ändra paletten:
- Anpassad färg, den anpassade färgen som ska läggas till.
- Index, index för färgen i paletten som den anpassade färgen kommer att ersätta. Ska vara mellan 0-55.
Exemplet nedan lägger till en anpassad färg (Orchid) i paletten innan den tillämpas på en font.
// Instantiating an Workbook object | |
Workbook workbook = new Workbook(); | |
//Checks if a color is in the palette for the spreadsheet. | |
Console.WriteLine(workbook.IsColorInPalette(Color.Orchid)); | |
// Adding Orchid color to the palette at 55th index | |
workbook.ChangePalette(Color.Orchid, 55); | |
Console.WriteLine(workbook.IsColorInPalette(Color.Orchid)); | |
// Adding a new worksheet to the Excel object | |
int i = workbook.Worksheets.Add(); | |
// Obtaining the reference of the newly added worksheet by passing its sheet index | |
Worksheet worksheet = workbook.Worksheets[i]; | |
// Accessing the "A1" cell from the worksheet | |
Cell cell = worksheet.Cells["A1"]; | |
// Adding some value to the "A1" cell | |
cell.PutValue("Hello Aspose!"); | |
// Defining new Style object | |
Style styleObject = workbook.CreateStyle(); | |
// Setting the Orchid (custom) color to the font | |
styleObject.Font.Color = workbook.Colors[55]; | |
// Applying the style to the cell | |
cell.SetStyle(styleObject); | |
// Saving the Excel file | |
workbook.Save("out.xlsx"); |