Back to Devexpress

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

windowsforms-15483-controls-and-libraries-spreadsheet-examples-cells-how-to-clear-cells-of-content-formatting-hyperlinks-and-comments.md

latest2.4 KB
Original Source

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

  • Dec 09, 2022
  • 2 minutes to read

This example demonstrates how to clear worksheet cells.

  • Clear All

  • Clear Cell Content

  • Clear Cell Formatting

  • Clear Cell Hyperlinks

  • Clear Cell Comments

View Example

csharp
// 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"]);
vb
' Remove all cell information (content, formatting, hyperlinks and comments).
worksheet.Clear(worksheet("C2:D2"))

' Remove cell content.
worksheet.ClearContents(worksheet("C3"))
worksheet("D3").Value = Nothing

' Remove cell formatting.
worksheet.ClearFormats(worksheet("C4"))
worksheet("D4").Style = workbook.Styles.DefaultStyle

' Remove hyperlinks from cells.
worksheet.ClearHyperlinks(worksheet("C5"))

Dim hyperlinkD5 As Hyperlink = 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.

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

How to: Delete a Cell or Range of Cells