Copy Sparkline by Specifying Data Range and Location of Sparkline Group
To copy a sparkline to other cells in Microsoft Excel:
- Select the cell containing the sparkline.
- Select Edit Data from the Sparkline section of the Design tab.
- Select Edit Group Location & Data.
- Specify the data range and location.
- Click OK.
Aspose.Cells 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.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create workbook from source Excel file | |
Workbook workbook = new Workbook(dataDir + "source.xlsx"); | |
// Access first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Access the first sparkline group | |
SparklineGroup group = worksheet.SparklineGroups[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"); |