Uyum Ayarları

Hizalama Ayarlarının Yapılandırılması

Microsoft Excel’deki hizalama ayarları

Hücreleri biçimlendirmek için Microsoft Excel kullanan herkes, Microsoft Excel’deki hizalama ayarlarına aşinadır.

Yukarıdaki şekilden görebileceğiniz gibi, farklı türde hizalama seçenekleri bulunmaktadır:

  • Metin hizalama (yatay ve dikey)
  • Girinti
  • Yönlendirme
  • Metin kontrol
  • Metin yönü

Tüm bu hizalama ayarları Aspose.Cells for Python via .NET tarafından tam olarak desteklenmekte olup, aşağıda daha ayrıntılı olarak tartışılmıştır.

Aspose.Cells for Python via .NET’de Hizalama ayarları

Aspose.Cells for Python via .NET, bir Excel dosyasını temsil eden Workbook adlı bir sınıf sağlar. Workbook sınıfı, Excel dosyasındaki her bir çalışma sayfasına erişim sağlayan bir worksheets koleksiyon içerir. Bir çalışma sayfası, Worksheet sınıfı ile temsil edilir. Worksheet sınıfı ise bir cells koleksiyonu sağlar. cells koleksiyonundaki her öğe, Cell sınıfı nesnesini temsil eder.

Aspose.Cells for Python via .NET, get_style ve set_style metodlarını cell biçimlendirmesini almak ve ayarlamak için sağlar. Style sınıfı, hizalama ayarlarını yapılandırmak için kullanışlı özellikler sunar.

TextAlignmentType numarasını kullanarak herhangi bir metin hizalama türünü seçin. TextAlignmentType numarasındaki önceden tanımlanmış metin hizalama türleri:

Metin Hizalama Türleri Açıklama
GENEL Genel metin hizalamasını temsil eder
ALT Alt metin hizalamasını temsil eder
ORTA Orta metin hizalamasını temsil eder
ORTA_GEÇİŞİ Orta metin hizalaması, metinleri yatay olarak ortalar
DAĞITILMIŞ Dağıtılmış metin hizalamasını temsil eder
DOLDUR Doldurma metin hizalamasını temsil eder
MEŞH Yüzde ayarlamasına göre hizalamayı sağlar
SOL Sol metin hizalamasını temsil eder
SAĞ Sağ metin hizalamasını temsil eder
ÜST Üst metin hizalamasını temsil eder
DOĞRU_AL Arapça metin için kashida uzunluğunu ayarlayarak hizalar
TAY_DAĞIT Tayca metni özel olarak dağıtır, çünkü her karakter kelime olarak kabul edilir

Yatay Hizalama

Metni yatay olarak hizalamak için Style nesnesinin horizontal_alignment özelliğini kullanın

from aspose.cells import SaveFormat, TextAlignmentType, Workbook
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 worksheet
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!")
# Setting the horizontal alignment of the text in the "A1" cell
style = cell.get_style()
style.horizontal_alignment = TextAlignmentType.CENTER
cell.set_style(style)
# Saving the Excel file
workbook.save(dataDir + "book1.out.xls", SaveFormat.EXCEL_97_TO_2003)

Dikey Hizalama

Yatay hizalama ile benzer şekilde metni dikey olarak hizalamak için Style nesnesinin vertical_alignment özelliğini kullanın.

from aspose.cells import SaveFormat, TextAlignmentType, Workbook
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()
# Clearing all the worksheets
workbook.worksheets.clear()
# Adding a new worksheet to the Excel object
i = workbook.worksheets.add()
# Obtaining the reference of the newly added worksheet by passing its sheet index
worksheet = workbook.worksheets[i]
# Accessing the "A1" cell from the worksheet
cell = worksheet.cells.get("A1")
# Adding some value to the "A1" cell
cell.put_value("Visit Aspose!")
# Setting the horizontal alignment of the text in the "A1" cell
style = cell.get_style()
# Setting the vertical alignment of the text in a cell
style.vertical_alignment = TextAlignmentType.CENTER
cell.set_style(style)
# Saving the Excel file
workbook.save(dataDir + "book1.out.xls", SaveFormat.EXCEL_97_TO_2003)

Girinti

Hücredeki metnin girinti seviyesini Style nesnesinin indent_level özelliği ile ayarlamak mümkündür.

from aspose.cells import SaveFormat, Workbook
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 worksheet
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!")
# Setting the horizontal alignment of the text in the "A1" cell
style = cell.get_style()
# Setting the indentation level of the text (inside the cell) to 2
style.indent_level = 2
cell.set_style(style)
# Saving the Excel file
workbook.save(dataDir + "book1.out.xls", SaveFormat.EXCEL_97_TO_2003)

Yönlendirme

Hücrede metnin yönlendirmesini (döndürme) Style nesnesinin rotation_angle özelliği ile ayarlayın.

from aspose.cells import SaveFormat, Workbook
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 worksheet
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!")
# Setting the horizontal alignment of the text in the "A1" cell
style = cell.get_style()
# Setting the rotation of the text (inside the cell) to 25
style.rotation_angle = 25
cell.set_style(style)
# Saving the Excel file
workbook.save(dataDir + "book1.out.xls", SaveFormat.EXCEL_97_TO_2003)

Metin Kontrolü

Aşağıdaki bölüm metin kaydırma, sığdırmayı daraltma ve diğer biçimlendirme seçeneklerini ayarlayarak metni nasıl kontrol edeceğinizi tartışmaktadır.

Metni Kaydırma

Hücrede metni kaydırmak onu okumayı kolaylaştırır: hücrenin yüksekliği, metni kesmek yerine veya yan hücrelere taşmak yerine tüm metni sığdırmak için ayarlanır. Metin kaydırma özelliğini Style nesnesinin is_text_wrapped özelliği ile açın veya kapatın.

from aspose.cells import Workbook
# 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 Workbook Object
wb = Workbook()
# Open first Worksheet in the workbook
ws = wb.worksheets[0]
# Get Worksheet Cells Collection
cell = ws.cells
# Increase the width of First Column Width
cell.set_column_width(0, 35)
# Increase the height of first row
cell.set_row_height(0, 36)
# Add Text to the Firts Cell
cell.get(0, 0).put_value("I am using the latest version of Aspose.Cells to test this functionality")
# Make Cell's Text wrap
style = cell.get(0, 0).get_style()
style.is_text_wrapped = True
cell.get(0, 0).set_style(style)
# Save Excel File
wb.save(dataDir + "WrappingText.out.xlsx")
Sığdırmayı Daraltma

Bir alanın metnini kaydırmak için bir seçenek, metni hücre boyutlarına sığdırmak için metin boyutunu küçültmektir. Bu, true olarak Style nesnesinin is_text_wrapped özelliği ile ayarlanır.

from aspose.cells import SaveFormat, Workbook
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 worksheet
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!")
# Setting the horizontal alignment of the text in the "A1" cell
style = cell.get_style()
# Shrinking the text to fit according to the dimensions of the cell
style.shrink_to_fit = True
cell.set_style(style)
# Saving the Excel file
workbook.save(dataDir + "book1.out.xls", SaveFormat.EXCEL_97_TO_2003)
Hücreleri Birleştirme

Microsoft Excel gibi, Aspose.Cells for Python via .NET birkaç hücreyi bir araya getirip tek hücre yapmayı destekler. Aspose.Cells for Python via .NET bu işlemi gerçekleştirmek için iki yaklaşım sunar. Bir yol, cells koleksiyonunun merge metodunu çağırmaktır. merge metodu, hücreleri birleştirmek için aşağıdaki parametreleri alır:

  • İlk satır: Birleştirmeye başlamak için ilk satır.
  • İlk sütun: Birleştirmeye başlamak için ilk sütun.
  • Satır sayısı: Birleştirilecek satır sayısı.
  • Sütun sayısı: Birleştirilecek sütun sayısı.
from aspose.cells import BackgroundType, 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)
# Create a Workbook.
wbk = Workbook()
# Create a Worksheet and get the first sheet.
worksheet = wbk.worksheets[0]
# Create a Cells object ot fetch all the cells.
cells = worksheet.cells
# Merge some Cells (C6:E7) into a single C6 Cell.
cells.merge(5, 2, 2, 3)
# Input data into C6 Cell.
worksheet.cells.get(5, 2).put_value("This is my value")
# Create a Style object to fetch the Style of C6 Cell.
style = worksheet.cells.get(5, 2).get_style()
# Create a Font object
font = style.font
# Set the name.
font.name = "Times New Roman"
# Set the font size.
font.size = 18
# Set the font color
font.color = Color.blue
# Bold the text
font.is_bold = True
# Make it italic
font.is_italic = True
# Set the backgrond color of C6 Cell to Red
style.foreground_color = Color.red
style.pattern = BackgroundType.SOLID
# Apply the Style to C6 Cell.
cells.get(5, 2).set_style(style)
# Save the Workbook.
wbk.save(dataDir + "mergingcells.out.xls")

Diğer yol, öncelikle cells koleksiyonunun create_range yöntemini çağırmak ve birleştirilecek hücrelerin aralığını oluşturmaktır. create_range yöntemi yukarıdaki merge yönteminin aynı parametre setini alır ve bir Range nesnesi döndürür. Range nesnesi ayrıca merge yöntemi sağlar, bu yöntem Range nesnesinde belirtilen aralığı birleştirir.

Metin Yönü

Hücrelerdeki metnin okuma sırasını ayarlamak mümkündür. Okuma sırası, karakterlerin, kelimelerin vb. görüntülendiği görsel sıradır. Örneğin, İngilizce soldan sağa bir dil iken Arapça sağdan sola bir dildir.

Okuma sırası, Style nesnesinin text_direction özelliği ile ayarlanır. Aspose.Cells for Python via .NET, TextDirectionType enumerasyonunda önceden tanımlanmış metin yönü türleri sağlar.

Metin Yönü Türleri Açıklama
KONTEXP İlk girilen karakterin diline uygun okuma sırası
SOL_İÇ Soldan sağa okuma sırası
SAĞ_İÇ Sağdan sola okuma sırası
from aspose.cells import TextDirectionType, Workbook
# Instantiating a Workbook object
workbook = Workbook()
# Obtaining the reference of first worksheet
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("I am using the latest version of Aspose.Cells to test this functionality.")
# Gets style in the "A1" cell
style = cell.get_style()
# Shrinking the text to fit according to the dimensions of the cell
style.text_direction = TextDirectionType.LEFT_TO_RIGHT
cell.set_style(style)
# Saving the Excel file
workbook.save("book1.xlsx")

Gelişmiş Konular