Ausrichtungseinstellungen
Ausrichtungseinstellungen konfigurieren
Ausrichtungseinstellungen in Microsoft Excel
Jeder, der Microsoft Excel zum Formatieren von Zellen verwendet hat, ist mit den Ausrichtungseinstellungen in Microsoft Excel vertraut.
Wie Sie der obigen Abbildung entnehmen können, gibt es verschiedene Ausrichtungsoptionen:
- Textausrichtung (horizontal & vertikal)
- Vertiefung.
- Orientierung.
- Textkontrolle.
- Textrichtung.
Alle diese Ausrichtungseinstellungen werden von Aspose.Cells vollständig unterstützt und unten ausführlicher erläutert.
Ausrichtungseinstellungen in Aspose.Cells
Aspose.Cells bietet eine Klasse,Arbeitsmappe , die eine Excel-Datei darstellt. DasArbeitsmappe Klasse enthält aArbeitsblätter Sammlung, die den Zugriff auf jedes Arbeitsblatt in der Excel-Datei ermöglicht. Ein Arbeitsblatt wird durch dargestelltArbeitsblatt Klasse. DasArbeitsblatt Klasse bietet aCells Sammlung. Jeder Artikel in derCells Sammlung stellt ein Objekt derCellKlasse.
Aspose.Cells bietetGetStyle undSetStyle Methoden für dieCell Klasse, die zum Abrufen und Festlegen der Formatierung einer Zelle verwendet werden. DasStil-Klasse bietet nützliche Eigenschaften zum Konfigurieren von Ausrichtungseinstellungen.
Wählen Sie mithilfe von einen beliebigen Textausrichtungstyp ausTextausrichtungstyp Aufzählung. Die vordefinierten Textausrichtungstypen in derTextausrichtungstypAufzählung sind:
Textausrichtungstypen | Beschreibung |
---|---|
Unterseite | Stellt die untere Textausrichtung dar |
Center | Stellt die zentrierte Textausrichtung dar |
CenterAcross | Stellt die Mitte über der Textausrichtung dar |
Verteilt | Stellt die verteilte Textausrichtung dar |
Füllen | Stellt die Fülltextausrichtung dar |
Allgemein | Stellt die allgemeine Textausrichtung dar |
Rechtfertigen | Stellt die Textausrichtung im Blocksatz dar |
Links | Stellt die linke Textausrichtung dar |
Recht | Stellt die rechte Textausrichtung dar |
oben | Stellt die obere Textausrichtung dar |
GerechtfertigtNiedrig | Richtet den Text mit einer angepassten Kashida-Länge für arabischen Text aus. |
ThaiDistributed | Verteilt besonders thailändischen Text, da jedes Zeichen als Wort behandelt wird. |
Horizontale Ausrichtung
Verwenden Sie dieStil ObjektHorizontale Ausrichtung-Eigenschaft, um den Text horizontal auszurichten.
// 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); |
Vertikale Ausrichtung
Verwenden Sie ähnlich wie bei der horizontalen Ausrichtung dieStil ObjektVertikale Ausrichtung-Eigenschaft, um den Text vertikal auszurichten.
// 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); |
Vertiefung
Es ist möglich, die Einzugsebene des Textes in einer Zelle mit einzustellenStil ObjektEinzugsebeneEigentum.
// 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); |
Orientierung
Stellen Sie die Ausrichtung (Drehung) des Textes in einer Zelle mit einStil ObjektDrehwinkelEigentum.
// 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); |
Textsteuerung
Im folgenden Abschnitt wird erläutert, wie Sie Text steuern, indem Sie Textumbruch, Anpassen verkleinern und andere Formatierungsoptionen festlegen.
Textumbruch
Das Umbrechen von Text in einer Zelle erleichtert das Lesen: Die Höhe der Zelle passt sich an den gesamten Text an, anstatt ihn abzuschneiden oder in benachbarte Zellen zu überlaufen. Stellen Sie den Textumbruch mit ein oder ausStil ObjektIsTextWrappedEigentum.
// 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"); |
Schrumpfen, um zu passen
Eine Option zum Umbrechen von Text in einem Feld besteht darin, die Textgröße zu verkleinern, um sie an die Abmessungen einer Zelle anzupassen. Dies geschieht durch die Einstellung vonStil ObjektIsTextWrapped Eigentum zuwahr.
// 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); |
Cells zusammenführen
Wie Microsoft Excel unterstützt Aspose.Cells das Zusammenführen mehrerer Zellen zu einer. Aspose.Cells bietet zwei Ansätze für diese Aufgabe. Eine Möglichkeit ist, die anzurufenCells SammlungVerschmelzen Methode. DasVerschmelzenDie Methode benötigt die folgenden Parameter, um die Zellen zusammenzuführen:
- Erste Reihe: Die erste Reihe, ab der mit dem Zusammenführen begonnen werden soll.
- Erste Spalte: Die erste Spalte, ab der mit dem Zusammenführen begonnen werden soll.
- Anzahl der Zeilen: Die Anzahl der zusammenzuführenden Zeilen.
- Anzahl der Spalten: Die Anzahl der zusammenzuführenden Spalten.
// 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"); |
Der andere Weg ist, zuerst die anzurufenCells SammlungBereich erstellen -Methode, um einen Bereich der zu verbindenden Zellen zu erstellen. DasBereich erstellen -Methode verwendet denselben Satz von Parametern wie die derVerschmelzen oben diskutierte Methode und gibt a zurückBereich Objekt. DasBereich Objekt bietet auch aVerschmelzen Methode, die den in der angegebenen Bereich zusammenführtBereichObjekt.
Textrichtung
Es ist möglich, die Lesereihenfolge von Text in Zellen festzulegen. Die Lesereihenfolge ist die visuelle Reihenfolge, in der Zeichen, Wörter usw. angezeigt werden. Zum Beispiel ist Englisch eine Sprache von links nach rechts, während Arabisch eine Sprache von rechts nach links ist.
Die Lesereihenfolge wird mit eingestelltStil ObjektTextrichtung Eigentum. Aspose.Cells bietet vordefinierte Textrichtungstypen in derTextrichtungstypAufzählung.
Textrichtungstypen | Beschreibung |
---|---|
Kontext | Die Lesereihenfolge in Übereinstimmung mit der Sprache des ersten eingegebenen Zeichens |
Links nach rechts | Lesereihenfolge von links nach rechts |
Rechts nach links | Lesereihenfolge von rechts nach links |
// 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"); |