Change the format of a cell

Possible Usage Scenarios

When you want to highlight certain data, you can change the style of the cells.

How to change the format of a cell in Excel

To change the format of a single cell in Excel, follow these steps:

  1. Open Excel and open the workbook that contains the cell you want to format.

  2. Locate the cell you want to format.

  3. Right-click on the cell and select “Format Cells” from the context menu. Alternatively, you can select the cell and go to the Home tab in the Excel ribbon, click on the “Format” dropdown in the “Cells” group, and select “Format Cells”.

  4. The “Format Cells” dialog box will appear. Here, you can choose various formatting options to apply to the selected cell. For example, you can change the font style, font size, font color, number format, borders, background color, etc. Explore the different tabs in the dialog box to access various formatting options.

  5. After making the desired formatting changes, click the “OK” button to apply the formatting to the selected cell.

How to change the format of a cell Using C#

To change the format of a cell using Aspose.Cells for Python via .NET, you can use You can use the following methods:

  1. Cell.set_style(style)
  2. Cell.set_style(style, explicit_flag)
  3. Cell.set_style(style, flag)

Sample Code

In this example, we create an Excel workbook, add some sample data, access the first worksheet, and get two cells(“A2” and “B3”). Then, we get the style of the cell, set various formatting options (e.g., font color, bold), and change the format to the cell. Finally, we save the workbook to a new file. todo:image_alt_text

from aspose.cells import StyleFlag, Workbook
from aspose.pydrawing import Color
# Create the workbook
workbook = Workbook()
# Get the first worksheet
ws = workbook.worksheets[0]
cells = ws.cells
# Setting the value to the cells
cell = cells.get("A1")
cell.put_value("Fruit")
cell = cells.get("B1")
cell.put_value("Count")
cell = cells.get("C1")
cell.put_value("Price")
cell = cells.get("A2")
cell.put_value("Apple")
cell = cells.get("A3")
cell.put_value("Mango")
cell = cells.get("A4")
cell.put_value("Blackberry")
cell = cells.get("A5")
cell.put_value("Cherry")
cell = cells.get("B2")
cell.put_value(5)
cell = cells.get("B3")
cell.put_value(3)
cell = cells.get("B4")
cell.put_value(6)
cell = cells.get("B5")
cell.put_value(4)
cell = cells.get("C2")
cell.put_value(5)
cell = cells.get("C3")
cell.put_value(20)
cell = cells.get("C4")
cell.put_value(30)
cell = cells.get("C5")
cell.put_value(60)
# Access the worksheet
worksheet = workbook.worksheets[0]
a2 = worksheet.cells.get("A2")
# Get style of A2
style = a2.get_style()
# Change the format
style.font.color = Color.red
style.font.is_bold = True
flag = StyleFlag()
flag.font_color = True
a2.set_style(style, flag)
b3 = worksheet.cells.get("B3")
# Get style of B3
style2 = b3.get_style()
# Change the format
style2.font.color = Color.blue
style2.font.is_italic = True
b3.set_style(style2)
# Save the modified workbook
workbook.save("output.xlsx")