Skip to main content

How to: Clear Cells of Content, Formatting, Hyperlinks and Comments

  • 2 minutes to read

This example demonstrates how to clear worksheet cells.

View Example

// Remove all cell information (content, formatting, hyperlinks and comments).
worksheet.Clear(worksheet["C2:D2"]);

// Remove cell content.
worksheet.ClearContents(worksheet["C3"]);
worksheet["D3"].Value = null;

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

// Remove hyperlinks from cells.
worksheet.ClearHyperlinks(worksheet["C5"]);

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

// Remove comments from cells.
worksheet.ClearComments(worksheet["C6"]);

The image below shows how cells can be cleared.

SpreadsheetControl_ClearCells

To delete an entire cell or a range of cells from the worksheet, use the Worksheet.DeleteCells method (see the How to: Delete a Cell or Range of Cells example).

See Also