Metin Koşullu Biçimlendirme nasıl eklenir

Olası Kullanım Senaryoları

Elektronik tablolarında metne dayalı koşullu biçimlendirme kullanmak, belirli çıkış kriterlerini karşılayan hücreleri vurgulamak için faydalıdır. Bu, veri analizini geliştirebilir ve büyük bir veri kümesinde önemli bilgileri bulmayı kolaylaştırabilir. İşte metin koşullu biçimlendirme kullanmanın bazı nedenleri:

Özel Metinleri Vurgula: Belirli kelime, ifadeler veya karakterlere bağlı biçimlendirme uygulayabilirsiniz. Örneğin, “Acil” veya “Tamamlandı” içeren tüm hücreleri vurgulamak, projedeki görevleri kolayca ayırt etmenize yardımcı olabilir. Desenleri veya Eğilimleri Tanımlayın: “Yüksek”, “Orta”, “Düşük” gibi kategoriler veya durumlar ile çalışıyorsanız, metne dayalı koşullu biçimlendirme bunları görsel olarak ayırt edebilir, böylece ilerlemeyi takip etmek veya görevleri önceliklendirmek daha kolay olur. Hata veya Veri Girşi Uyarıları: Metin biçimlendirme tutarsız veya hatalı girişleri, yanlış yazılmış kelimeleri, eksik metinleri veya yanlış değerleri işaretleyebilir. Bu, çok sayıda metinsel giriş içeren veri kümelerinde özellikle faydalıdır. Gelişmiş Okunabilirlik: Metne renk kodu uygulamak veya stilini değiştirmek ( kalın, italik vb.), önemli bilgilerin öne çıkmasını sağlar ve belgeyi genel olarak daha okunabilir hale getirir. Dinamik Geri Bildirim: Metin belirli koşulları karşıladığında otomatik olarak biçimlendirmeyi ayarlayan kurallar kurabilirsiniz. Bu, veriler değiştikçe biçimlendirmeyi manuel olarak güncellemenize gerek kalmaz.

Özetle, metin koşullu biçimlendirme, ilgili bilgileri, hataları ve trendleri hızlıca fark etmenize yardımcı olur ve metinsel verilerin yönetim ve yorumlanmasında güçlü bir araçtır.

Excel Kullanarak Metin Koşullu Biçimlendirme Nasıl Eklenir

Excel’de metne dayalı koşullu biçimlendirme eklemek için şu adımları izleyin:

Hücre Aralığını Seçin: Koşullu biçimlendirmeyi uygulamak istediğiniz hücreleri vurgulayın. Koşullu Biçimlendirme Menüsünü Açın: Excel şeridindeki Anahtar sekmesine gidin. “Stiller” grubunda Koşullu Biçimlendirme’ye tıklayın. Yeni Kural Seçin: Açılır menüden Yeni Kural’ı seçin. “Sadece hücreleri biçimlendir” seçeneğini seçin: Yeni Biçimlendirme Kuralı iletişim kutusunda, “Bir Kural Türü Seçin” bölümünde “Sadece hücreleri biçimlendir"yi seçin. Kural Kriterlerini Belirleyin: “Hücreleri biçimlendir” bölümünde, açılır menüden Belirli Metin’i seçin. Koşula göre içeren, başlar veya biter seçin. Biçimlendirmek istediğiniz metni girin (örneğin, “Acil” veya “Tamamlandı”). Biçimlendirmeyi Seçin: Biçim düğmesine tıklayın. Hücreleri Biçimlendir iletişim kutusunda, yazı tipi rengi, dolgu rengi veya diğer biçimlendirme seçeneklerini seçebilirsiniz. Kuralı Uygula: İstediğiniz biçimi belirledikten sonra, Kuralı uygula’ya tıklayın. Yeni Biçimlendirme Kuralı iletişim kutusunda tekrar Tamam’a tıklayarak kapatın. Sonuçları Görüntüle: Belirttiğiniz metni içeren hücreler artık biçimlendirilmiş olacak, bu da ilgili bilgileri kolayca görmenizi sağlar.

Aspose.Cells for .NET kullanarak Metin Koşullu Biçimlendirme Nasıl Eklenir

Aspose.Cells, Microsoft Excel 2007 ve sonrası sürümler tarafından sağlanan koşullu biçimlendirmeyi çalışma zamanında hücrelerde XLSX formatında tam destekler. Bu örnekler, BeginsWith, ContainsBlank, ContainsText gibi gelişmiş koşullu biçimlendirme türleri için bir egzersiz göstermektedir.

Değer Belirtilen Metinle Başladığında Hücreyi Biçimlendir

// This method implements the BeginsWith conditional formatting type.
private void AddBeginWith()
{
// Instantiate a workbook object
Workbook book = new Workbook();
// Create a worksheet object and get the first worksheet
Worksheet _sheet = book.Worksheets[0];
FormatConditionCollection conds = GetFormatCondition("E15:G16", Color.LightGoldenrodYellow, _sheet);
int idx = conds.AddCondition(FormatConditionType.BeginsWith);
FormatCondition cond = conds[idx];
cond.Style.BackgroundColor = Color.Pink;
cond.Style.Pattern = BackgroundType.Solid;
cond.Text = "ab";
Cell c = _sheet.Cells["E15"];
c.PutValue("abc");
c = _sheet.Cells["G16"];
c.PutValue("babx");
book.Save("BeginsWith.xlsx");
}
// This method adds formatted conditions.
private FormatConditionCollection GetFormatCondition(string cellAreaName, Color color, Worksheet _sheet)
{
// Adds an empty conditional formattings
int index = _sheet.ConditionalFormattings.Add();
// Get the formatted conditions
FormatConditionCollection formatConditions = _sheet.ConditionalFormattings[index];
// Get the cell area calling the custom GetCellAreaByName method
CellArea area = GetCellAreaByName(cellAreaName);
// Add the formatted conditions cell area.
formatConditions.AddArea(area);
// Call the custom FillCell method
FillCell(cellAreaName, color, _sheet);
// Return the formatted conditions
return formatConditions;
}
// This method specifies the cell shading color for the conditional formattings cellarea range.
private void FillCell(string cellAreaName, Color color, Worksheet _sheet)
{
CellArea area = GetCellAreaByName(cellAreaName);
int k = 0;
for (int i = area.StartColumn; i <= area.EndColumn; i++)
{
for (int j = area.StartRow; j <= area.EndRow; j++)
{
Cell c = _sheet.Cells[j, i];
if (!color.IsEmpty)
{
Style s = c.GetStyle();
s.ForegroundColor = color;
s.Pattern = BackgroundType.Solid;
c.SetStyle(s);
}
// Set some random values to the cells in the cellarea range
int value = j + i + k;
c.PutValue(value);
k++;
}
}
}
// This method specifies the CellArea range (start row, start col, end row, end col etc.)
// For the conditional formatting
internal static CellArea GetCellAreaByName(string s)
{
CellArea area = new CellArea();
string[] strCellRange = s.Replace("$", "").Split(':');
int column;
CellsHelper.CellNameToIndex(strCellRange[0], out area.StartRow, out column);
area.StartColumn = column;
if (strCellRange.Length == 1)
{
area.EndRow = area.StartRow;
area.EndColumn = area.StartColumn;
}
else
{
CellsHelper.CellNameToIndex(strCellRange[1], out area.EndRow, out column);
area.EndColumn = column;
}
return area;
}

Değer Boşsa Hücreyi Biçimlendir

// This method implements the ContainsBlank conditional formatting type.
private void AddContainsBlank()
{
// Instantiate a workbook object
Workbook book = new Workbook();
// Create a worksheet object and get the first worksheet
Worksheet _sheet = book.Worksheets[0];
FormatConditionCollection conds = GetFormatCondition("E9:G10", Color.LightBlue, _sheet);
int idx = conds.AddCondition(FormatConditionType.ContainsBlanks);
FormatCondition cond = conds[idx];
cond.Style.BackgroundColor = Color.Yellow;
cond.Style.Pattern = BackgroundType.Solid;
Cell c = _sheet.Cells["E9"];
c.PutValue(" ");
c = _sheet.Cells["G10"];
c.PutValue(" ");
book.Save("ContainsBlank.xlsx");
}

Hata İçeriyorsa Hücreyi Biçimlendir

// This method implements the ContainsErrors conditional formatting type.
private void AddContainsErrors()
{
// Instantiate a workbook object
Workbook book = new Workbook();
// Create a worksheet object and get the first worksheet
Worksheet _sheet = book.Worksheets[0];
FormatConditionCollection conds = GetFormatCondition("E17:G18", Color.LightSkyBlue, _sheet);
int idx = conds.AddCondition(FormatConditionType.ContainsErrors);
FormatCondition cond = conds[idx];
cond.Style.BackgroundColor = Color.Yellow;
cond.Style.Pattern = BackgroundType.Solid;
Cell c = _sheet.Cells["E17"];
c.PutValue(" ");
c = _sheet.Cells["G18"];
c.PutValue(" ");
book.Save("ContainsErrors.xlsx");
}

Belirtilen Metni İçeriyorsa Hücreyi Biçimlendir

// This method implements the ContainsText conditional formatting type.
private void AddContainsText()
{
// Instantiate a workbook object
Workbook book = new Workbook();
// Create a worksheet object and get the first worksheet
Worksheet _sheet = book.Worksheets[0];
FormatConditionCollection conds = GetFormatCondition("E5:G6", Color.LightBlue, _sheet);
int idx = conds.AddCondition(FormatConditionType.ContainsText);
FormatCondition cond = conds[idx];
cond.Style.BackgroundColor = Color.Yellow;
cond.Style.Pattern = BackgroundType.Solid;
cond.Text = "1";
book.Save("ContainsText.xlsx");
}

Tekrarlayan Değerleri İçeriyorsa Hücreyi Biçimlendir

// This method implements the DuplicateValues conditional formatting type.
private void AddDuplicateValues()
{
// Instantiate a workbook object
Workbook book = new Workbook();
// Create a worksheet object and get the first worksheet
Worksheet _sheet = book.Worksheets[0];
FormatConditionCollection conds = GetFormatCondition("E23:G24", Color.LightSlateGray, _sheet);
int idx = conds.AddCondition(FormatConditionType.DuplicateValues);
FormatCondition cond = conds[idx];
cond.Style.BackgroundColor = Color.Pink;
cond.Style.Pattern = BackgroundType.Solid;
Cell c = _sheet.Cells["E23"];
c.PutValue("bb");
c = _sheet.Cells["G24"];
c.PutValue("bb");
book.Save("DuplicateValues.xlsx");
}

Belirtilen Metinle Biten Değeri İçeriyorsa Hücreyi Biçimlendir

// This method implements the EndsWith conditional formatting type.
private void AddEndWith()
{
// Instantiate a workbook object
Workbook book = new Workbook();
// Create a worksheet object and get the first worksheet
Worksheet _sheet = book.Worksheets[0];
FormatConditionCollection conds = GetFormatCondition("E13:G14", Color.LightGray, _sheet);
int idx = conds.AddCondition(FormatConditionType.EndsWith);
FormatCondition cond = conds[idx];
cond.Style.BackgroundColor = Color.Yellow;
cond.Style.Pattern = BackgroundType.Solid;
cond.Text = "ab";
Cell c = _sheet.Cells["E13"];
c.PutValue("nnnab");
c = _sheet.Cells["G14"];
c.PutValue("mmmabc");
book.Save("EndsWith.xlsx");
}

Değer Boş Değilse Hücreyi Biçimlendir

// This method implements the NotContainsBlank conditional formatting type.
private void AddNotContainsBlank()
{
// Instantiate a workbook object
Workbook book = new Workbook();
// Create a worksheet object and get the first worksheet
Worksheet _sheet = book.Worksheets[0];
FormatConditionCollection conds = GetFormatCondition("E11:G12", Color.LightCoral, _sheet);
int idx = conds.AddCondition(FormatConditionType.NotContainsBlanks);
FormatCondition cond = conds[idx];
cond.Style.BackgroundColor = Color.Pink;
cond.Style.Pattern = BackgroundType.Solid;
Cell c = _sheet.Cells["E11"];
c.PutValue("abc");
c = _sheet.Cells["G12"];
c.PutValue(" ");
book.Save("NotContainsBlank.xlsx");
}

Hata İçermiyorsa Hücreyi Biçimlendir

// This method implements the NotContainsErrors conditional formatting type.
private void AddNotContainsErrors()
{
// Instantiate a workbook object
Workbook book = new Workbook();
// Create a worksheet object and get the first worksheet
Worksheet _sheet = book.Worksheets[0];
FormatConditionCollection conds = GetFormatCondition("E19:G20", Color.LightSeaGreen, _sheet);
int idx = conds.AddCondition(FormatConditionType.NotContainsErrors);
FormatCondition cond = conds[idx];
cond.Style.BackgroundColor = Color.Pink;
cond.Style.Pattern = BackgroundType.Solid;
Cell c = _sheet.Cells["E19"];
c.PutValue(" ");
c = _sheet.Cells["G20"];
c.PutValue(" ");
book.Save("NotContainsErrors.xlsx");
}

Belirtilen Metni İçermiyorsa Hücreyi Biçimlendir

// This method implements the NotContainsText conditional formatting type.
private void AddNotContainsText()
{
// Instantiate a workbook object
Workbook book = new Workbook();
// Create a worksheet object and get the first worksheet
Worksheet _sheet = book.Worksheets[0];
FormatConditionCollection conds = GetFormatCondition("E7:G8", Color.LightCoral, _sheet);
int idx = conds.AddCondition(FormatConditionType.NotContainsText);
FormatCondition cond = conds[idx];
cond.Style.BackgroundColor = Color.Pink;
cond.Style.Pattern = BackgroundType.Solid;
cond.Text = "3";
book.Save("NotContainsText.xlsx");
}

Benzersiz Değerleri İçeriyorsa Hücreyi Biçimlendir

// This method implements the UniqueValues conditional formatting type.
private void AddUniqueValues()
{
// Instantiate a workbook object
Workbook book = new Workbook();
// Create a worksheet object and get the first worksheet
Worksheet _sheet = book.Worksheets[0];
FormatConditionCollection conds = GetFormatCondition("E21:G22", Color.LightSalmon, _sheet);
int idx = conds.AddCondition(FormatConditionType.UniqueValues);
FormatCondition cond = conds[idx];
cond.Style.BackgroundColor = Color.Yellow;
cond.Style.Pattern = BackgroundType.Solid;
Cell c = _sheet.Cells["E21"];
c.PutValue("aa");
c = _sheet.Cells["G22"];
c.PutValue("aa");
book.Save("UniqueValues.xlsx");
}