DsExcel Java enables users to cut or copy shapes, charts, slicers and pictures from one workbook to another and from one worksheet to another.
To perform the copy operation, you can use the copy() method of the IRange interface.
To perform the cut operation, you can use the cut() method of the IRange interface.
In order to cut or copy shape, slicer, chart and picture in DsExcel Java, refer to the following example code.
Java |
Copy Code |
---|---|
Workbook workbook = new Workbook(); IWorksheet worksheet = workbook.getWorksheets().get(0); // Create a shape in worksheet, shape's range is Range("A7:B7") IShape shape = worksheet.getShapes().addShape(AutoShapeType.Rectangle, 40, 40, 100, 100); shape.getTextFrame().getTextRange().getFont().getColor().setRGB(Color.FromArgb(0, 255, 0)); // Range["A1:D10"] contains Range["A7:B7"], copy a new shape to Range["C1:F7"] worksheet.getRange("A1:D10").copy(worksheet.getRange("C1")); worksheet.getRange("A1:D10").copy(worksheet.getRange("C1:G9")); // Cross sheet copy operation - copy a new shape to worksheet2's Range["C1:F7"] IWorksheet worksheet2 = workbook.getWorksheets().add(); worksheet.getRange("A1:D10").copy(worksheet2.getRange("C1")); worksheet.getRange("A1:D10").copy(worksheet2.getRange("C1:G9")); // Range["A1:D10"] contains Range["A7:B7"], cut a new shape to Range["C1:F7"] worksheet.getRange("A1:D10").cut(worksheet.getRange("C1")); worksheet.getRange("A1:D10").cut(worksheet.getRange("C1:G9")); // Cross sheet cut operation - cut a new shape to worksheet2's Range["C1:F7"] IWorksheet worksheet3 = workbook.getWorksheets().add(); worksheet.getRange("A1:D10").cut(worksheet3.getRange("C1")); worksheet2.getRange("A1:D10").cut(worksheet3.getRange("C1:G9")); |
To duplicate a shape to the current worksheet, you can use the methods of the IShape interface.
In order to duplicate an existing shape, slicer, chart and picture, refer to the following example code.
Java |
Copy Code |
---|---|
// Create Shape IShape shape1 = worksheet.getShapes().addShape(AutoShapeType.Rectangle, 50, 50, 200, 200); // Create Chart, chart's range is Range["G1:M21"] IShape chart = chartworksheet.getShapes().addChart(ChartType.ColumnClustered, 300, 10, 300, 300); chartworksheet.getRange("A1:D6").setValue(new Object[][]{ {null, "S1", "S2", "S3"}, {"Item1", 10, 25, 25}, {"Item2", -51, -36, 27}, {"Item3", 52, -85, -30}, {"Item4", 22, 65, 65}, {"Item5", 23, 69, 69} }); chart.getChart().getSeriesCollection().add(chartworksheet.getRange("A1:D6"), RowCol.Columns, true, true); // Create slicer cache for table. ISlicerCache cache = workbook1.getSlicerCaches().add(table, "Category", "categoryCache"); // Create slicer ISlicer slicer = cache.getSlicers().add(workbook1.getWorksheets().get("Sheet1"), "cate1", "Category", 30, 550, 100, 200); // Create Picture IShape picture = worksheet.getShapes().addPicture("C:/Pictures", 1, 1, 100, 100); // Duplicate Shape IShape newShape = shape1.duplicate(); // Duplicate Chart IShape newchart = chart.duplicate(); // Duplicate Slicer IShape slicerShape = slicer.getShape().duplicate(); // Duplicate Picture IShape newPicture = picture.duplicate(); |