Doldurma Ayarları

Renkler ve Arka Plan Desenleri

Microsoft Excel, hücrelerin ön plan (çerçeve) ve arka plan (doldurma) renklerini ve arka plan desenlerini ayarlayabilir.

Aspose.Cells for Python via .NET, bu özellikleri esnek bir biçimde destekler. Bu konuda, bu özellikleri Aspose.Cells kullanarak nasıl kullanacağınızı öğreneceğiz.

Renkler ve Arka Plan Desenlerini Ayarlama

Aspose.Cells for Python via .NET, Microsoft Excel dosyasını temsil eden Workbook adlı bir sınıf sağlar. Workbook sınıfı, Excel dosyasındaki her çalışma sayfasına erişim sağlayan bir worksheets koleksiyonu içerir. Bir çalışma sayfası, Worksheet sınıfı ile temsil edilir. Worksheet sınıfı, bir Cells koleksiyonu sağlar. Cells koleksiyonundaki her öğe, bir Cell sınıfı nesnesini temsil eder.

Cell sınıfı, get_style ve set_style yöntemlerine sahiptir; bunlar, bir hücrenin biçimlendirmesini almak ve ayarlamak için kullanılır. Style sınıfı, hücrelerin ön plan ve arka plan renklerini ayarlamak için özellikler sağlar. Aspose.Cells for Python via .NET, aşağıda listelenen önceden tanımlı arka plan desenleri seti içeren BackgroundType adında bir enumerasyon sağlar.

Arka Plan Desenleri Açıklama
DIAGONAL_CROSSHATCH Diagonal çapraz çizgili deseni temsil eder
DIAGONAL_STRIPE Diagonal çizgi deseni temsil eder
GRAY6 %6,25 gri deseni temsil eder
GRAY12 %12,5 gri deseni temsil eder
GRAY25 %25 gri deseni temsil eder
GRAY50 %50 gri deseni temsil eder
GRAY75 %75 gri deseni temsil eder
YATAY ÇİZGİ Yatay şerit desenini temsil eder
YOK Arka plan yok
TERS DİKİŞLİ ÇİZGİ Ters çapraz çizgi desenini temsil eder
DÜZ Katı desenleri temsil eder
KOYUŞA DİKİŞLİ ÇİZGİ Kalın çapraz dikiş deseni
İnce DİKİŞLİ ÇİZGİ İnce çapraz dikiş deseni
İNCE DİKİŞLİ ÇİZGİ İnce çapraz şerit deseni
İnce YATAY ÇAPRAZ İnce yatay çapraz desen
İnce YATAY ÇİZGİ İnce yatay şerit deseni
İnce TERS DİKİŞLİ ÇİZGİ İnce ters çapraz şerit deseni
İnce DİKEN İnce dikey çizgi deseni
DÜZ DİZİ Dikey şerit deseni

Aşağıdaki örnekte, A1 hücresinin ön plan rengi ayarlanmış ancak A2, dikey çizgili bir arka plan deseni olan hem ön plan rengi hem de arka plan rengi olarak yapılandırılmıştır.

from aspose.cells import BackgroundType, SaveFormat, Workbook
from aspose.pydrawing import Color
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)
# Instantiating a Workbook object
workbook = Workbook()
# Adding a new worksheet to the Workbook object
i = workbook.worksheets.add()
# Obtaining the reference of the newly added worksheet by passing its sheet index
worksheet = workbook.worksheets[i]
# Define a Style and get the A1 cell style
style = worksheet.cells.get("A1").get_style()
# Setting the foreground color to yellow
style.foreground_color = Color.yellow
# Setting the background pattern to vertical stripe
style.pattern = BackgroundType.VERTICAL_STRIPE
# Apply the style to A1 cell
worksheet.cells.get("A1").set_style(style)
# Get the A2 cell style
style = worksheet.cells.get("A2").get_style()
# Setting the foreground color to blue
style.foreground_color = Color.blue
# Setting the background color to yellow
style.background_color = Color.yellow
# Setting the background pattern to vertical stripe
style.pattern = BackgroundType.VERTICAL_STRIPE
# Apply the style to A2 cell
worksheet.cells.get("A2").set_style(style)
# Saving the Excel file
workbook.save(dataDir + "book1.out.xls", SaveFormat.EXCEL_97_TO_2003)

Bilinmesi Gerekenler

Gradyan Dolgu Efektleri Uygulama

Hücreye istenilen Gradyan Dolgu Efektlerini uygulamak için, Style nesnesinin set_two_color_gradient metodunu kullanın.

from aspose.cells import TextAlignmentType, Workbook
from aspose.cells.drawing import GradientStyleType
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 a new Workbook
workbook = Workbook()
# Get the first worksheet (default) in the workbook
worksheet = workbook.worksheets[0]
# Input a value into B3 cell
worksheet.cells.get(2, 1).put_value("test")
# Get the Style of the cell
style = worksheet.cells.get("B3").get_style()
# Set Gradient pattern on
style.is_gradient = True
# Specify two color gradient fill effects
style.set_two_color_gradient(Color.from_argb(255, 255, 255), Color.from_argb(79, 129, 189), GradientStyleType.HORIZONTAL, 1)
# Set the color of the text in the cell
style.font.color = Color.red
# Specify horizontal and vertical alignment settings
style.horizontal_alignment = TextAlignmentType.CENTER
style.vertical_alignment = TextAlignmentType.CENTER
# Apply the style to the cell
worksheet.cells.get("B3").set_style(style)
# Set the third row height in pixels
worksheet.cells.set_row_height_pixel(2, 53)
# Merge the range of cells (B3:C3)
worksheet.cells.merge(2, 1, 1, 2)
# Save the Excel file
workbook.save(dataDir + "output.xlsx")

Renkler ve Palet

Bir palet, bir görüntü oluşturmak için kullanılabilen renk sayısıdır. Bir sunumda standart bir palet kullanımı, kullanıcının tutarlı bir görünüm oluşturmasına olanak tanır. Her Microsoft Excel (97-2003) dosyasının bir hücrelere, fontlara, ızgaralara, grafik nesnelerine, doldurmalara ve çizgilere uygulanabilen 56 renklik bir paleti vardır.

Aspose.Cells for Python via .NET ile mevcut paletin renkleri kullanılabildiği gibi, özel renkler de kullanılabilir. Bir özel renk kullanmadan önce onu palete ekleyin.

Bu konu, paletine özel renkler eklemenin nasıl yapıldığını tartışmaktadır.

Paletine Özel Renkler Eklemek

Aspose.Cells for Python via .NET, Microsoft Excel’in 56 renk paletini destekler. Paletede tanımlı olmayan bir özel renk kullanmak için, renk paletine ekleyin.

Aspose.Cells for Python via .NET, bir Microsoft Excel dosyasını temsil eden {0} adında bir sınıf sağlar. {1} sınıfı, bir Excel dosyasındaki her çalışma sayfasına erişim sağlayan {2} koleksiyonunu içerir. Bir çalışma sayfası, {3} sınıfı ile temsil edilir. {4} sınıfı ise bir {5} koleksiyonu sağlar. {6} koleksiyondaki her öğe, bir {7} sınıfı nesnesini temsil eder.

  • Özel Renk, paletine eklenecek özel renk.
  • İndeks, özel rengin paletindeki rengin yerini belirtir. 0-55 arasında olmalıdır.

Aşağıdaki örnek, (Orkide) özel bir rengi paletine ekleyip bunu bir font üzerine uygulamadan önce paletine ekler.

from aspose.cells import SaveFormat, Workbook
from aspose.pydrawing import Color
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)
# Instantiating an Workbook object
workbook = Workbook()
# Adding Orchid color to the palette at 55th index
workbook.change_palette(Color.orchid, 55)
# Adding a new worksheet to the Excel object
i = workbook.worksheets.add()
# Obtaining the reference of the newly added worksheet by passing its sheet index
worksheet = workbook.worksheets[i]
# Accessing the "A1" cell from the worksheet
cell = worksheet.cells.get("A1")
# Adding some value to the "A1" cell
cell.put_value("Hello Aspose!")
# Defining new Style object
styleObject = workbook.create_style()
# Setting the Orchid (custom) color to the font
styleObject.font.color = Color.orchid
# Applying the style to the cell
cell.set_style(styleObject)
# Saving the Excel file
workbook.save(dataDir + "book1.out.xls", SaveFormat.AUTO)