Skip to main content

How to: Clear Cell Formatting

  • 2 minutes to read

This example demonstrates how to remove all formatting from a cell or range of cells. You can do this in one of the following ways.

  • Call the Worksheet.ClearFormats method with the passed object specifying the cell or cell range to be cleared.
  • Apply the Normal style to a cell or range of cells via the CellRange.Style property.

    The Normal style object can be accessed from the Workbook.Styles collection by the style name (Normal) or index (by default, this style is added as the first in the collection of styles and cannot be deleted), or via the StyleCollection.DefaultStyle property.

View Example

// Remove all cell information (content, formatting, hyperlinks and comments).

// Remove cell content.
worksheet["D3"].Value = null;

// Remove cell formatting.
worksheet["D4"].Style = workbook.Styles.DefaultStyle;

// Remove hyperlinks from cells.

Hyperlink hyperlinkD5 = worksheet.Hyperlinks.GetHyperlinks(worksheet["D5"])[0];

// Remove comments from cells.

Comment commentD6 = worksheet.Comments.GetComments(worksheet["D6"])[0];