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


#1

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


#2

@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?


#3

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.


#4

@ServerSide527,

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


#5

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.


#6

@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:
https://docs.aspose.com/display/cellsjava/Copy+Shapes+between+Worksheets


#7

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?


#8

@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);