This article provides a guide on how to insert sparklines in Excel using C#. It has the details to see the development environment, steps to develop the application, and a sample code for displaying Excel sparklines charts using C#. You will learn to customize the sparklines charts by setting various parameters.
Steps to Add Sparklines in Excel using C#
- Set the environment to use Aspose.Cells for .NET to add sparklines
- Create an Excel file using Workbook class, access a sheet, and file sample data
- Create a cell area providing the start row, start column, end row, and end column
- Add a SparklineGroup using the Add method in the Worksheet.SparklineGroups collection class
- Add a Sparkline in the newly added group by providing the data range, row, and column
- Create a color using Workbook.CreateCellsColor() method and set it to SparklineGroup.SeriesColor
- Save the output
These steps summarize how to add a sparkline in Excel using C#. Create or load a workbook with sample data and define a cell area around the target data. Add sparkline group of type SparklineType.Line, data range, flag for vertical data, and cell area. Finally, add the sparkline to the group and set its color before saving the resultant Workbook.
Code to Create Sparklines in Excel using C#
The above code demonstrates the process of adding Excel sparklines using C#. You can show the high and low points by setting the ShowHighPoint and ShowLowPoint properties to true for the group. Similarly, you may set the line weight bay setting the LineWeight property of the group to a numeric value such as 1, or use style by setting the PresetStyle property in the group to SparklinePresetStyleType.Style10 etc.
This article has taught us how to use sparklines in Excel using C#. To apply conditional formatting in Excel, refer to the article on how to apply conditional formatting in Excel in C#.