Any way to copy range of chart and paste it in another range

Hi,

I’m looking to find a way to copy the range of a specific chart or shape from Excel and then paste it to another range.
Do you have that functionality?

Thanks

@ServerSide527,

Thanks for your query.

Could you elaborate with more details with sample file for your requirements. Do you want to copy source data range of the chart to some other location?

Ideally, I would like to select a chartArea (chart) or a shape, copy and then paste it somewhere else being able to define where is going to be pasted to (range to be pasted to). So copy the chart and pasted it in a specific range.

@ServerSide527,

I think you may try using Range.Copy() method (see the document for your reference: Copy Range Data with Style|Documentation) that would suit your needs and you will get formatted data, objects/shapes, etc. in the destination sheet cells.

Is there any method which gives you the range of a chart or shape?
If not then Range.Copy() cannot work with charts or shapes.

I have the destination range and the chart or shape i want to paste on that destination range. However, i cannot get the range of that particular chart.

@ServerSide527,

Do you mean the data source for the chart? Well, I think you may use: Series.Values attribute to get to know about the data source range of cells for the chart. Also, you may use. Chart.NSeries.CategoryData attribute to get the category data range.

By the way, you may also copy shapes and charts, see the document for your reference:

Hi,

I know you can addCopy a chart in a sheet. But i want to add a chart in a specific range inside that sheet not just add it to that Sheet. I want to paste it in specific cells. Is that possible?

@ServerSide527,

Well, I am afraid, there is no any automatic way to accomplish the task, you have to create the range based on the chart by yourself using your own code accordingly and paste it @ your desired location/range in the sheet. See the sample code segment for your reference:
e.g
Sample code:

Chart chart = worksheet.Charts[0];


int uC = chart.ChartObject.UpperLeftColumn;

int uR = chart.ChartObject.UpperLeftRow;


int lC = chart.ChartObject.LowerRightColumn;

int lR = chart.ChartObject.LowerRightRow;


String strrange = CellsHelper.CellIndexToName(uR, uC) + ":" + CellsHelper.CellIndexToName(lR, lC);

Hi,

I can do that. So there is no other way? Because you actually select the cells not only the chart.
Can we select at least the active chart or active shape on a specific sheet?

Thanks

@ServerSide527,

I am afraid, there is no other way around to cope with it, so you may try the suggested approach to accomplish the task.