Come Usare la Palette di Colori
Colori e Palette
Una palette è il numero di colori disponibili per creare un’immagine. L’uso di una palette standardizzata in una presentazione consente all’utente di creare un aspetto costante. Ogni file di Microsoft Excel (97-2003) ha una palette di 56 colori che possono essere applicati a celle, caratteri, linee guida, oggetti grafici, riempimenti e linee in un grafico.
Con Aspose.Cells for Node.js via C++, è possibile non solo usare i colori esistenti della palette, ma anche colori personalizzati. Prima di usare un colore personalizzato, aggiungilo alla palette.
Questo argomento tratta come aggiungere colori personalizzati alla palette.
Aggiungi Colori Personalizzati alla Palette
Aspose.Cells supporta la palette a 56 colori di Microsoft Excel. Per utilizzare un colore personalizzato non definito nella palette, aggiungi il colore alla palette.
Aspose.Cells fornisce una classe, Workbook, che rappresenta un file Microsoft Excel. La classe Workbook fornisce un metodo changePalette(Color, number) che accetta i seguenti parametri per aggiungere un colore personalizzato e modificare la palette:
- Colore personalizzato, il colore personalizzato da aggiungere.
- Indice, l’indice del colore nella palette che il colore personalizzato sostituirà. Dovrebbe essere compreso tra 0 e 55.
Nell’esempio seguente viene aggiunto un colore personalizzato (Orchidea) alla palette prima di applicarlo a un carattere.
const path = require("path"); | |
const AsposeCells = require("aspose.cells.node"); | |
// The path to the documents directory. | |
const dataDir = path.join(__dirname, "data"); | |
const filePath = path.join(dataDir, "sample.xlsx"); | |
// Loads the workbook which contains hidden external links | |
const workbook = new AsposeCells.Workbook(filePath); | |
// Checks if a color is in the palette for the spreadsheet. | |
console.log(workbook.isColorInPalette(AsposeCells.Color.Orchid)); | |
// Adding Orchid color to the palette at 55th index | |
workbook.changePalette(AsposeCells.Color.Orchid, 55); | |
console.log(workbook.isColorInPalette(AsposeCells.Color.Orchid)); | |
// Adding a new worksheet to the Excel object | |
const i = workbook.getWorksheets().add(); | |
// Obtaining the reference of the newly added worksheet by passing its sheet index | |
const worksheet = workbook.getWorksheets().get(i); | |
// Accessing the "A1" cell from the worksheet | |
const cell = worksheet.getCells().get("A1"); | |
// Adding some value to the "A1" cell | |
cell.putValue("Hello Aspose!"); | |
// Defining new Style object | |
const styleObject = workbook.createStyle(); | |
// Setting the Orchid (custom) color to the font | |
styleObject.getFont().setColor(workbook.getColors()[55]); | |
// Applying the style to the cell | |
cell.setStyle(styleObject); | |
// Saving the Excel file | |
workbook.save("out.xlsx"); |