Excel teman och färger
Hur man tillämpar och skapar färgschema i Excel
Dokumentteman gör det enkelt att koordinera färger, teckensnitt och grafisk formateringseffekter för Excel-dokument och uppdatera dem snabbt.
Teman ger ett enhetligt utseende med namngivna stilar, grafiska effekter och andra objekt som används i en arbetsbok. Till exempel ser Accent1-stilen olika ut i Office- och Apex-teman. Ofta tillämpar du ett dokumenttema och ändrar det sedan som du vill ha det.
Hur man tillämpar ett färgschema i Excel
- Öppna Excel och gå till fliken “Sidlayout” i Excel-ribbonen.
- Klicka på knappen “Färger” i avsnittet “Teman”.
- Välj en färgpalett som matchar dina krav eller sväva över en schema för att se en förhandsgranskning i realtid.
Hur man skapar en anpassad färgpalett i Excel
Du kan skapa din egen färguppsättning för att ge ditt dokument en fräsch, unik look eller följa din organisations varumärkesstandard.
-
Öppna Excel och gå till fliken “Sidlayout” i Excel-ribbonen.
-
Klicka på knappen “Färger” i avsnittet “Teman”.
-
Klicka på knappen “Anpassa färger…”.
-
I dialogrutan “Skapa nya temafärger” kan du välja färger för varje element genom att klicka på färgnedtagningarna bredvid dem. Du kan välja färger från paletten eller definiera anpassade färger med hjälp av alternativet “Fler färger”.
-
Efter att ha valt alla önskade färger, ange ett namn för din anpassade färgpalett i fältet “Namn”.
-
Klicka på knappen “Spara” för att spara din anpassade färgpalett. Din anpassade färgpalett kommer nu att finnas tillgänglig i rullgardinsmenyn “Färger” för framtida användning.
Hur man skapar och tillämpar färgpalett i Aspose.Cells
Aspose.Cells ger funktioner för anpassning av teman och färger.
Hur man skapar anpassat färgtema i Aspose.Cells
Om temafärger används i filen behöver vi inte ändra varje cell individuellt; vi behöver bara ändra färgerna i temat.
Nedan följer ett exempel på hur man tillämpar anpassade teman med önskade färger. Vi använder en provmall manuellt skapad i Microsoft Excel 2007.
Följande exempel laddar en mall XLSX-fil, definierar färger för olika temafärgtyper, tillämpar de anpassade färgerna och sparar Excel-filen.
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, "book1.xlsx"); | |
// Define Color array (of 12 colors) for Theme. | |
const carr = [ | |
new AsposeCells.Color("AntiqueWhite"), // Background1 | |
new AsposeCells.Color("Brown"), // Text1 | |
new AsposeCells.Color("AliceBlue"), // Background2 | |
new AsposeCells.Color("Yellow"), // Text2 | |
new AsposeCells.Color("YellowGreen"), // Accent1 | |
new AsposeCells.Color("Red"), // Accent2 | |
new AsposeCells.Color("Pink"), // Accent3 | |
new AsposeCells.Color("Purple"), // Accent4 | |
new AsposeCells.Color("PaleGreen"), // Accent5 | |
new AsposeCells.Color("Orange"), // Accent6 | |
new AsposeCells.Color("Green"), // Hyperlink | |
new AsposeCells.Color("Gray") // Followed Hyperlink | |
]; | |
// Instantiate a Workbook. | |
// Open the template file. | |
const workbook = new AsposeCells.Workbook(filePath); | |
// Set the custom theme with specified colors. | |
workbook.customTheme("CustomeTheme1", carr); | |
// Save as the excel file. | |
workbook.save(path.join(dataDir, "output.out.xlsx")); |
Hur man tillämpar temafärger i Aspose.Cells
Följande exempel tillämpar en cells förgrunds- och teckensfärger baserat på standardtema (arbetsbokens) färgtyper. Det sparar också Excel-filen till disk.
const path = require("path"); | |
const AsposeCells = require("aspose.cells.node"); | |
// The path to the documents directory. | |
const dataDir = path.join(__dirname, "data"); | |
// Create directory if it is not already present. | |
if (!require("fs").existsSync(dataDir)) { | |
require("fs").mkdirSync(dataDir); | |
} | |
// Instantiate a Workbook. | |
const workbook = new AsposeCells.Workbook(); | |
// Get cells collection in the first (default) worksheet. | |
const cells = workbook.getWorksheets().get(0).getCells(); | |
// Get the D3 cell. | |
const c = cells.get("D3"); | |
// Get the style of the cell. | |
const s = c.getStyle(); | |
// Set foreground color for the cell from the default theme Accent2 color. | |
s.setForegroundThemeColor(new AsposeCells.ThemeColor(AsposeCells.ThemeColorType.Accent2, 0.5)); | |
// Set the pattern type. | |
s.setPattern(AsposeCells.BackgroundType.Solid); | |
// Get the font for the style. | |
const f = s.getFont(); | |
// Set the theme color. | |
f.setThemeColor(new AsposeCells.ThemeColor(AsposeCells.ThemeColorType.Accent4, 0.1)); | |
// Apply style. | |
c.setStyle(s); | |
// Put a value. | |
c.putValue("Testing1"); | |
// Save the excel file. | |
workbook.save(path.join(dataDir, "output.out.xlsx")); |
Hur man får och ställer in temafärger i Aspose.Cells
Nedan följer några metoder och egenskaper som implementerar temafärger.
- Style.setForegroundThemeColor: Används för att sätta förgrundsfärgen.
- Style.setBackgroundThemeColor: Används för att sätta bakgrundsfärgen.
- Font.setThemeColor: Används för att sätta teckenfärgen.
- Workbook.getThemeColor: Används för att få en temafärg.
- Workbook.setThemeColor: Används för att sätta en temafärg.
Följande exempel visar hur man hämtar och ställer in tema färger.
Följande exempel använder en mall XLSX-fil, hämtar färger för olika temafärgtyper, ändrar färgerna och sparar Microsoft Excel-filen.
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, "book1.xlsx"); | |
// Instantiate Workbook object. | |
// Open an existing excel file. | |
const workbook = new AsposeCells.Workbook(filePath); | |
// Get the Background1 theme color. | |
let c = workbook.getThemeColor(AsposeCells.ThemeColorType.Background1); | |
// Print the color. | |
console.log("theme color Background1: ", c); | |
// Get the Accent2 theme color. | |
c = workbook.getThemeColor(AsposeCells.ThemeColorType.Accent2); | |
// Print the color. | |
console.log("theme color Accent2: ", c); | |
// Change the Background1 theme color. | |
workbook.setThemeColor(AsposeCells.ThemeColorType.Background1, AsposeCells.Color.Red); | |
// Get the updated Background1 theme color. | |
c = workbook.getThemeColor(AsposeCells.ThemeColorType.Background1); | |
// Print the updated color for confirmation. | |
console.log("theme color Background1 changed to: ", c); | |
// Change the Accent2 theme color. | |
workbook.setThemeColor(AsposeCells.ThemeColorType.Accent2, AsposeCells.Color.Blue); | |
// Get the updated Accent2 theme color. | |
c = workbook.getThemeColor(AsposeCells.ThemeColorType.Accent2); | |
// Print the updated color for confirmation. | |
console.log("theme color Accent2 changed to: ", c); | |
// Save the updated file. | |
workbook.save(path.join(dataDir, "output.out.xlsx")); |