FlexSheet for WPF allows you to align and indent cells to enhance the appearance of the presented data. Cell alignment can be easily applied using SetCellFormat method and indentation can be applied using SetCellIndent method in C1FlexSheet.
You can change the alignment of data both horizontally and vertically, and apply indentation to the cell contents. Follow the given steps to apply alignment and indentation in cells:
XAML |
Copy Code
|
---|---|
<Button Content="Left Align" Name="_btnLeft" Click="_btnLeft_Click" HorizontalAlignment="Left" VerticalAlignment="Top" Width="60"/> <Button Content="Center Align" Name="_btnCenter" Click="_btnCenter_Click" HorizontalAlignment="Left" VerticalAlignment="Top" Width="85" Margin="78,0,0,0"/> <Button Content="Right Align" Name="_btnRight" Click="_btnRight_Click" HorizontalAlignment="Left" VerticalAlignment="Top" Width="70" Margin="185,0,0,0"/> <Button Content="Top Align" Name="_btnTop" Click="_btnTop_Click" HorizontalAlignment="Left" VerticalAlignment="Top" Width="65" Margin="22,25,0,0"/> <Button Content="Middle Align" Name="_btnMiddle" Click="_btnMiddle_Click" HorizontalAlignment="Left" VerticalAlignment="Top" Width="80" Margin="107,25,0,0"/> <Button Content="Bottom Align" Name="_btnBottom" Click="_btnBottom_Click" HorizontalAlignment="Left" VerticalAlignment="Top" Width="80" Margin="212,25,0,0"/> <Button Content="Decrease Indent" Name="_btnDecreaseIndent" Click="_btnDecreaseIndent_Click" HorizontalAlignment="Right" VerticalAlignment="Top" Width="100" Margin="0,25,10,0"/> <Button Content="Increase Indent" Name="_btnIncreaseIndent" Click="_btnIncreaseIndent_Click" HorizontalAlignment="Right" VerticalAlignment="Top" Width="100" Margin="0,0,10,0"/> |
After adding data to a sheet in C1FlexSheet control, you can choose how to display the data in cells using different types of indentation and alignment.
You can change the horizontal alignment of the data in cell by applying left, centre or right alignment to it. Just select the cell(s) to align the data and you are good to go.
To align the data on the left, use the following code:
Similarly, you can align the cell data on the right or at the center by changing the value of enum HorizontalAlignment from Left to Right or Center.
You can change the vertical alignment of the data in cell by applying top, middle or right alignment to it. Just select the cell(s) to align the data vertically.
To align the data at the top, use the following code:
Similarly, you can align the data in the middle or at the bottom of the cell by changing the value of enum VerticalAlignment from Top to Middle or Bottom.
You can change the indentation of a cell by increasing or decreasing the indent of the selected cell(s). To increase the cell indention, use the following code:
To decrease the cell indention, use the following code: