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 for Python via .NET ile geliştiriciler, kenarlıklar ekleyebilir ve Microsoft Excel’deki gibi görünümünü özelleştirebilir.
Hücrelere Kenarlık Eklemek
Aspose.Cells for Python via .NET, Microsoft Excel dosyasını temsil eden Workbook adlı bir sınıf sağlar. Workbook sınıfı, Excel dosyasındaki her çalışma sayfasına erişim sağlayan 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 koleksiyonundaki her öğe, Cell sınıfının bir nesnesini temsil eder.
Aspose.Cells for Python via .NET, get_style adlı yöntemi Cell sınıfında sağlar. set_style yöntemi, bir hücrenin biçimlendirme stilini ayarlamak için kullanılır. Style sınıfı, hücrelere kenarlık 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 |
---|---|
BOTTOM_BORDER | Alt kenarlık çizgisi |
DIAGONAL_DOWN | Sol üstten sağ altta çapraz çizgi |
DIAGONAL_UP | Sol alttan sağ üstte çapraz çizgi |
LEFT_BORDER | Sol kenarlık çizgisi |
RIGHT_BORDER | Sağ kenarlık çizgisi |
TOP_BORDER | Üst kenarlık ç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 line_style 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 |
---|---|
DASH_DOT | İnce noktalı çizgi |
DASH_DOT_DOT | İnce nokta noktalı çizgi |
DASHED | Kesik çizgi |
DOTTED | Noktalı çizgi |
DOUBLE | İki kat çizgi |
HAIR | Saç hattı |
MEDIUM_DASH_DOT | Orta noktalı çizgi |
MEDIUM_DASH_DOT_DOT | Orta nokta noktalı çizgi |
MEDIUM_DASHED | Orta kesikli çizgi |
NONE | Hiç çizgi yok |
MEDIUM | Orta çizgi |
SLANTED_DASH_DOT | Eğimli orta noktalı çizgi |
THICK | Kalın çizgi |
THIN | İnce çizgi |
Bir çizgi stili seçin ve ardından Border nesnesinin line_style özelliğine atayın. |
from aspose.cells import BorderType, CellBorderType, Workbook | |
from aspose.pydrawing import Color | |
from os import os, path | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# The path to the documents directory. | |
dataDir = RunExamples.GetDataDir(".") | |
# Create directory if it is not already present. | |
IsExists = path.isdir(dataDir) | |
if notIsExists: | |
os.makedirs(dataDir) | |
# Instantiating a Workbook object | |
workbook = Workbook() | |
# Obtaining the reference of the first (default) worksheet by passing its sheet index | |
worksheet = workbook.worksheets[0] | |
# Accessing the "A1" cell from the worksheet | |
cell = worksheet.cells.get("A1") | |
# Adding some value to the "A1" cell | |
cell.put_value("Visit Aspose!") | |
# Create a style object | |
style = cell.get_style() | |
# Setting the line style of the top border | |
style.borders.get(BorderType.TOP_BORDER).line_style = CellBorderType.THICK | |
# Setting the color of the top border | |
style.borders.get(BorderType.TOP_BORDER).color = Color.black | |
# Setting the line style of the bottom border | |
style.borders.get(BorderType.BOTTOM_BORDER).line_style = CellBorderType.THICK | |
# Setting the color of the bottom border | |
style.borders.get(BorderType.BOTTOM_BORDER).color = Color.black | |
# Setting the line style of the left border | |
style.borders.get(BorderType.LEFT_BORDER).line_style = CellBorderType.THICK | |
# Setting the color of the left border | |
style.borders.get(BorderType.LEFT_BORDER).color = Color.black | |
# Setting the line style of the right border | |
style.borders.get(BorderType.RIGHT_BORDER).line_style = CellBorderType.THICK | |
# Setting the color of the right border | |
style.borders.get(BorderType.RIGHT_BORDER).color = Color.black | |
# Apply the border styles to the cell | |
cell.set_style(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 create_range 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ı.
create_range 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.
from aspose.cells import BorderType, CellBorderType, Workbook | |
from aspose.pydrawing import Color | |
from os import os, path | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# The path to the documents directory. | |
dataDir = RunExamples.GetDataDir(".") | |
# Create directory if it is not already present. | |
IsExists = path.isdir(dataDir) | |
if notIsExists: | |
os.makedirs(dataDir) | |
# Instantiating a Workbook object | |
workbook = Workbook() | |
# Obtaining the reference of the first (default) worksheet by passing its sheet index | |
worksheet = workbook.worksheets[0] | |
# Accessing the "A1" cell from the worksheet | |
cell = worksheet.cells.get("A1") | |
# Adding some value to the "A1" cell | |
cell.put_value("Hello World From Aspose") | |
# Creating a range of cells starting from "A1" cell to 3rd column in a row | |
range = worksheet.cells.create_range(0, 0, 1, 3) | |
# Adding a thick top border with blue line | |
range.set_outline_border(BorderType.TOP_BORDER, CellBorderType.THICK, Color.blue) | |
# Adding a thick bottom border with blue line | |
range.set_outline_border(BorderType.BOTTOM_BORDER, CellBorderType.THICK, Color.blue) | |
# Adding a thick left border with blue line | |
range.set_outline_border(BorderType.LEFT_BORDER, CellBorderType.THICK, Color.blue) | |
# Adding a thick right border with blue line | |
range.set_outline_border(BorderType.RIGHT_BORDER, CellBorderType.THICK, Color.blue) | |
# Saving the Excel file | |
workbook.save(dataDir + "book1.out.xls") |