[]
GcExcel allows users to cut or copy shapes, charts, slicers and pictures from one workbook to another and from one worksheet to another.
In order to perform the copy operation, you can use the Copy() method of the IRange interface.
In order to perform the cut operation, you can use the Cut() method of the IRange interface.
Refer to the following example code to see how you can cut or copy shape, slicer, chart and picture.
Workbook workbook = new Workbook();
IWorksheet worksheet = workbook.Worksheets[0];
//Create a shape in worksheet, shape's range is Range["A7:B7"]
IShape shape = worksheet.Shapes.AddShape(AutoShapeType.Rectangle, 1, 1, 100, 100);
//Range["A1:D10"] contains Range["A7:B7"], copy a new shape to Range["C1:F7"]
worksheet.Range["A1:D10"].Copy(worksheet.Range["C1"]);
worksheet.Range["A1:D10"].Copy(worksheet.Range["C1:G9"]);
//Range["A1:D10"] contains Range["A7:B7"],cut a new shape to Range["C1:F7"]
worksheet.Range["A1:D10"].Cut(worksheet.Range["C1"]);
worksheet.Range["A1:D10"].Cut(worksheet.Range["C1:G9"]);
// Cross-sheet cut, copy operation
Workbook workbook1 = new Workbook();
IWorksheet worksheet1 = workbook1.Worksheets[0];
IWorksheet worksheet2 = workbook1.Worksheets.Add();
//Create a shape in worksheet, shape's range is Range["A7:B7"]
IShape Shape = worksheet.Shapes.AddShape(AutoShapeType.Rectangle, 1, 1, 100, 100);
//Range["A1:D10"] contains Range["A7:B7"]. Copy a new shape to worksheet2's Range["C1:F7"]
worksheet1.Range["A1:D10"].Copy(worksheet2.Range["C1"]);
worksheet1.Range["A1:D10"].Copy(worksheet2.Range["C1:G9"]);
//Range["A1:D10"] contains Range["A7:B7"]. Cut a new shape to worksheet2's Range["C1:F7"]
worksheet1.Range["A1:D10"].Cut(worksheet2.Range["C1"]);
worksheet1.Range["A1:D10"].Cut(worksheet2.Range["C1:G9"]);
In order to duplicate a shape to the current worksheet, you can use the Duplicate() method of the IShape interface.
Refer to the following example code to see how you duplicate an existing shape, slicer, chart and picture.
//Create shape,chart,slicer,picture
IShape Shape1 = worksheet.Shapes.AddShape(AutoShapeType.Rectangle, 100, 100, 200, 200);
IShape chart = worksheet.Shapes.AddChart(ChartType.ColumnClustered, 200, 300, 300, 300);
ISlicerCache cache1 = workbook.SlicerCaches.Add("Category", "cate1");
ISlicer slicer = cache1.Slicers.Add(workbook.Worksheets["Sheet1"], "cate1", "Category", 300, 300, 100, 200);
IShape picture = worksheet.Shapes.AddPicture("C:/Pictures", 1, 1, 100, 100);
//Duplicate shape
IShape newShape = Shape1.Duplicate();
//Duplicate chart
IShape newShape1 = chart.Duplicate();
//Duplicate slicer
slicer.Shape.Duplicate();
//Duplicate picture
IShape newPicture = picture.Duplicate();