Format Rows and Columns

Working with Rows

How to Adjust Row Height

Aspose.Cells for Python via .NET 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.

How to Set the Height of a Row

It is possible to set the height of a single row by calling the Cells collection’s set_row_height method. The set_row_height method takes the following parameters as follows:

  • row, the index of the row that you’re changing the height of.
  • height, the row height to apply on the row.

How to Set 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 standard_height property of the Cells collection.

Example:

Working with Columns

How to Set the Width of a Column

Set the width of a column by calling the Cells collection’s set_column_width method. The set_column_width method takes the following parameters:

  • column, the index of the column that you’re changing the width of.
  • width, the desired column width.

How to Set Column Width in Pixels

Set the width of a column by calling the Cells collection’s set_column_width_pixel method. The set_column_width_pixel method takes the following parameters:

  • column, the index of the column that you’re changing the width of.
  • pixels, the desired column width in pixels.

How to Set 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 standard_width property.

Advance topics