Back to Devexpress

ChartObject.LoadTemplate(Stream) Method

officefileapi-devexpress-dot-spreadsheet-dot-charts-dot-chartobject-dot-loadtemplate-x28-system-dot-io-dot-stream-x29.md

latest3.6 KB
Original Source

ChartObject.LoadTemplate(Stream) Method

Loads a custom chart style and formatting settings from the stream and applies it to the chart.

Namespace : DevExpress.Spreadsheet.Charts

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

NuGet Package : DevExpress.Spreadsheet.Core

Declaration

csharp
void LoadTemplate(
    Stream stream
)
vb
Sub LoadTemplate(
    stream As Stream
)

Parameters

NameTypeDescription
streamStream

A stream that contains a chart template in CRTX format.

|

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 applies a chart template from a .CRTX file to an existing chart:

csharp
using DevExpress.Spreadsheet.Charts;
using System.IO;
// ...
spreadsheetControl1.LoadDocument("Document.xlsx");
// Create a chart.
DevExpress.Spreadsheet.Charts.Chart chart1 = spreadsheetControl1.ActiveWorksheet.Charts.Add(ChartType.ColumnClustered, 
spreadsheetControl1.ActiveWorksheet["A21:B32"]);
chart1.TopLeftCell = spreadsheetControl1.ActiveWorksheet.Cells["D20"];
chart1.BottomRightCell = spreadsheetControl1.ActiveWorksheet.Cells["K34"];
// Apply the chart template to the created chart.
using (FileStream stream = new FileStream("Chart1.crtx", FileMode.Open)) {
  chart1.LoadTemplate(stream)
}
vb
Imports DevExpress.Spreadsheet.Charts
Imports System.IO
' ...
spreadsheetControl1.LoadDocument("Document.xlsx")
' Create a chart.
Dim chart1 As DevExpress.Spreadsheet.Charts.Chart = spreadsheetControl1.ActiveWorksheet.Charts.Add(ChartType.ColumnClustered, 
spreadsheetControl1.ActiveWorksheet("A21:B32"))
chart1.TopLeftCell = spreadsheetControl1.ActiveWorksheet.Cells("D20")
chart1.BottomRightCell = spreadsheetControl1.ActiveWorksheet.Cells("K34")
' Apply the chart template to the created chart.
Using stream As New FileStream("Chart1.crtx", FileMode.Open)
    chart1.LoadTemplate(stream)
End Using

The image below illustrates the result:

Limitations

  • Excel 2016 charts are not supported.

Chart templates do not store series data, but do 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 number of chart series must correspond to the number of series stored in the chart template for the following chart types:

  • Surface chart.

  • Stock charts.

See Also

ChartObject Interface

ChartObject Members

DevExpress.Spreadsheet.Charts Namespace