Configuring Alignment Settings
Alignment settings in Microsoft Excel
Anyone who has used Microsoft Excel to format cells will be familiar with the alignment settings in Microsoft Excel.
As you can see from the above figure, there are different kinds of alignment options:
- Text alignment(horizontal & vertical)
- Text control.
- Text direction.
All of these alignment settings are fully supported by Aspose.Cells and are discussed in more detail below.
Alignment settings in Aspose.Cells
Aspose.Cells provides a class, Workbook, that represents an Excel file. The Workbook class contains a Worksheets collection that allows access to each worksheet in the Excel file. A worksheet is represented by the Worksheet class. The Worksheet class provides a Cells collection. Each item in the Cells collection represents an object of the Cell class.
|Text Alignment Types||Description|
|Bottom||Represents bottom text alignment|
|Center||Represents center text alignment|
|CenterAcross||Represents center across text alignment|
|Distributed||Represents distributed text alignment|
|Fill||Represents fill text alignment|
|General||Represents general text alignment|
|Justify||Represents justify text alignment|
|Left||Represents left text alignment|
|Right||Represents right text alignment|
|Top||Represents top text alignment|
|JustifiedLow||Aligns the text with an adjusted kashida length for Arabic text.|
|ThaiDistributed||Distributes Thai text especially, because each character is treated as a word.|
The following section discusses how to control text by setting text wrapping, shrink to fit and other formatting options.
Wrapping text in a cell makes it easier to read: the height of the cell adjusts to fit all the text, instead of cutting it off or spilling over into adjacent cells. Set text wrapping on or off with the Style object’s IsTextWrapped property.
Shrinking to Fit
Like Microsoft Excel, Aspose.Cells supports merging several cells into one. Aspose.Cells provides two approaches to this task. One way is to call the Cells collection’s Merge method. The Merge method takes the following parameters to merge the cells:
- First row: the first row from where to start merging.
- First column: the first column from where to start merging.
- Number of rows: the number of rows to merge.
- Number of columns: the number of columns to merge.
The other way is to first call the Cells collection’s CreateRange method to create a range of the cells to be merged. The CreateRange method takes the same set of parameters as that of the Merge method discussed above and returns a Range object. The Range object also provides a Merge method that merges the range specified in the Range object.
It is possible to set the reading order of text in cells. The reading order is the visual order in which characters, words, etc. are displayed. For example, English is a left to right language while Arabic is a right to left language.
|Text Direction Types||Description|
|Context||The reading order consistent with the language of the first entered character|
|LeftToRight||Left to right reading order|
|RightToLeft||Right to left reading order|