How to: Delete Sparklines

  • 2 min to read

The examples below demonstrate how to remove sparkline groups or individual sparklines from a worksheet.

Delete a Sparkline Group

To remove a sparkline group, call the SparklineGroupCollection.Remove or SparklineGroupCollection.RemoveAt method of the SparklineGroupCollection object that is accessed from the Worksheet.SparklineGroups property.


SparklineGroupCollection sparklineGroups = worksheet.SparklineGroups;
// Create a line sparkline group.
SparklineGroup lineGroup = sparklineGroups.Add(worksheet["G4:G7"], worksheet["C4:F4,C5:F5,C6:F6,C7:F7"], SparklineGroupType.Line);
// Create a column sparkline group.
SparklineGroup columnGroup = sparklineGroups.Add(worksheet["G8"], worksheet["C8:F8"], SparklineGroupType.Column);

// Delete the line sparkline group from the collection.
sparklineGroups.RemoveAt(0);

// Delete the column sparkline group from the collection.
sparklineGroups.Remove(columnGroup);

You can also use the SparklineGroup.Delete method to delete the required sparkline group from the collection.


columnGroup.Delete();

To remove all sparkline groups from the worksheet at once, call the SparklineGroupCollection.Clear method.


sparklineGroups.Clear();

Delete a Single Sparkline

To remove an individual sparkline (defined by the Sparkline object) from a sparkline group, call the SparklineCollection.Remove or SparklineCollection.RemoveAt method of the SparklineCollection collection accessed from the SparklineGroup.Sparklines property of the SparklineGroup object that stores the sparkline you wish to delete.

You can also use the Sparkline.Delete method to delete the required sparkline from the sparkline collection.


// Create a group of line sparklines.
SparklineGroup lineGroup = worksheet.SparklineGroups.Add(worksheet["G4:G7"], worksheet["C4:F4,C5:F5,C6:F6,C7:F7"], SparklineGroupType.Line);

// Remove the first sparkline in the group.
lineGroup.Sparklines.RemoveAt(0);

// Remove the last sparkline in the group.
lineGroup.Sparklines[2].Delete();
See Also