Back to Devexpress

ChartCollection.AddFromTemplate(Stream, CellRange) Method

officefileapi-devexpress-dot-spreadsheet-dot-charts-dot-chartcollection-dot-addfromtemplate-x28-system-dot-io-dot-stream-devexpress-dot-spreadsheet-dot-cellrange-x29.md

latest3.4 KB
Original Source

ChartCollection.AddFromTemplate(Stream, CellRange) Method

Loads a chart template from the stream, binds it to data from the specified range, and adds the chart to the collection.

Namespace : DevExpress.Spreadsheet.Charts

Assembly : DevExpress.Spreadsheet.v25.2.Core.dll

NuGet Package : DevExpress.Spreadsheet.Core

Declaration

csharp
Chart AddFromTemplate(
    Stream stream,
    CellRange range
)
vb
Function AddFromTemplate(
    stream As Stream,
    range As CellRange
) As Chart

Parameters

NameTypeDescription
streamStream

A stream that contains a chart template in .CRTX format.

| | range | CellRange |

A CellRange that contains chart data.

|

Returns

TypeDescription
Chart

The created chart object.

|

Remarks

A CRTX file contains a chart template that can be applied to a Chart object or added to ChartCollection as a new chart in the Spreadsheet control. The file stores settings for colors, axes, series, gridlines, categories, legends, text, and other chart options. CRTX files are used to apply the same styles and formatting to multiple charts.

The following code snippet shows how to add a chart from a .CRTX file to a workbook:

csharp
using DevExpress.Spreadsheet.Charts;
using System.IO;
// ...
spreadsheetControl1.LoadDocument("Document.xlsx");
using (FileStream stream = new FileStream("Chart1.crtx", FileMode.Open)) {
    var chart = spreadsheetControl1.ActiveWorksheet.Charts.AddFromTemplate(stream, 
    spreadsheetControl1.ActiveWorksheet["A21:B32"]);
}
vb
Imports DevExpress.Spreadsheet.Charts
Imports System.IO
' ...
spreadsheetControl1.LoadDocument("Document.xlsx")
Using stream As New FileStream("Chart1.crtx", FileMode.Open)
    Dim chart = spreadsheetControl1.ActiveWorksheet.Charts.AddFromTemplate(stream, 
  spreadsheetControl1.ActiveWorksheet("A21:B32"))
End Using

The image below illustrates the result:

Limitations

  • Excel 2016 charts are not supported.
  • Chart templates do not store series data, but store chart series settings (for example, series type and number). Since a chart template defines series, it may require sufficient data to populate them. The following chart types are affected:

See Also

ChartCollection Interface

ChartCollection Members

DevExpress.Spreadsheet.Charts Namespace