Çalışma Kitaplarında Koşullu Biçimlendirme Uygulama

Hücre Değerine Bağlı Olarak Koşullu Biçimlendirme Uygulamak İçin Aspose.Cells Kullanma

  1. Aspose.Cells’ı İndirin ve Kurun.
    1. Aspose.Cells for Python via .NET’i indirin.
  2. Geliştirme bilgisayarınıza kurun. Kurulduğunda, tüm Aspose bileşenleri değerlendirme modunda çalışır. Değerlendirme modunun süresiz bir sınırlaması yoktur ve yalnızca üretilen belgelere filigran enjekte eder.
  3. Bir proje oluşturun. Visual Studio.NET’i başlatın ve yeni bir konsol uygulaması oluşturun. Bu örnek bir Python konsol uygulaması oluşturur, ancak VB.NET de kullanabilirsiniz.
  4. Referanslar Ekleyin. Projenize Aspose.Cells referansı ekleyin.
  5. *Hücre Değerine Bağlı Olarak Koşullu Biçimlendirme Uygulayın. Aşağıda verilen kod, görevi gerçekleştirmek için kullanılan koddur. Bir hücreye koşullu biçimlendirme uygularım.
from aspose.cells import CellArea, FormatConditionType, OperatorType, 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()
sheet = workbook.worksheets[0]
# Adds an empty conditional formatting
index = sheet.conditional_formattings.add()
fcs = sheet.conditional_formattings[index]
# Sets the conditional format range.
ca = CellArea()
ca.start_row = 0
ca.end_row = 0
ca.start_column = 0
ca.end_column = 0
fcs.add_area(ca)
# Adds condition.
conditionIndex = fcs.add_condition(FormatConditionType.CELL_VALUE, OperatorType.BETWEEN, "50", "100")
# Sets the background color.
fc = fcs[conditionIndex]
fc.style.background_color = Color.red
# Saving the Excel file
workbook.save(dataDir + "output.out.xls", SaveFormat.AUTO)

Yukarıdaki kod çalıştırıldığında, koşullu biçimlendirme çıktı dosyasının ilk çalışsayfasındaki “A1” hücresine uygulanır (çıktı.xls). A1 hücresinin değerine bağlı olarak uygulanan koşullu biçimlendirme. Eğer A1’in değeri 50 ile 100 arasında ise, arka plan rengi koşullu biçimlendirme nedeniyle kırmızı olur.

Aspose.Cells Kullanarak Formül Değerine Bağlı Olarak Koşullu Biçimlendirme Uygulama

  1. Formül Uygun Olarak Koşullu Biçimlendirme Uygulama (Kod Parçası) Aşağıda verilen kod, görevi gerçekleştirmek için kullanılan koddur. B3’e koşullu biçimlendirme uygular.
from aspose.cells import CellArea, FormatConditionType, 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()
sheet = workbook.worksheets[0]
# Adds an empty conditional formatting
index = sheet.conditional_formattings.add()
fcs = sheet.conditional_formattings[index]
# Sets the conditional format range.
ca = CellArea()
ca = CellArea()
ca.start_row = 2
ca.end_row = 2
ca.start_column = 1
ca.end_column = 1
fcs.add_area(ca)
# Adds condition.
conditionIndex = fcs.add_condition(FormatConditionType.EXPRESSION)
# Sets the background color.
fc = fcs[conditionIndex]
fc.formula1 = "=IF(SUM(B1:B2)>100,TRUE,FALSE)"
fc.style.background_color = Color.red
sheet.cells.get("B3").formula = "=SUM(B1:B2)"
sheet.cells.get("C4").put_value("If Sum of B1:B2 is greater than 100, B3 will have RED background")
# Saving the Excel file
workbook.save(dataDir + "output.out.xls", SaveFormat.AUTO)

Yukarıdaki kod çalıştırıldığında, koşullu biçimlendirme çıktı dosyasının ilk çalışsayfasındaki “B3” hücresine uygulanır (çıktı.xls). Uygulanan koşullu biçimlendirme, “B1” ve “B2”nin değerinin toplamını hesaplayan formülün sonucuna bağlıdır.