Table of Contents

Sparklines

XlsxDocumentSheet.Sparklines lists a sheet's sparkline groups: each group's type (line, column, win/loss), its sparklines (a cell and the range it draws), the points it marks and its colour. A group is added as Excel's Sparklines command adds one, and removed. Measured against Excel: listed as Excel lists them, and written as Excel writes them.

dotnet add package DocWright.Spreadsheet

List a sheet's sparklines

using DocWright.Spreadsheet;

XlsxDocument workbook = XlsxDocument.Open(File.OpenRead("sales-objects.xlsx"));
XlsxDocumentSheet sheet = workbook.FindSheet("Objects")!;
foreach (XlsxSparklineGroup group in sheet.Sparklines)
{
    Console.WriteLine($"{group}: first {group.Sparklines[0]}, markers {group.ShowMarkers}, colour {group.SeriesColor}");
}

Excel lists the newest group first; so does Sparklines.

Add and remove a group

using DocWright.Spreadsheet;

XlsxSparklineGroup trend = sheet.Sparklines.Add(XlsxSparklineType.Line, "Data!B2:E5", "L2:L5");
Console.WriteLine($"added {trend}: {string.Join(", ", trend.Sparklines)}");
Line, 1 sparklines: first J2 = Data!B6:E6, markers False, colour 376092
WinLoss, 4 sparklines: first I2 = Data!B2:E2, markers False, colour 376092
Column, 4 sparklines: first H2 = Data!B2:E2, markers False, colour 376092
Line, 4 sparklines: first G2 = Data!B2:E2, markers True, colour FF0000
added Line, 4 sparklines: L2 = Data!B2:E2, L3 = Data!B3:E3, L4 = Data!B4:E4, L5 = Data!B5:E5

One sparkline is made for each location cell: a column of cells draws the data's rows, a row of cells its columns, one cell the whole of a one-row or one-column range. The group takes Excel's colours. Remove() takes a group off. Download the workbook: sales-sparklines.xlsx.

Sparklines on the printed page

A sheet converted to PDF or images draws its sparklines in their cells as Excel prints them: the values spread across the cell, a line with its markers, columns rising from the lowest value, win/loss blocks above or below the middle, and the high, low, first, last and negative points in their colours. A sparkline's cell is printed even when it holds nothing else, as Excel prints it. See Shapes and text boxes for a converted sheet.