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ü
Bu tüm hizalama ayarları, Aspose.Cells tarafından tamamen desteklenir ve aşağıda daha detaylı olarak tartışılmaktadır.
Aspose.Cells’te hizalama ayarları
Aspose.Cells, GetStyle ve SetStyle metodlarını, Cell sınıfı için bir hücrenin biçimlendirmesini almak ve ayarlamak için kullanır. Style sınıfı, hizalama ayarlarını yapılandırmak için kullanışlı özellikler sağlar.
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 |
---|---|
Bottom | , alt metin hizalamasını temsil eder |
Center | , merkez metin hizalamasını temsil eder |
CenterAcross | , metin hizalamasını çapraz merkezlemeyi temsil eder |
Distributed | , dağıtılmış metin hizalamasını temsil eder |
Fill | , doldurma metin hizalamasını temsil eder |
General | , genel metin hizalamasını temsil eder |
Justify | , düzgün metin hizalamasını temsil eder |
Left | , sol metin hizalamasını temsil eder |
Right | , sağ metin hizalamasını temsil eder |
Top | , üst metin hizalamasını temsil eder |
JustifiedLow | , Arapça metin için ayarlanmış bir kashida uzunluğuyla metni hizalar. |
ThaiDistributed | , Özellikle Tayland metnini dağıtır, çünkü her karakter bir kelime olarak kabul edilir. |
Yatay, Dikey Hiza ve Girinti
Metni yatay hizalamak için HorizontalAlignment özelliğini ve metni dikey hizalamak için VerticalAlignment özelliğini kullanın. Bir hücrede metnin girinti düzeyini IndentLevel özelliği ile ayarlamak mümkündür. Ve yalnızca yatay hizalama sol veya sağ olduğunda etkilidir.
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
// Obtaining the reference of first worksheet | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Accessing the "A1" cell from the worksheet | |
Cell cell = worksheet.getCells().get("A1"); | |
// Adding some value to the "A1" cell | |
cell.putValue("Visit Aspose!"); | |
// Setting the horizontal alignment of the text in the "A1" cell | |
Style style = cell.getStyle(); | |
//Set text left horizontal alignment | |
style.setHorizontalAlignment(TextAlignmentType.RIGHT); | |
//Set indent | |
style.setIndentLevel(4); | |
//Set text top vertical alignment | |
style.setVerticalAlignment(TextAlignmentType.TOP); | |
cell.setStyle(style); | |
// Saving the Excel file | |
workbook.save("book1.xlsx"); |
Yönlendirme
Bir hücrede metnin yönlendirmesini (döndürme) RotationAngle özelliği ile ayarlayın.
// Accessing the "A1" cell from the worksheet | |
Cell cell = worksheet.getCells().get("A1"); | |
// Adding some value to the "A1" cell | |
cell.putValue("Visit Aspose!"); | |
// Setting the horizontal alignment of the text in the "A1" cell | |
Style style = cell.getStyle(); | |
// Setting the rotation of the text (inside the cell) to 25 | |
style.setRotationAngle(25); | |
cell.setStyle(style); | |
//Accessing the "A2" cell from the worksheet | |
cell = worksheet.getCells().get("A2"); | |
// Adding some value to the "A1" cell | |
cell.putValue("Visit Aspose!"); | |
// Setting the horizontal alignment of the text in the "A2" cell | |
style = cell.getStyle(); | |
// Setting the orientation of the text from top to bottom | |
style.setRotationAngle(255); | |
cell.setStyle(style); | |
// Saving the Excel file | |
workbook.save("book1.xlsx"); |
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
Bir hücredeki metni kaydırmak metni okumayı kolaylaştırır: hücrenin yüksekliği, metni kesmek yerine veya bitişik hücrelere taşmak yerine tüm metni sığdırmak için ayarlanır. Metin kaydırma özelliği ile metin kaydırma açık veya kapalı olarak ayarlayın.
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
// Obtaining the reference of first worksheet | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Accessing the "A1" cell from the worksheet | |
Cell cell = worksheet.getCells().get("A1"); | |
// Adding some value to the "A1" cell | |
cell.putValue("I am using the latest version of Aspose.Cells to test this functionality."); | |
// Gets style | |
Style style = cell.getStyle(); | |
// Wrap Cell's Text wrap | |
style.setTextWrapped( true); | |
//Set style. | |
cell.setStyle(style); | |
// Saving the Excel file | |
workbook.save("book1.xlsx"); |
Sığdırmayı Daraltma
Bir alanda metni kaydırmak için bir seçenek, metni bir hücrenin boyutlarına sığdırmak için metin boyutunu küçültmektir. Bu, ShrinkToFit özelliğini true olarak ayarlayarak yapılır.
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
// Obtaining the reference of first worksheet | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Accessing the "A1" cell from the worksheet | |
Cell cell = worksheet.getCells().get("A1"); | |
// Adding some value to the "A1" cell | |
cell.putValue("I am using the latest version of Aspose.Cells to test this functionality."); | |
// Gets style in the "A1" cell | |
Style style = cell.getStyle(); | |
// Shrinking the text to fit according to the dimensions of the cell | |
style.setShrinkToFit(true); | |
cell.setStyle(style); | |
// Saving the Excel file | |
workbook.save("book1.xlsx"); | |
Hücreleri Birleştirme
Microsoft Excel gibi, Aspose.Cells birçok hücreyi tek bir hücre olarak birleştirmeyi destekler. Aspose.Cells bu görevi yerine getirmek için iki yaklaşım sağlar. Bu görevi yerine getirmenin bir yolu Merge yöntemini çağırmaktır. Yöntem, 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ı.
// Create a Cells object ot fetch all the cells. | |
Cells cells = worksheet.getCells(); | |
// Merge some Cells (C6:E7) into a single C6 Cell. | |
cells.merge(5, 2, 2, 3); | |
// Input data into C6 Cell. | |
worksheet.getCells().get(5, 2).putValue("This is my value"); | |
// Create a Style object to fetch the Style of C6 Cell. | |
Style style = worksheet.getCells().get(5, 2).getStyle(); | |
// Create a Font object | |
Font font = style.getFont(); | |
// Set the name. | |
font.setName("Times New Roman"); | |
// Set the font size. | |
font.setSize(18); | |
// Set the font color | |
font.setColor(Color.getBlue()); | |
// Bold the text | |
font.setBold(true); | |
// Make it italic | |
font.setItalic(true); | |
// Set the backgrond color of C6 Cell to Red | |
style.setForegroundColor(Color.getRed()); | |
style.setPattern(BackgroundType.SOLID); | |
// Apply the Style to C6 Cell. | |
cells.get(5, 2).setStyle(style); | |
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ı TextDirection özelliği ile ayarlanır. Aspose.Cells, TextDirectionType numaralı numaralandırmada önceden tanımlanmış metin yönü tiplerini sağlar.
Metin Yönü Türleri | Açıklama |
---|---|
Context | Girilen ilk karakterin diline uygun okuma sırası |
LeftToRight | Soldan sağa okuma sırası |
RightToLeft | Sağdan sola okuma sırası |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
// Obtaining the reference of first worksheet | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Accessing the "A1" cell from the worksheet | |
Cell cell = worksheet.getCells().get("A1"); | |
// Adding some value to the "A1" cell | |
cell.putValue("I am using the latest version of Aspose.Cells to test this functionality."); | |
// Gets style in the "A1" cell | |
Style style = cell.getStyle(); | |
// Shrinking the text to fit according to the dimensions of the cell | |
style.setTextDirection(TextDirectionType.LEFT_TO_RIGHT); | |
cell.setStyle(style); | |
// Saving the Excel file | |
workbook.save("book1.xlsx"); |