Excel ve ODS dosyalarının Koşullu Biçimlerini Ayarlayın.
Giriş
Koşullu biçimlendirme, bir hücreye veya hücre aralığına biçimler uygulamanıza ve bu biçimlendirmenin hücre değerine veya bir formülün değerine bağlı olarak değişmesine olanak tanıyan gelişmiş bir Microsoft Excel özelliğidir. Örneğin, bir hücrenin değeri 500’den büyük olduğunda hücre kalın görünebilir. Hücre değeri koşulu karşıladığında belirtilen biçim, hücreye uygulanır. Hücre değeri biçim koşulunu karşılamazsa, hücrenin varsayılan biçimlendirmesi kullanılır. Microsoft Excel’de Biçim, ardından Koşullu Biçimlendirme‘yi seçerek Koşullu Biçimlendirme iletişim kutusunu açabilirsiniz.
Aspose.Cells, hücrelere koşullu biçimlendirme uygulamayı destekler. Bu makale, bu konuyu açıklamaktadır. Ayrıca Excel’in renk ölçeği koşullu biçimlendirme için kullandığı rengi nasıl hesapladığını açıklar.
Koşullu Biçimlendirme Uygulama
Aspose.Cells, koşullu biçimlendirme uygulamayı birkaç şekilde destekler:
- Tasarımcı elek tablosu kullanarak
- Kopya yöntemi kullanarak.
- Çalışma zamanında koşullu biçimlendirme oluşturarak.
Tasarımcı Elek Tablosu Kullanma
Geliştiriciler, Microsoft Excel’de koşullu biçimlendirmeler içeren bir tasarımcı elektronik tablo oluşturabilir ve ardından o elektronik tabloyu Aspose.Cells ile açabilirler. Aspose.Cells, tasarımcı elektronik tabloyu yükler ve kaydeder, herhangi bir koşullu biçimlendirme ayarını korur.
Kopyalama Yöntemi Kullanımı
Aspose.Cells, geliştiricilere bir hücreden diğerine koşullu biçimlendirme ayarlarını çağırarak kopyalama imkanı sunar.
// 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); | |
// Creating a file stream containing the Excel file to be opened | |
FileStream fstream = new FileStream(dataDir + "Book1.xlsx", FileMode.Open); | |
// Opening the Excel file through the file stream | |
Workbook workbook = new Workbook(fstream); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Copying conditional format settings from cell "A1" to cell "B1" | |
//worksheet.CopyConditionalFormatting(0, 0, 0, 1); | |
int TotalRowCount = 0; | |
for (int i = 0; i < workbook.Worksheets.Count; i++) | |
{ | |
Worksheet sourceSheet = workbook.Worksheets[i]; | |
Range sourceRange = sourceSheet.Cells.MaxDisplayRange; | |
Range destRange = worksheet.Cells.CreateRange(sourceRange.FirstRow + TotalRowCount, sourceRange.FirstColumn, | |
sourceRange.RowCount, sourceRange.ColumnCount); | |
destRange.Copy(sourceRange); | |
TotalRowCount = sourceRange.RowCount + TotalRowCount; | |
} | |
// Saving the modified Excel file | |
workbook.Save(dataDir + "output.xls"); | |
// Closing the file stream to free all resources | |
fstream.Close(); | |
Çalışma Zamanında Koşullu Biçimlendirme Uygulama
Aspose.Cells, çalışma zamanında koşullu biçimlendirme eklemeye ve kaldırmaya olanak tanır. Aşağıdaki kod örnekleri, koşullu biçimlendirme ayarlarını nasıl yapacağınızı gösterir:
- Bir çalışma kitabı örneği oluşturun.
- Boş bir koşullu biçimlendirme ekleyin.
- Biçimlendirmenin uygulanması gereken aralığı belirleyin.
- Biçimlendirme koşullarını tanımlayın.
- Dosyayı kaydedin.
Bu örneğin ardından, yazı tipi ayarları, kenarlık ayarları ve desen ayarları nasıl uygulanacağını gösteren birçok diğer küçük örnek gelir.
Microsoft Excel 2007, Aspose.Cells’in de desteklediği daha gelişmiş koşullu biçimlendirme ekledi. Buradaki örnekler, basit biçimlendirmeyi nasıl kullanacağınızı gösterir; Microsoft Excel 2007 örnekleri ise daha gelişmiş koşullu biçimlendirmeyi nasıl uygulayabileceğinizi gösterir.
// 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); | |
string filePath = dataDir + "Book1.xlsx"; | |
// 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); | |
ca = new CellArea(); | |
ca.StartRow = 1; | |
ca.EndRow = 1; | |
ca.StartColumn = 1; | |
ca.EndColumn = 1; | |
fcs.AddArea(ca); | |
// Adds condition. | |
int conditionIndex = fcs.AddCondition(FormatConditionType.CellValue, OperatorType.Between, "=A2", "100"); | |
// Adds condition. | |
int conditionIndex2 = 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.xls"); |
Yazı Tipi Ayarı
// 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(); | |
// Adding a new worksheet to the Excel object | |
int i = workbook.Worksheets.Add(); | |
// Obtaining the reference of the newly added worksheet by passing its sheet index | |
Worksheet worksheet = workbook.Worksheets[i]; | |
// Accessing the "A1" cell from the worksheet | |
Aspose.Cells.Cell cell = worksheet.Cells["A1"]; | |
// Adding some value to the "A1" cell | |
cell.PutValue("Hello Aspose!"); | |
// Obtaining the style of the cell | |
Style style = cell.GetStyle(); | |
// Setting the font weight to bold | |
style.Font.IsBold = true; | |
// Applying the style to the cell | |
cell.SetStyle(style); | |
// Saving the Excel file | |
workbook.Save(dataDir + "book1.out.xls", SaveFormat.Excel97To2003); |
Sınır Ayarı
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
public static void Run() | |
{ | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// 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 = 5; | |
ca.StartColumn = 0; | |
ca.EndColumn = 3; | |
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.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Dashed; | |
fc.Style.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Dashed; | |
fc.Style.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Dashed; | |
fc.Style.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Dashed; | |
fc.Style.Borders[BorderType.LeftBorder].Color = Color.FromArgb(0, 255, 255); | |
fc.Style.Borders[BorderType.RightBorder].Color = Color.FromArgb(0, 255, 255); | |
fc.Style.Borders[BorderType.TopBorder].Color = Color.FromArgb(0, 255, 255); | |
fc.Style.Borders[BorderType.BottomBorder].Color = Color.FromArgb(255, 255, 0); | |
workbook.Save(dataDir + "output.xlsx"); | |
} |
Desen Ayarı
// 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); | |
// 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 = 5; | |
ca.StartColumn = 0; | |
ca.EndColumn = 3; | |
fcs.AddArea(ca); | |
// Adds condition. | |
int conditionIndex = fcs.AddCondition(FormatConditionType.CellValue, OperatorType.Between, "50", "100"); | |
FormatCondition fc = fcs[conditionIndex]; | |
fc.Style.Pattern = BackgroundType.ReverseDiagonalStripe; | |
fc.Style.ForegroundColor = Color.FromArgb(255, 255, 0); | |
fc.Style.BackgroundColor = Color.FromArgb(0, 255, 255); | |
workbook.Save(dataDir + "output.xlsx"); |
Gelişmiş Konular
- 2-Renkli Ölçek ve 3-Renkli Ölçek Koşullu Biçimlendirmeleri Ekle
- Gelişmiş Koşullu Biçimlendirme Uygulamak
- Çalışma Kitaplarında Koşullu Biçimlendirme Uygulamak
- Koşullu Biçimlendirme ile Sıfır Satır ve Sütunlara Gölgelendirme Uygulamak
- Koşullu Biçimlendirme Veri Çubukları Görüntüleri Oluşturmak
- Kullanılan Koşullu Biçimlendirme İkon Setleri, Veri Çubukları veya Renk Ölçekleri Nesnelerini Almak