Veri Çubukları Koşullu Biçimlendirmesi Nasıl Eklenir

Olası Kullanım Senaryoları

Koşullu biçimlendirmede Veri Çubukları kullanmak, verinizi bir bakışta anlamanın güçlü (ve görsel!) bir yoludur.

  1. Değerlerin Görsel Karşılaştırması: Veri çubukları sayıları yatay çubuklara dönüştürür, böylece değerleri yan yana karşılaştırmak çok kolay — hücrelerinizde mini bir çubuk grafik gibi!
  2. Hemen Desen Tanıma: Sıralama veya tarama yapmadan yüksekler, alçaklar ve aykırı değerleri anında görebilirsiniz.
  3. Daha İyi Okunabilirlik: Özellikle uzun tablolar için faydalıdır — bilişsel yükü azaltır ve ana eğilimleri hızlıca kavramanıza yardımcı olur.
  4. Dinamik ve Gerçek Zamanlı: Değerler değiştikçe, çubuklar otomatik olarak güncellenir — canlı metrikleri, ilerlemeleri veya KPI’ları takip etmek için harika.
  5. Profesyonel Görünüm Sahibi Panolar: Raporlara veya panolara temiz, modern ve parlatılmış bir görünüm katar.

Excel Kullanarak Veri Çubukları Koşullu Biçimlendirme Nasıl Eklenir

Excel’de Veri Çubukları koşullu biçimlendirmesi eklemek için şu adımları uygulayabilirsiniz:

  1. Veri aralığınızı seçin, örneğin: C2:C20 — bu satış, skor veya ilerleme değerleri olabilir.
  2. Şeritteki Giriş sekmesine gidin.
  3. Stiller grubunda Koşullu Biçimlendirme’ye tıklayın.
  4. Veri Çubukları üzerine gelin.
  5. Bir stil seçin: Gradyan Doldurma (çubuklar soldan sağa solmalıdır) ve Düz Doldurma (çubuklar katı renkli olur).
  6. Beğendiğiniz stil üzerine tıklayın — ve tamam!

Aspose.Cells for .NET Kullanarak Veri Çubukları Koşullu Biçimlendirme Nasıl Eklenir

Aspose.Cells, çalışma zamanında XLSX formatındaki hücrelerde Microsoft Excel 2007 ve sonrası sürümler tarafından sağlanan koşullu biçimlendirmeyi tam olarak destekler. Bu örnek, farklı özellik setleriyle Veri Çubukları koşullu biçimlendirmesi için bir egzersiz gösterir.

private void TestDataBar()
{
// Instantiate a workbook object
Workbook book = new Workbook();
// Create a worksheet object and get the first worksheet
Worksheet _sheet = book.Worksheets[0];
AddDataBar1(_sheet);
AddDataBar2(_sheet);
book.Save(filePath + "DataBar.xlsx");
}
// This method implements the DataBars conditional formatting type with Percentile attribute.
private void AddDataBar2(Worksheet _sheet)
{
FormatConditionCollection conds = GetFormatCondition("E3:G4", Color.LightGreen, _sheet);
int idx = conds.AddCondition(FormatConditionType.DataBar);
FormatCondition cond = conds[idx];
cond.DataBar.Color = Color.Orange;
cond.DataBar.MinCfvo.Type = FormatConditionValueType.Percentile;
cond.DataBar.MinCfvo.Value = 30.78;
cond.DataBar.ShowValue = false;
}
// This method implements the DataBars conditional formatting type.
private void AddDataBar1(Worksheet _sheet)
{
FormatConditionCollection conds = GetFormatCondition("E1:G2", Color.YellowGreen, _sheet);
int idx = conds.AddCondition(FormatConditionType.DataBar);
FormatCondition cond = conds[idx];
}
// 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;
}