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, bir 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ı, bir Cells koleksiyonu sağlar. Cells koleksiyonundaki her öğe, Cell sınıfının bir örneğini temsil eder.
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 Hizalama
Metni yatay olarak hizalamak için Style nesnesinin HorizontalAlignment özelliğini 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); | |
// 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 worksheet | |
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!"); | |
// Setting the horizontal alignment of the text in the "A1" cell | |
Style style = cell.GetStyle(); | |
style.HorizontalAlignment = TextAlignmentType.Center; | |
cell.SetStyle(style); | |
// Saving the Excel file | |
workbook.Save(dataDir + "book1.out.xls", SaveFormat.Excel97To2003); |
Dikey Hizalama
Yatay hizalama ile benzer şekilde metni dikey olarak hizalamak için Style nesnesinin VerticalAlignment özelliğini 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); | |
// 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(); | |
// Clearing all the worksheets | |
workbook.Worksheets.Clear(); | |
// 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 | |
Aspose.Cells.Cell cell = worksheet.Cells["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 vertical alignment of the text in a cell | |
style.VerticalAlignment = TextAlignmentType.Center; | |
cell.SetStyle(style); | |
// Saving the Excel file | |
workbook.Save(dataDir + "book1.out.xls", SaveFormat.Excel97To2003); |
Girinti
Hücredeki metnin girinti seviyesini Style nesnesinin IndentLevel özelliği ile ayarlamak mümkündü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(); | |
// Obtaining the reference of the worksheet | |
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!"); | |
// Setting the horizontal alignment of the text in the "A1" cell | |
Style style = cell.GetStyle(); | |
// Setting the indentation level of the text (inside the cell) to 2 | |
style.IndentLevel = 2; | |
cell.SetStyle(style); | |
// Saving the Excel file | |
workbook.Save(dataDir + "book1.out.xls", SaveFormat.Excel97To2003); |
Yönlendirme
Hücrede metnin yönlendirmesini (döndürme) Style nesnesinin RotationAngle özelliği ile ayarlayı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 worksheet | |
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!"); | |
// 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.RotationAngle = 25; | |
cell.SetStyle(style); | |
// Saving the Excel file | |
workbook.Save(dataDir + "book1.out.xls", SaveFormat.Excel97To2003); |
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 IsTextWrapped özelliği ile açın veya kapatı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 Workbook Object | |
Workbook wb = new Workbook(); | |
// Open first Worksheet in the workbook | |
Worksheet ws = wb.Worksheets[0]; | |
// Get Worksheet Cells Collection | |
Aspose.Cells.Cells cell = ws.Cells; | |
// Increase the width of First Column Width | |
cell.SetColumnWidth(0, 35); | |
// Increase the height of first row | |
cell.SetRowHeight(0, 36); | |
// Add Text to the Firts Cell | |
cell[0, 0].PutValue("I am using the latest version of Aspose.Cells to test this functionality"); | |
// Make Cell's Text wrap | |
Style style = cell[0, 0].GetStyle(); | |
style.IsTextWrapped = true; | |
cell[0, 0].SetStyle(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 IsTextWrapped özelliği ile ayarlanı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(); | |
// Obtaining the reference of the worksheet | |
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!"); | |
// Setting the horizontal alignment of the text in the "A1" cell | |
Style style = cell.GetStyle(); | |
// Shrinking the text to fit according to the dimensions of the cell | |
style.ShrinkToFit = true; | |
cell.SetStyle(style); | |
// Saving the Excel file | |
workbook.Save(dataDir + "book1.out.xls", SaveFormat.Excel97To2003); |
Hücreleri Birleştirme
Microsoft Excel gibi, Aspose.Cells birkaç hücreyi birleştirme işlemine destek verir. Aspose.Cells bu göreve iki yaklaşım sağlar. Bir yol, Cells koleksiyonunun Merge yöntemini çağırmaktır. Merge yöntemi 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ı.
// 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); | |
// Create a Workbook. | |
Workbook wbk = new Workbook(); | |
// Create a Worksheet and get the first sheet. | |
Worksheet worksheet = wbk.Worksheets[0]; | |
// Create a Cells object ot fetch all the cells. | |
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[5, 2].PutValue("This is my value"); | |
// Create a Style object to fetch the Style of C6 Cell. | |
Style style = worksheet.Cells[5, 2].GetStyle(); | |
// Create a Font object | |
Font font = style.Font; | |
// Set the name. | |
font.Name = "Times New Roman"; | |
// Set the font size. | |
font.Size = 18; | |
// Set the font color | |
font.Color = System.Drawing.Color.Blue; | |
// Bold the text | |
font.IsBold = true; | |
// Make it italic | |
font.IsItalic = true; | |
// Set the backgrond color of C6 Cell to Red | |
style.ForegroundColor = System.Drawing.Color.Red; | |
style.Pattern = BackgroundType.Solid; | |
// Apply the Style to C6 Cell. | |
cells[5, 2].SetStyle(style); | |
// Save the Workbook. | |
wbk.Save(dataDir + "mergingcells.out.xls"); |
Diğer yol, öncelikle Cells koleksiyonunun CreateRange yöntemini çağırmak ve birleştirilecek hücrelerin aralığını oluşturmaktır. CreateRange 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 TextDirection özelliği ile ayarlanır. Aspose.Cells, TextDirectionType numaralandırmasında önceden tanımlanmış metin yönü türlerini 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.Worksheets[0]; | |
// Accessing the "A1" cell from the worksheet | |
Cell cell = worksheet.Cells["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.TextDirection = (TextDirectionType.LeftToRight); | |
cell.SetStyle(style); | |
// Saving the Excel file | |
workbook.Save("book1.xlsx"); |