Back to Devexpress

ChartObject.MoveToWorksheet(Worksheet) Method

officefileapi-devexpress-dot-spreadsheet-dot-charts-dot-chartobject-dot-movetoworksheet-x28-devexpress-dot-spreadsheet-dot-worksheet-x29.md

latest5.3 KB
Original Source

ChartObject.MoveToWorksheet(Worksheet) Method

Moves a chart to the specified worksheet.

Namespace : DevExpress.Spreadsheet.Charts

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

NuGet Package : DevExpress.Spreadsheet.Core

Declaration

csharp
Chart MoveToWorksheet(
    Worksheet worksheet
)
vb
Function MoveToWorksheet(
    worksheet As Worksheet
) As Chart

Parameters

NameTypeDescription
worksheetWorksheet

A Worksheet object that specifies a worksheet in the current workbook where the chart will be placed.

|

Returns

TypeDescription
Chart

A Chart object that specifies the embedded chart.

|

Remarks

The following example demonstrates how to use the MoveToWorksheet method to move a chart from a separate chart sheet to a worksheet containing the source data.

View Example

csharp
Worksheet worksheet = workbook.Worksheets["chartTask1"];

// Create a chart sheet containing a pie chart.
ChartSheet chartSheet = workbook.ChartSheets.Add(ChartType.Pie, worksheet["B2:C7"]);

// Move the chart to the worksheet with chart data.
Chart embeddedChart = chartSheet.Chart.MoveToWorksheet(worksheet);
// Adjust the chart location.
embeddedChart.TopLeftCell = worksheet.Cells["E2"];
embeddedChart.BottomRightCell = worksheet.Cells["K15"];

workbook.Worksheets.ActiveWorksheet = worksheet;
vb
Dim worksheet As Worksheet = workbook.Worksheets("chartTask1")

' Create a chart sheet containing a pie chart.
Dim chartSheet As ChartSheet = workbook.ChartSheets.Add(ChartType.Pie, worksheet("B2:C7"))

' Move the chart to the worksheet with chart data.
Dim embeddedChart As Chart = chartSheet.Chart.MoveToWorksheet(worksheet)
' Adjust the chart location.
embeddedChart.TopLeftCell = worksheet.Cells("E2")
embeddedChart.BottomRightCell = worksheet.Cells("K15")

workbook.Worksheets.ActiveWorksheet = worksheet

The following code snippets (auto-collected from DevExpress Examples) contain references to the MoveToWorksheet(Worksheet) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

wpf-spreadsheet-chart-api/CS/SpreadsheetWPFChartAPISamples/CodeExamples/ChartSheetActions.cs#L110

csharp
// Move the chart to the worksheet with chart data.
Chart embeddedChart = chartSheet.Chart.MoveToWorksheet(worksheet);
// Adjust the chart location.

winforms-spreadsheet-chart-api/CS/SpreadsheetChartAPISamples/CodeExamples/ChartSheetActions.cs#L110

csharp
// Move the chart to the worksheet with chart data.
Chart embeddedChart = chartSheet.Chart.MoveToWorksheet(worksheet);
// Adjust the chart location.

wpf-spreadsheet-chart-api/VB/SpreadsheetWPFChartAPISamples/CodeExamples/ChartSheetActions.vb#L106

vb
' Move the chart to the worksheet with chart data.
Dim embeddedChart As Chart = chartSheet.Chart.MoveToWorksheet(worksheet)
' Adjust the chart location.

winforms-spreadsheet-chart-api/VB/SpreadsheetChartAPISamples/CodeExamples/ChartSheetActions.vb#L105

vb
' Move the chart to the worksheet with chart data.
Dim embeddedChart As Chart = chartSheet.Chart.MoveToWorksheet(worksheet)
' Adjust the chart location.

See Also

ChartObject Interface

ChartObject Members

DevExpress.Spreadsheet.Charts Namespace