Format Rows and Columns
Working with Rows
Adjusting Row Height
Aspose.Cells provides a class, Workbook, that represents a Microsoft Excel file. The Workbook class contains a WorksheetCollection 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 that represents all cells in the worksheet.
The Cells collection provides several methods to manage rows or columns in a worksheet. Some of these are discussed below in more detail.
Setting the Height of a Row
It is possible to set the height of a single row by calling the Cells collection’s SetRowHeight method. The SetRowHeight method takes the following parameters as follows:
- Row index, the index of the row that you’re changing the height of.
- Row height, the row height to apply on the row.
Setting the Height of All Rows in a Worksheet
If developers need to set the same row height for all rows in the worksheet, they can do it by using the StandardHeight property of the Cells collection.
Example:
Working with Columns
Setting the Width of a Column
Set the width of a column by calling the Cells collection’s SetColumnWidth method. The SetColumnWidth method takes the following parameters:
- Column index, the index of the column that you’re changing the width of.
- Column width, the desired column width.
Setting Column Width in Pixels
Set the width of a column by calling the Cells collection’s SetColumnWidthPixel method. The SetColumnWidthPixel method takes the following parameters:
- Column index, the index of the column that you’re changing the width of.
- Column width, the desired column width in pixels.
Setting the Width of All Columns in a Worksheet
To set the same column width for all columns in the worksheet, use the Cells collection’s StandardWidth property.
Advance topics
- AutoFit Rows and Columns
- Convert Text to Columns using Aspose.Cells
- Copying Rows and Columns
- Delete Blank Rows and Columns in a Worksheet
- Grouping and Ungrouping Rows and Columns
- Hiding and Showing Rows and Columns
- Insert or Delete Rows in an Excel Worksheet
- Inserting and Deleting Rows and Columns of Excel file
- Remove duplicate rows in a Worksheet
- Update references in other worksheets while deleting blank columns and rows in a worksheet