Copy Sparkline by Specifying Data Range and Location of Sparkline Group

Contents
[ ]

To copy a sparkline to other cells in Microsoft Excel:

  1. Select the cell containing the sparkline.
  2. Select Edit Data from the Sparkline section of the Design tab.
  3. Select Edit Group Location & Data.
  4. Specify the data range and location.
  5. Click OK.

Aspose.Cells for Python via .NET provides the SparklineCollection.Add(dataRange, row, column) method to specify a sparkline group’s data range and location. The following sample code loads the source Excel file as shown in the screenshot above, then accesses the first sparkline group and adds data ranges and locations in the sparkline group. Finally, it writes the output Excel file on disk which is also shown in the screenshot above.

from aspose.cells import Workbook
# 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(".")
# Create workbook from source Excel file
workbook = Workbook(dataDir + "source.xlsx")
# Access first worksheet
worksheet = workbook.worksheets[0]
# Access the first sparkline group
group = worksheet.sparkline_groups[0]
# Add Data Ranges and Locations inside this sparkline group
group.sparklines.add("D5:O5", 4, 15)
group.sparklines.add("D6:O6", 5, 15)
group.sparklines.add("D7:O7", 6, 15)
group.sparklines.add("D8:O8", 7, 15)
# Save the workbook
workbook.save(dataDir + "output_out.xlsx")