The sample demonstrates how to insert SparkLine into an excel workbook.
using Spire.Xls; using System.Drawing; namespace SparkLine { class Program { static void Main(string[] args) { Workbook workbook = new Workbook(); workbook.Version = ExcelVersion.Version2010; workbook.CreateEmptySheets(1); Worksheet sheet = workbook.Worksheets[0]; //Country sheet.Range["A1"].Value = "Country"; sheet.Range["A2"].Value = "Cuba"; sheet.Range["A3"].Value = "Mexico"; sheet.Range["A4"].Value = "France"; sheet.Range["A5"].Value = "German"; //Jun sheet.Range["B1"].Value = "Jun"; sheet.Range["B2"].NumberValue = 0.23; sheet.Range["B3"].NumberValue = 0.37; sheet.Range["B4"].NumberValue = 0.15; sheet.Range["B5"].NumberValue = 0.25; //Jul sheet.Range["C1"].Value = "Jul"; sheet.Range["C2"].NumberValue = 0.1; sheet.Range["C3"].NumberValue = 0.35; sheet.Range["C4"].NumberValue = 0.22; sheet.Range["C5"].NumberValue = 0.33; //Aug sheet.Range["D1"].Value = "Aug"; sheet.Range["D2"].NumberValue = 0.14; sheet.Range["D3"].NumberValue = 0.36; sheet.Range["D4"].NumberValue = 0.25; sheet.Range["D5"].NumberValue = 0.25; //Sep sheet.Range["E1"].Value = "Sep"; sheet.Range["E2"].NumberValue = 0.17; sheet.Range["E3"].NumberValue = 0.28; sheet.Range["E4"].NumberValue = 0.39; sheet.Range["E5"].NumberValue = 0.32; //Style sheet.Range["A1:E1"].Style.Font.IsBold = true; sheet.Range["A2:E2"].Style.KnownColor = ExcelColors.LightYellow; sheet.Range["A3:E3"].Style.KnownColor = ExcelColors.LightGreen1; sheet.Range["A4:E4"].Style.KnownColor = ExcelColors.LightOrange; sheet.Range["A5:E5"].Style.KnownColor = ExcelColors.LightTurquoise; //Border sheet.Range["A1:E5"].Style.Borders[BordersLineType.EdgeTop].Color = Color.FromArgb(0, 0, 128); sheet.Range["A1:E5"].Style.Borders[BordersLineType.EdgeTop].LineStyle = LineStyleType.Thin; sheet.Range["A1:E5"].Style.Borders[BordersLineType.EdgeBottom].Color = Color.FromArgb(0, 0, 128); sheet.Range["A1:E5"].Style.Borders[BordersLineType.EdgeBottom].LineStyle = LineStyleType.Thin; sheet.Range["A1:E5"].Style.Borders[BordersLineType.EdgeLeft].Color = Color.FromArgb(0, 0, 128); sheet.Range["A1:E5"].Style.Borders[BordersLineType.EdgeLeft].LineStyle = LineStyleType.Thin; sheet.Range["A1:E5"].Style.Borders[BordersLineType.EdgeRight].Color = Color.FromArgb(0, 0, 128); sheet.Range["A1:E5"].Style.Borders[BordersLineType.EdgeRight].LineStyle = LineStyleType.Thin; sheet.Range["B2:D5"].Style.NumberFormatIndex = 9; SparklineGroup sparklineGroup = sheet.SparklineGroups.AddGroup(SparklineType.Line); SparklineCollection sparklines = sparklineGroup.Add(); sparklines.Add(sheet["B2:E2"], sheet["F2"]); sparklines.Add(sheet["B3:E3"], sheet["F3"]); sparklines.Add(sheet["B4:E4"], sheet["F4"]); sparklines.Add(sheet["B5:E5"], sheet["F5"]); workbook.SaveToFile("Sample.xlsx"); System.Diagnostics.Process.Start(workbook.FileName); } } }
Imports Spire.Xls Imports System.Drawing Module Module1 Sub Main() Dim workbook As New Workbook() workbook.Version = ExcelVersion.Version2010 workbook.CreateEmptySheets(1) Dim sheet As Worksheet = workbook.Worksheets(0) 'Country sheet.Range("A1").Value = "Country" sheet.Range("A2").Value = "Cuba" sheet.Range("A3").Value = "Mexico" sheet.Range("A4").Value = "France" sheet.Range("A5").Value = "German" 'Jun sheet.Range("B1").Value = "Jun" sheet.Range("B2").NumberValue = 0.23 sheet.Range("B3").NumberValue = 0.37 sheet.Range("B4").NumberValue = 0.15 sheet.Range("B5").NumberValue = 0.25 'Jul sheet.Range("C1").Value = "Jul" sheet.Range("C2").NumberValue = 0.1 sheet.Range("C3").NumberValue = 0.35 sheet.Range("C4").NumberValue = 0.22 sheet.Range("C5").NumberValue = 0.33 'Aug sheet.Range("D1").Value = "Aug" sheet.Range("D2").NumberValue = 0.14 sheet.Range("D3").NumberValue = 0.36 sheet.Range("D4").NumberValue = 0.25 sheet.Range("D5").NumberValue = 0.25 'Sep sheet.Range("E1").Value = "Sep" sheet.Range("E2").NumberValue = 0.17 sheet.Range("E3").NumberValue = 0.28 sheet.Range("E4").NumberValue = 0.39 sheet.Range("E5").NumberValue = 0.32 'Style sheet.Range("A1:E1").Style.Font.IsBold = True sheet.Range("A2:E2").Style.KnownColor = ExcelColors.LightYellow sheet.Range("A3:E3").Style.KnownColor = ExcelColors.LightGreen1 sheet.Range("A4:E4").Style.KnownColor = ExcelColors.LightOrange sheet.Range("A5:E5").Style.KnownColor = ExcelColors.LightTurquoise 'Border sheet.Range("A1:E5").Style.Borders(BordersLineType.EdgeTop).Color = Color.FromArgb(0, 0, 128) sheet.Range("A1:E5").Style.Borders(BordersLineType.EdgeTop).LineStyle = LineStyleType.Thin sheet.Range("A1:E5").Style.Borders(BordersLineType.EdgeBottom).Color = Color.FromArgb(0, 0, 128) sheet.Range("A1:E5").Style.Borders(BordersLineType.EdgeBottom).LineStyle = LineStyleType.Thin sheet.Range("A1:E5").Style.Borders(BordersLineType.EdgeLeft).Color = Color.FromArgb(0, 0, 128) sheet.Range("A1:E5").Style.Borders(BordersLineType.EdgeLeft).LineStyle = LineStyleType.Thin sheet.Range("A1:E5").Style.Borders(BordersLineType.EdgeRight).Color = Color.FromArgb(0, 0, 128) sheet.Range("A1:E5").Style.Borders(BordersLineType.EdgeRight).LineStyle = LineStyleType.Thin sheet.Range("B2:D5").Style.NumberFormatIndex = 9 Dim sparklineGroup As SparklineGroup = sheet.SparklineGroups.AddGroup(SparklineType.Line) Dim sparklines As SparklineCollection = sparklineGroup.Add() sparklines.Add(sheet("B2:E2"), sheet("F2")) sparklines.Add(sheet("B3:E3"), sheet("F3")) sparklines.Add(sheet("B4:E4"), sheet("F4")) sparklines.Add(sheet("B5:E5"), sheet("F5")) workbook.SaveToFile("Sample.xlsx") System.Diagnostics.Process.Start(workbook.FileName) End Sub End Module