Insert Sparkline

Insert a sparkline

It’s simple to create a sparkline with Aspose.Cells for Python via .NET with the following example codes:

from aspose.cells import CellArea, Workbook
from aspose.cells.charts import SparklineType
from aspose.pydrawing import Color
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# The path to the documents directory.
dataDir = RunExamples.GetDataDir(".")
# Instantiating a Workbook object
book = Workbook()
sheet = book.worksheets[0]
sheet.cells.get("A1").put_value(5)
sheet.cells.get("B1").put_value(2)
sheet.cells.get("C1").put_value(1)
sheet.cells.get("D1").put_value(3)
# Define the CellArea
ca = CellArea()
ca.start_column = 4
ca.end_column = 4
ca.start_row = 0
ca.end_row = 0
idx = sheet.sparkline_groups.add(SparklineType.LINE, sheet.name + "!A1:D1", False, ca)
group = sheet.sparkline_groups[idx]
group.sparklines.add(sheet.name + "!A1:D1", 0, 4)
#region Customize Sparklines
# Create CellsColor
clr = book.create_cells_color()
clr.color = Color.orange
group.series_color = clr
# set the high points are colored green and the low points are colored red
group.show_high_point = True
group.show_low_point = True
group.high_point_color.color = Color.green
group.low_point_color.color = Color.red
# set line weight
group.line_weight = 1.0
# you also can choose a nice visual style
# group.PresetStyle = SparklinePresetStyleType.Style10;
#endregion Customize Sparklines
# Saving the Excel file
book.save(dataDir + "output.xlsx")

Advance topics