Excel 主题和颜色

如何在Excel中应用和创建颜色方案

文档主题使得轻松协调Excel文档的颜色、字体和图形格式效果,并快速更新它们。 主题提供了具有命名样式、图形效果和工作簿中使用的其他对象的统一外观。例如,Accent1样式在Office和Apex主题中看起来不同。通常,您应用文档主题,然后修改它以满足您的要求。

如何在Excel中应用颜色方案

  1. 打开Excel,并转到Excel功能区的"页面布局"选项卡。
  2. 在"主题"部分的"颜色"按钮上单击。
  3. 选择与您的要求相匹配的调色板,或将鼠标悬停在一个方案上以查看实时预览。

如何在Excel中创建自定义颜色方案

您可以创建自己的颜色集,为您的文档带来新的、独特的外观,或者遵守您组织的品牌标准。

  1. 打开Excel,并转到Excel功能区的"页面布局"选项卡。

  2. 在"主题"部分的"颜色"按钮上单击。

  3. 单击"自定义颜色…" 按钮。

  4. 在"创建新主题颜色"对话框中,您可以通过单击旁边的颜色下拉菜单来选择每个元素的颜色。您可以从调色板中选择颜色,或者使用"更多颜色"选项定义自定义颜色。

  5. 在选择所有所需的颜色后,在“名称”字段中提供自定义颜色方案的名称。

  6. 点击“保存”按钮以保存您的自定义颜色方案。 您的自定义颜色方案现在将在“颜色”下拉菜单中可供将来使用。

如何在 Aspose.Cells for Python via .NET 中创建并应用色彩方案

Aspose.Cells for Python via .NET 提供自定义主题和颜色的功能。

在 Aspose.Cells for Python via .NET 中如何创建自定义色彩主题

如果文件中使用主题颜色,则我们无需逐个修改每个单元格,我们只需要修改主题中的颜色。

以下示例显示如何应用具有您所需颜色的自定义主题。 我们使用在Microsoft Excel 2007中手动创建的示例模板文件。

下面的示例加载一个模板XLSX文件,为不同的主题颜色类型定义颜色,应用自定义颜色并保存Excel文件。

from aspose.cells import Workbook,License,PdfSaveOptions, LoadOptions, LoadFormat, LoadFilter, LoadDataFilterOptions, PasteOptions,PasteType
from aspose.pydrawing import Color
# For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
# The path to the documents directory.
dataDir = RunExamples.GetDataDir(".")
# Instantiate Workbook object.
# Open an exiting excel file.
workbook = Workbook(dataDir + "book1.xlsx")
# Define Color array (of 12 colors) for Theme.
colors = []
colors.append(Color.from_argb(255, 250, 235, 215)) # Background1
colors.append(Color.from_argb(255, 165, 42, 42)) # Text1
colors.append(Color.from_argb(255, 240, 248, 255)) # Background2
colors.append(Color.from_argb(255, 255, 255, 0)) # Text2
colors.append(Color.from_argb(255, 154, 205, 50)) # Accent1
colors.append(Color.from_argb(255, 255, 0, 0)) # Accent2
colors.append(Color.from_argb(255, 255, 192, 203)) # Accent3
colors.append(Color.from_argb(255, 128, 0, 128)) # Accent4
colors.append(Color.from_argb(255, 152, 251, 152)) # Accent5
colors.append(Color.from_argb(255, 255, 165, 0)) # Accent6
colors.append(Color.from_argb(255, 0, 128, 0)) # Hyperlink
colors.append(Color.from_argb(255, 128, 128, 128)) # Followed Hyperlink
# Set the custom theme with specified colors.
workbook.custom_theme("CustomeTheme1", colors)
# Save as the excel file.
workbook.save(dataDir + "output.out.xlsx")

在 Aspose.Cells for Python via .NET 中如何应用主题颜色

下面的示例根据工作簿的默认主题颜色类型,应用单元格的前景色和字体颜色。它还将Excel文件保存到磁盘。

from aspose.cells import BackgroundType, ThemeColor, ThemeColorType, Workbook
from os import os, path
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# The path to the documents directory.
dataDir = RunExamples.GetDataDir(".")
# Create directory if it is not already present.
IsExists = path.isdir(dataDir)
if notIsExists:
os.makedirs(dataDir)
# Instantiate a Workbook.
workbook = Workbook()
# Get cells collection in the first (default) worksheet.
cells = workbook.worksheets[0].cells
# Get the D3 cell.
c = cells.get("D3")
# Get the style of the cell.
s = c.get_style()
# Set foreground color for the cell from the default theme Accent2 color.
s.foreground_theme_color = ThemeColor(ThemeColorType.ACCENT2, 0.5)
# Set the pattern type.
s.pattern = BackgroundType.SOLID
# Get the font for the style.
f = s.font
# Set the theme color.
f.theme_color = ThemeColor(ThemeColorType.ACCENT4, 0.1)
# Apply style.
c.set_style(s)
# Put a value.
c.put_value("Testing1")
# Save the excel file.
workbook.save(dataDir + "output.out.xlsx")

如何获取和设置 Aspose.Cells for Python via .NET 中的主题颜色

以下是实现主题颜色的几种方法和属性。

以下示例演示如何获取和设置主题颜色。

以下示例使用了一个模板 XLSX 文件,获取了不同主题颜色类型的颜色,更改了颜色,然后保存了 Microsoft Excel 文件。

from aspose.cells import ThemeColorType, Workbook
from aspose.pydrawing import Color
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# The path to the documents directory.
dataDir = RunExamples.GetDataDir(".")
# Instantiate Workbook object.
# Open an exiting excel file.
workbook = Workbook(dataDir + "book1.xlsx")
# Get the Background1 theme color.
c = workbook.get_theme_color(ThemeColorType.BACKGROUND1)
# Print the color.
print("theme color Background1: " + str(c))
# Get the Accent2 theme color.
c = workbook.get_theme_color(ThemeColorType.ACCENT2)
# Print the color.
print("theme color Accent2: " + str(c))
# Change the Background1 theme color.
workbook.set_theme_color(ThemeColorType.BACKGROUND1, Color.red)
# Get the updated Background1 theme color.
c = workbook.get_theme_color(ThemeColorType.BACKGROUND1)
# Print the updated color for confirmation.
print("theme color Background1 changed to: " + str(c))
# Change the Accent2 theme color.
workbook.set_theme_color(ThemeColorType.ACCENT2, Color.blue)
# Get the updated Accent2 theme color.
c = workbook.get_theme_color(ThemeColorType.ACCENT2)
# Print the updated color for confirmation.
print("theme color Accent2 changed to: " + str(c))
# Save the updated file.
workbook.save(dataDir + "output.out.xlsx")

高级主题