Doldurma Ayarları
Renkler ve Arka Plan Desenleri
Microsoft Excel, hücrelerin ön plan (çerçeve) ve arka plan (doldurma) renklerini ve arka plan desenlerini ayarlayabilir.
Aspose.Cells, bu özellikleri esnek bir şekilde destekler. Bu konuda, Aspose.Cells kullanarak bu özellikleri nasıl kullanacağımızı öğreneceğiz.
Renkler ve Arka Plan Desenlerini Ayarlama
Aspose.Cells, Microsoft Excel dosyasını temsil eden bir sınıf olan Workbook sunar. Workbook sınıfı, Excel dosyasındaki her bir çalışma sayfasına erişim sağlayan bir koleksiyon içerir. Bir çalışma sayfası Worksheets sınıfı tarafından temsil edilir. Worksheet sınıfı, bir koleksiyon sağlar. Worksheet sınıfı, bir koleksiyon sağlar. Cells koleksiyonundaki her öğe, Cell sınıfının bir nesnesini temsil eder.
Cell, hücre biçimlendirme işlemlerini almak ve ayarlamak için kullanılan GetStyle ve SetStyle metodlarına sahiptir. Style sınıfı, hücrelerin ön plan ve arka plan renklerini ayarlamak için özellikler sağlar. Aspose.Cells, aşağıda verilen önceden tanımlanmış arka plan desenlerini içeren bir BackgroundType numaralı sıralı koleksiyon sağlar.
Arka Plan Desenleri | Açıklama |
---|---|
DiagonalCrosshatch | Çapraz çizgili deseni temsil eder |
DiagonalStripe | Çapraz şerit deseni temsil eder |
Gray6 | %6,25 gri deseni temsil eder |
Gray12 | %12,5 gri deseni temsil eder |
Gray25 | %25 gri deseni temsil eder |
Gray50 | %50 gri deseni temsil eder |
Gray75 | %75 gri deseni temsil eder |
HorizontalStripe | Dikey şerit deseni temsil eder |
None | Arka plan yok |
ReverseDiagonalStripe | Çapraz ters şerit deseni temsil eder |
Solid | Düz deseni temsil eder |
ThickDiagonalCrosshatch | Kalın çapraz çizgili deseni temsil eder |
ThinDiagonalCrosshatch | İnce çapraz çizgili deseni temsil eder |
ThinDiagonalStripe | İnce çapraz şerit deseni temsil eder |
ThinHorizontalCrosshatch | İnce yatay çapraz çizgili deseni temsil eder |
ThinHorizontalStripe | İnce yatay şerit deseni temsil eder |
ThinReverseDiagonalStripe | İnce ters çapraz şerit deseni temsil eder |
ThinVerticalStripe | İnce dikey şerit deseni temsil eder |
VerticalStripe | Dikey şerit deseni temsil eder |
Aşağıdaki örnekte, A1 hücresinin ön plan rengi ayarlanmış ancak A2, dikey çizgili bir arka plan deseni olan hem ön plan rengi hem de arka plan rengi olarak yapılandırılmıştır.
// 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 Workbook object | |
int i = workbook.Worksheets.Add(); | |
// Obtaining the reference of the newly added worksheet by passing its sheet index | |
Worksheet worksheet = workbook.Worksheets[i]; | |
// Define a Style and get the A1 cell style | |
Style style = worksheet.Cells["A1"].GetStyle(); | |
// Setting the foreground color to yellow | |
style.ForegroundColor = Color.Yellow; | |
// Setting the background pattern to vertical stripe | |
style.Pattern = BackgroundType.VerticalStripe; | |
// Apply the style to A1 cell | |
worksheet.Cells["A1"].SetStyle(style); | |
// Get the A2 cell style | |
style = worksheet.Cells["A2"].GetStyle(); | |
// Setting the foreground color to blue | |
style.ForegroundColor = Color.Blue; | |
// Setting the background color to yellow | |
style.BackgroundColor = Color.Yellow; | |
// Setting the background pattern to vertical stripe | |
style.Pattern = BackgroundType.VerticalStripe; | |
// Apply the style to A2 cell | |
worksheet.Cells["A2"].SetStyle(style); | |
// Saving the Excel file | |
workbook.Save(dataDir + "book1.out.xls", SaveFormat.Excel97To2003); |
Bilinmesi Gerekenler
- Bir hücrenin ön plan veya arka plan rengini ayarlamak için, Style nesnesinin ForegroundColor veya BackgroundColor özelliklerini kullanın. Her iki özellik de, Style nesnesinin Pattern özelliği yapılandırılmışsa yalnızca etki eder.
- ForegroundColor özelliği hücrenin gölge rengini belirler. Pattern özelliği, önyüz veya arka plan rengi için kullanılan arka plan deseninin türünü belirtir. Aspose.Cells, bir dizi önceden tanımlanmış arka plan desenlerini içeren BackgroundType adlı bir numaralandırmayı sağlar.
- Eğer BackgroundType numaralandırmasından BackgroundType.None değerini seçerseniz, ön plan rengi uygulanmaz. Benzer şekilde, BackgroundType.None veya BackgroundType.Solid değerlerini seçerseniz arka plan rengi uygulanmaz.
- Hücrenin gölgelendirme/dolgu rengini alırken, Style.Pattern BackgroundType.None ise, Style.ForegroundColor Color.Empty değerini döndürecektir.
Gradyan Dolgu Efektleri Uygulama
Hücreye istenilen Gradyan Dolgu Efektlerini uygulamak için, Style nesnesinin SetTwoColorGradient metodunu kullanın.
// 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); | |
// Instantiate a new Workbook | |
Workbook workbook = new Workbook(); | |
// Get the first worksheet (default) in the workbook | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Input a value into B3 cell | |
worksheet.Cells[2, 1].PutValue("test"); | |
// Get the Style of the cell | |
Style style = worksheet.Cells["B3"].GetStyle(); | |
// Set Gradient pattern on | |
style.IsGradient = true; | |
// Specify two color gradient fill effects | |
style.SetTwoColorGradient(Color.FromArgb(255, 255, 255), Color.FromArgb(79, 129, 189), GradientStyleType.Horizontal, 1); | |
// Set the color of the text in the cell | |
style.Font.Color = Color.Red; | |
// Specify horizontal and vertical alignment settings | |
style.HorizontalAlignment = TextAlignmentType.Center; | |
style.VerticalAlignment = TextAlignmentType.Center; | |
// Apply the style to the cell | |
worksheet.Cells["B3"].SetStyle(style); | |
// Set the third row height in pixels | |
worksheet.Cells.SetRowHeightPixel(2, 53); | |
// Merge the range of cells (B3:C3) | |
worksheet.Cells.Merge(2, 1, 1, 2); | |
// Save the Excel file | |
workbook.Save(dataDir + "output.xlsx"); |
Renkler ve Palet
Bir palet, bir görüntü oluşturmak için kullanılabilen renk sayısıdır. Bir sunumda standart bir palet kullanımı, kullanıcının tutarlı bir görünüm oluşturmasına olanak tanır. Her Microsoft Excel (97-2003) dosyasının bir hücrelere, fontlara, ızgaralara, grafik nesnelerine, doldurmalara ve çizgilere uygulanabilen 56 renklik bir paleti vardır.
Aspose.Cells ile sadece paletin mevcut renklerini değil aynı zamanda özel renkleri de kullanmak mümkündür. Özel bir rengi kullanmadan önce, önce paletine ekleyin.
Bu konu, paletine özel renkler eklemenin nasıl yapıldığını tartışmaktadır.
Paletine Özel Renkler Eklemek
Aspose.Cells, Microsoft Excel’in 56 renkli paletini destekler. Paletine tanımlanmamış özel bir renk kullanmak için, rengi paletine ekleyin.
Aspose.Cells, bir Microsoft Excel dosyasını temsil eden Workbook sınıfını sağlar. Workbook sınıfı, paleti değiştirmek için özel bir renk eklemek için aşağıdaki parametreleri alan bir ChangePalette yöntemi sağlar:
- Özel Renk, paletine eklenecek özel renk.
- İndeks, özel rengin paletindeki rengin yerini belirtir. 0-55 arasında olmalıdır.
Aşağıdaki örnek, (Orkide) özel bir rengi paletine ekleyip bunu bir font üzerine uygulamadan önce paletine ekler.
// Instantiating an Workbook object | |
Workbook workbook = new Workbook(); | |
//Checks if a color is in the palette for the spreadsheet. | |
Console.WriteLine(workbook.IsColorInPalette(Color.Orchid)); | |
// Adding Orchid color to the palette at 55th index | |
workbook.ChangePalette(Color.Orchid, 55); | |
Console.WriteLine(workbook.IsColorInPalette(Color.Orchid)); | |
// 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 | |
Cell cell = worksheet.Cells["A1"]; | |
// Adding some value to the "A1" cell | |
cell.PutValue("Hello Aspose!"); | |
// Defining new Style object | |
Style styleObject = workbook.CreateStyle(); | |
// Setting the Orchid (custom) color to the font | |
styleObject.Font.Color = workbook.Colors[55]; | |
// Applying the style to the cell | |
cell.SetStyle(styleObject); | |
// Saving the Excel file | |
workbook.Save("out.xlsx"); |