Çalışma Sayfalarında Koşullu Biçimlendirme Uygula

Cell Değerine Göre Koşullu Biçimlendirmeyi Uygulamak için Aspose.Cells’i Kullanma

  1. İndirin ve yükleyin Aspose.Cells.
  2. İndir Aspose.Cells for .NET.
  3. Geliştirme bilgisayarınıza kurun. Tüm Aspose bileşenleri kurulduğunda değerlendirme modunda çalışır. Değerlendirme modunun zaman sınırı yoktur ve yalnızca üretilen belgelere filigran ekler.
  4. proje oluştur. Visual Studio.NET’i başlatın ve yeni bir konsol uygulaması oluşturun. Bu örnek, bir C# konsol uygulaması oluşturur, ancak VB.NET’i de kullanabilirsiniz.
  5. referans ekle. Projenize Aspose.Cells’e bir referans ekleyin, örneğin ….\Program Files\Aspose\Aspose.Cells\Bin\Net1.0\Aspose.Cells.dll’ye bir referans ekleyin
  6. *Hücre değerine göre koşullu biçimlendirme uygulayın. Görevi gerçekleştirmek için kullanılan kod aşağıdadır. Bir hücreye koşullu biçimlendirme uyguluyorum.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Create directory if it is not already present.
bool IsExists = System.IO.Directory.Exists(dataDir);
if (!IsExists)
System.IO.Directory.CreateDirectory(dataDir);
// Instantiating a Workbook object
Workbook workbook = new Workbook();
Worksheet sheet = workbook.Worksheets[0];
// Adds an empty conditional formatting
int index = sheet.ConditionalFormattings.Add();
FormatConditionCollection fcs = sheet.ConditionalFormattings[index];
// Sets the conditional format range.
CellArea ca = new CellArea();
ca.StartRow = 0;
ca.EndRow = 0;
ca.StartColumn = 0;
ca.EndColumn = 0;
fcs.AddArea(ca);
// Adds condition.
int conditionIndex = fcs.AddCondition(FormatConditionType.CellValue, OperatorType.Between, "50", "100");
// Sets the background color.
FormatCondition fc = fcs[conditionIndex];
fc.Style.BackgroundColor = Color.Red;
// Saving the Excel file
workbook.Save(dataDir+ "output.out.xls", SaveFormat.Auto);

Yukarıdaki kod yürütüldüğünde, çıktı dosyasının (output.xls) ilk çalışma sayfasındaki “A1” hücresine koşullu biçimlendirme uygulanır. A1’e uygulanan koşullu biçimlendirme, hücre değerine bağlıdır. A1’in hücre değeri 50 ile 100 arasındaysa, uygulanan koşullu biçimlendirme nedeniyle arka plan rengi kırmızıdır.

Formüle Dayalı Koşullu Biçimlendirmeyi Uygulamak için Aspose.Cells’i Kullanma

  1. Formüle bağlı olarak koşullu biçimlendirme uygulama (Kod Parçacığı) Görevi gerçekleştirmek için kod aşağıdadır. B3’te koşullu biçimlendirme uygular.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Create directory if it is not already present.
bool IsExists = System.IO.Directory.Exists(dataDir);
if (!IsExists)
System.IO.Directory.CreateDirectory(dataDir);
// Instantiating a Workbook object
Workbook workbook = new Workbook();
Worksheet sheet = workbook.Worksheets[0];
// Adds an empty conditional formatting
int index = sheet.ConditionalFormattings.Add();
FormatConditionCollection fcs = sheet.ConditionalFormattings[index];
// Sets the conditional format range.
CellArea ca = new CellArea();
ca = new CellArea();
ca.StartRow = 2;
ca.EndRow = 2;
ca.StartColumn = 1;
ca.EndColumn = 1;
fcs.AddArea(ca);
// Adds condition.
int conditionIndex = fcs.AddCondition(FormatConditionType.Expression);
// Sets the background color.
FormatCondition fc = fcs[conditionIndex];
fc.Formula1 = "=IF(SUM(B1:B2)>100,TRUE,FALSE)";
fc.Style.BackgroundColor = Color.Red;
sheet.Cells["B3"].Formula = "=SUM(B1:B2)";
sheet.Cells["C4"].PutValue("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 yürütüldüğünde, çıktı dosyasının (output.xls) ilk çalışma sayfasındaki “B3” hücresine koşullu biçimlendirme uygulanır. Uygulanan koşullu biçimlendirme, “B3” değerini B1 ve B2’nin toplamı olarak hesaplayan formüle bağlıdır.