)
We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to export the sparkline column to excel in the WinForms GridGroupingControl?

Platform: WinForms |
Control: GridGroupingControl |
Published Date: January 27, 2015 |
Last Revised Date: December 23, 2019

Excel export

By default, GridGroupingControl does not have Grid-like support for exporting the Sparkline cells to Excel. But Sparkline cells also can be exported by the following customization.

The Sparkline column or cells in the GridGroupingControl can be exported to Excel by defining the Sparkline Groups in the Excel sheet while exporting. ISparklineGroups interface is used for defining the Sparkline group in the Excel sheet.

ISparklineGroups interface caches the SparklineGroup that needs to be added to the Excel sheet. The Sparklines appears once you select the Data range and the Location range. Data range and Reference range for the Sparkline in Excel can be determined and assigned in QueryImportExportCellInfo event.

C#

void converter_QueryImportExportCellInfo(object sender, GridImportExportCellInfoEventArgs e)
{
   if (e.Action == GridConverterAction.Export)
   {
      GridTableCellStyleInfoIdentity id = e.GridCell.CellIdentity as GridTableCellStyleInfoIdentity;
      if (id != null && id.Column != null && id.DisplayElement.IsRecord() &&
e.GridCell.CellType == GridCellTypeName.Control && e.GridCell.Control is SparkLine)
      {
          ISparklineGroup sparklineGroup = e.ExcelCell.Worksheet.SparklineGroups.Add();
          sparklineGroup.SparklineType = SparklineType.Line;
          ISparklines sparklines = sparklineGroup.Add();
          //Specify your needed Column index for starting range
          string startRange = GridRangeInfo.GetAlphaLabel(e.ExcelCell.Column - 3) + e.ExcelCell.Row.ToString();
          //Specify your needed Column index for end range
          string endRange = GridRangeInfo.GetAlphaLabel(e.ExcelCell.Column - 1) + e.ExcelCell.Row.ToString();
          IRange dataRange = e.ExcelCell.Worksheet.Range[startRange + ":" + endRange];
          IRange referenceRange = e.ExcelCell;
          //Adding Sparkline in excel sheet range
          sparklines.Add(dataRange, referenceRange);
          e.Handled = true;
      }
   }
}

VB

Private Sub converter_QueryImportExportCellInfo(ByVal sender As Object, GridImportExportCellIn- ByVal e As foEventArgs)
   If e.Action = GridConverterAction.Export Then
   Dim id As GridTableCellStyleInfoIdentity = TryCast(e.GridCell.CellIdentity, GridTableCellStyleInfoI)-dentity
   If id IsNot Nothing AndAlso id.Column IsNot Nothing AndAlso id.DisplayElement.IsRecord() AndAlso e.GridCell.CellType Is GridCellTypeName.Control AndAlso TypeOf e.GridCell.Control Is SparkLine Then
      Dim sparklineGroup As ISparklineGroup = e.ExcelCell.Worksheet.SparklineGroups.Add()
       sparklineGroup.SparklineType = SparklineType.Line
      Dim sparklines As ISparklines = sparklineGroup.Add()
      'Specify your needed Column index for starting range
      Dim startRange As String = GridRangeInfo.GetAlphaLabel(e.ExcelCell.Column - 3) + e.ExcelCell.Row.ToString()
      'Specify your needed Column index for end range
      Dim endRange As String = GridRangeInfo.GetAlphaLabel(e.ExcelCell.Column - 1) + e.ExcelCell.Row.ToString()
      Dim dataRange As IRange = e.ExcelCell.Worksheet.Range(startRange & ":" & endRange)
      Dim referenceRange As IRange = e.ExcelCell
      'Adding Sparkline in excel sheet range
      sparklines.Add(dataRange, referenceRange)
      e.Handled = True
   End If
   End If
End Sub

Screenshots:

Sparkline in GridGroupingControl

Figure 1: Sparkline in GridGroupingControl

 

Sparkline in Excelsheet

Figure 2: Sparkline in ExcelSheet (Exported)

Samples:

C#: Export SparkLine CS

VB: Export SparkLine VB

Reference link: https://help.syncfusion.com/windowsforms/classic/gridgroupingcontrol/exporting

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon