Темы и цвета Excel

Как применить и создать цветовую схему в Excel

Темы документов позволяют легко координировать цвета, шрифты и графические эффекты форматирования документов Excel и быстро обновлять их. Темы предоставляют единообразный вид с именованными стилями, графическими эффектами и другими объектами, используемыми в рабочей книге. Например, стиль Accent1 в темах Office и Apex выглядит по-разному. Часто вы применяете тему документа, а затем изменяете ее в соответствии с вашими запросами.

Как применить цветовую схему в Excel

  1. Откройте Excel и перейдите на вкладку “Разметка страницы” на ленте Excel.
  2. Нажмите кнопку “Цвета” в разделе “Темы”.
  3. Выберите цветовую палитру, которая соответствует вашим требованиям, или наведите курсор на схему, чтобы увидеть предварительный просмотр.

Как создать пользовательскую цветовую схему в Excel

Вы можете создать собственный набор цветов, чтобы придать вашему документу свежий, уникальный вид или соответствовать корпоративному стилю вашей организации.

  1. Откройте Excel и перейдите на вкладку “Разметка страницы” на ленте Excel.

  2. Нажмите кнопку “Цвета” в разделе “Темы”.

  3. Нажмите кнопку “Настроить цвета…”.

  4. В диалоговом окне “Создание новых тем цветов” вы можете выбрать цвета для каждого элемента, нажав на выпадающие списки цветов рядом с ними. Вы можете выбрать цвета из палитры или определить пользовательские цвета, используя опцию “Другие цвета”.

  5. После выбора всех желаемых цветов укажите имя для вашей пользовательской цветовой схемы в поле “Имя”.

  6. Нажмите кнопку “Сохранить”, чтобы сохранить вашу пользовательскую цветовую схему. Ваша пользовательская цветовая схема теперь будет доступна в раскрывающемся меню “Цвета” для последующего использования.

Как создать и применить цветовую схему в Aspose.Cells для Python via .NET

Aspose.Cells для Python via .NET предоставляет возможности настройки тем и цветов.

Как создать пользовательскую цветовую тему в Aspose.Cells для 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 для 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 для 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")

Продвинутые темы