Kenar Ayarları

Hücrelere Kenarlık Eklemek

Microsoft Excel, kullanıcılara sınırlar ekleyerek hücreleri biçimlendirmelerine olanak tanır. Sınırın türü nereye eklendiğine bağlıdır. Örneğin, üst sınır, bir hücrenin üst konumuna eklenen sınırdır. Kullanıcılar ayrıca sınırların çizgi stili ve rengini değiştirebilirler.

Aspose.Cells ile geliştiriciler, sınırlar ekleyebilir ve bunları Microsoft Excel’de olduğu gibi esnek bir şekilde özelleştirebilirler.

Hücrelere Kenarlık Eklemek

Aspose.Cells, bir Microsoft Excel dosyasını temsil eden Workbook sınıfını sağlar. Workbook sınıfı, Excel dosyasındaki her bir çalışma sayfasına erişim sağlayan bir Worksheets koleksiyonunu içerir. Bir çalışma sayfası Worksheet sınıfı tarafından temsil edilir. Worksheet sınıfı Cells koleksiyonunu sağlar. Cells koleksiyonunda her öğe, Cell sınıfının bir nesnesini temsil eder.

Aspose.Cells, Cell sınıfında GetStyle metodunu sağlar. SetStyle metodu, bir hücrenin biçimlendirme stili ayarlamak için kullanılır. Style sınıfı, hücrelere sınırlar eklemek için özellikler sağlar.

Bir Hücreye Sınır Ekleme

Geliştiriciler, Style nesnesinin Borders koleksiyonunu kullanarak bir hücreye sınır ekleyebilirler. Sınır türü, Borders koleksiyonuna bir dizin olarak iletilir. Tüm sınır türleri, BorderType numaralandırmasında önceden tanımlanmıştır.

Sınır numaralandırması

Sınır Türleri Açıklama
BottomBorder Alt sınır çizgisi
DiagonalDown Sol üstten sağ alt köşeye çapraz çizgi
DiagonalUp Sol alttan sağ üste çapraz çizgi
LeftBorder Sol sınır çizgisi
RightBorder Sağ sınır çizgisi
TopBorder Üst sınır çizgisi

The Borders collection stores all borders. Each border in the Borders collection is represented by a Border object which provides two properties, Color and LineStyle to set a border’s line color and style respectively.

Bir sınırın çizgi rengini ayarlamak için, renk seçmek için .NET Framework’ün bir parçası olan Renk numaralandırmasını seçin ve onu Sınır nesnesinin Renk özelliğine atayın.

Sınırın çizgi stili, CellBorderType numaralandırmasından bir çizgi stili seçilerek ayarlanır.

HücreSınırTürü numaralandırması

Çizgi Stilleri Açıklama
DashDot İnce tireli kesikli çizgi
DashDotDot İnce tireli kesik noktalı çizgi
Dashed Kesikli çizgi
Dotted Noktalı çizgi
Double Çift çizgi
Hair Saç inceliğinde çizgi
MediumDashDot Orta tireli kesikli çizgi
MediumDashDotDot Orta tireli kesik noktalı çizgi
MediumDashed Orta kesikli çizgi
None No Line
Medium Orta Çizgi
SlantedDashDot Eğik orta kesikli çizgi
Thick Kalın çizgi
Thin İnce çizgi
Bir çizgi stili seçin ve ardından Border nesnesinin LineStyle özelliğine atayı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);
// 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();
// Obtaining the reference of the first (default) worksheet by passing its sheet index
Worksheet worksheet = workbook.Worksheets[0];
// Accessing the "A1" cell from the worksheet
Aspose.Cells.Cell cell = worksheet.Cells["A1"];
// Adding some value to the "A1" cell
cell.PutValue("Visit Aspose!");
// Create a style object
Style style = cell.GetStyle();
// Setting the line style of the top border
style.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thick;
// Setting the color of the top border
style.Borders[BorderType.TopBorder].Color = Color.Black;
// Setting the line style of the bottom border
style.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thick;
// Setting the color of the bottom border
style.Borders[BorderType.BottomBorder].Color = Color.Black;
// Setting the line style of the left border
style.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Thick;
// Setting the color of the left border
style.Borders[BorderType.LeftBorder].Color = Color.Black;
// Setting the line style of the right border
style.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Thick;
// Setting the color of the right border
style.Borders[BorderType.RightBorder].Color = Color.Black;
// Apply the border styles to the cell
cell.SetStyle(style);
// Saving the Excel file
workbook.Save(dataDir + "book1.out.xls");

Hücre Aralığına Sınırlar Ekleme

Tek bir hücreden ziyade bir hücre aralığına da sınırlar eklemek mümkündür. Bunu yapmak için öncelikle Cells koleksiyonunun CreateRange yöntemini çağırarak bir hücre aralığı oluşturun. Aşağıdaki parametreleri alır:

  • İlk Sütun, aralığın ilk sütunu.
  • İlk Sütun, aralığın ilk sütunu.
  • Satır Sayısı, aralıktaki satır sayısı.
  • Sütun Sayısı, aralıktaki sütun sayısı.

CreateRange yöntemi belirtilen hücre aralığını içeren bir Range nesnesi döndürür. Range nesnesi, hücre aralığına sınır eklemek için aşağıdaki parametreleri alır:

  • Sınır Türü, BorderType sıralamasından seçilen sınır türü.
  • Çizgi Stili, CellBorderType sıralamasından seçilen sınır çizgi stili.
  • Renk, Renk sıralamasından seçilen çizgi rengi.
// 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();
// Obtaining the reference of the first (default) worksheet by passing its sheet index
Worksheet worksheet = workbook.Worksheets[0];
// Accessing the "A1" cell from the worksheet
Cell cell = worksheet.Cells["A1"];
// Adding some value to the "A1" cell
cell.PutValue("Hello World From Aspose");
// Creating a range of cells starting from "A1" cell to 3rd column in a row
Range range = worksheet.Cells.CreateRange(0, 0, 1, 3);
// Adding a thick top border with blue line
range.SetOutlineBorder(BorderType.TopBorder, CellBorderType.Thick, Color.Blue);
// Adding a thick bottom border with blue line
range.SetOutlineBorder(BorderType.BottomBorder, CellBorderType.Thick, Color.Blue);
// Adding a thick left border with blue line
range.SetOutlineBorder(BorderType.LeftBorder, CellBorderType.Thick, Color.Blue);
// Adding a thick right border with blue line
range.SetOutlineBorder(BorderType.RightBorder, CellBorderType.Thick, Color.Blue);
// Saving the Excel file
workbook.Save(dataDir + "book1.out.xls");