Skip to content

Instantly share code, notes, and snippets.

@aspose-com-kb
Last active June 15, 2024 14:02
Show Gist options
  • Save aspose-com-kb/67dc70c6e4bb5e77aa7669616cc184cf to your computer and use it in GitHub Desktop.
Save aspose-com-kb/67dc70c6e4bb5e77aa7669616cc184cf to your computer and use it in GitHub Desktop.
Insert Sparklines in Excel using C#. For more information: https://kb.aspose.com/cells/net/insert-sparklines-in-excel-using-csharp/
using System.Drawing;
using Aspose.Cells;
using Aspose.Cells.Charts;
class Program
{
static void Main(string[] args)
{
new License().SetLicense("License.lic");
// Instantiating a Workbook object
Workbook wb = new Workbook();
Worksheet sheet = wb.Worksheets[0];
sheet.Cells["A1"].PutValue(10);
sheet.Cells["B1"].PutValue(2);
sheet.Cells["C1"].PutValue(1);
sheet.Cells["D1"].PutValue(3);
// Define the CellArea and add a group
CellArea ca = new CellArea() { StartRow = 0, StartColumn = 4, EndRow = 0, EndColumn = 4 };
int idx = sheet.SparklineGroups.Add(SparklineType.Line, sheet.Name + "!A1:D1", false, ca);
// Access the group and add a spark line
SparklineGroup sparklineGroup = sheet.SparklineGroups[idx];
sparklineGroup.Sparklines.Add(sheet.Name + "!A1:D1", 0, 4);
// Customize the spark line color
CellsColor cellsColor = wb.CreateCellsColor();
cellsColor.Color = Color.Green;
sparklineGroup.SeriesColor = cellsColor;
// Saving the Excel file
wb.Save("output.xlsx");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment