Format cells

Introduction

How to Format Cells using GetStyle and SetStyle Methods

Apply different kinds of formatting styles on cells to set background or foreground colors, borders, fonts, horizontal and vertical alignments, indentation level, text direction, rotation angle and much more.

How to Use the GetStyle and SetStyle Methods

If developers need to apply different formatting styles to different cells then it’s better to get the Style of the cell using Cell.get_style method, specify the style attributes and then apply the formatting using Cell.set_style method. An example is given below to demonstrate this approach to apply various formatting on a cell.

How to Use Style Object to Format Different Cells

If developers need to apply the Same formatting style to different cells then they can use Style object. Please follow the steps below to use the Style object:

  1. Add a Style object by calling the create_style method of the Workbook class
  2. Access the newly added Style object
  3. Set the desired properties/attributes of the Style object to apply desired formatting settings
  4. Assign the configured Style object to your desired cells

This approach can greatly improve the efficiency of your applications and save memory too.

How to Use Microsoft Excel 2007 Predefined Styles

If you need to apply different formatting styles for Microsoft Excel 2007, apply styles using the Aspose.Cells for Python via .NET API. An example is given below to demonstrate this approach to apply a predefined style on a cell.

How to Format Selected Characters in a Cell

Dealing with Font Settings explains how to format text in cells, but it only explains how to format all of the cell content. What if you want to format only selected characters?

Aspose.Cells for Python via .NET supports this feature too. This topic explains how to we use this feature effectively.

How to Format Selected Characters

Aspose.Cells for Python via .NET provides a class, Workbook that represents a Microsoft Excel file. The Workbook class contains the worksheets collection that allows access to each worksheet in an 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.

The Cell class provides the characters method that takes the following parameters to select a range of characters inside a cell:

  • Start Index, the index of the character that the selection starts from.
  • Number of Characters, the number of characters to select.

The characters method returns an instance of the FontSetting class that allows developers to format the characters in the same way as they would a cell as shown below in the code example. In the output file, in the A1 cell, the word ‘Visit’ will be formatted with the default font but ‘Aspose!’ is bold and blue.

How to Format Rows and Columns

Sometimes, developers need to apply the same formatting on rows or columns. Applying formatting on cells one by one often takes longer and is not a good solution. To address this issue, Aspose.Cells for Python via .NET provides a simple, fast way discussed in detail in this article.

Formatting Rows & Columns

Aspose.Cells for Python via .NET provides a class, the Workbook that represents a Microsoft 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. The cells collection provides a rows collection.

How to Format a Row

Each item in the rows collection represents a Row object. The Row object offers the apply_style method used to set the row’s formatting. To apply the same formatting to a row, use the Style object. The steps below show how to use it.

  1. Add a Style object to the Workbook class by calling its create_style method.
  2. Set the Style object’s properties to apply formatting settings.
  3. Make the relevant attributes ON for the StyleFlag object.
  4. Assign the configured Style object to the Row object.

How to Format a Column

The cells collection also provides a columns collection. Each item in the columns collection represents a Column object. Similar to a Row object, the Column object also offers the apply_style method for formatting a column.

Advance topics