在工作表内部发送形状到前面或后面

可能的使用场景

当同一位置存在多个形状时,它们的可见性由它们的z-顺序位置决定。Aspose.Cells提供了Shape.ToFrontOrBack()方法,该方法可以更改形状的z-顺序位置。如果要将形状发送到后面,将使用像-1、-2、-3等的负数,如果要将形状移到前面,则使用像1、2、3等的正数。

在工作表内发送形状到最前或最后

以下示例代码解释了Shape.ToFrontOrBack()方法的用法。请查看代码中使用的样本Excel文件和由其生成的输出Excel文件。屏幕截图显示了代码对样本Excel文件的影响。

todo:image_alt_text

示例代码

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
//Load source Excel file
Workbook wb = new Workbook(srcDir + "sampleToFrontOrBack.xlsx");
//Access first worksheet
Worksheet ws = wb.getWorksheets().get(0);
//Access first and fourth shape
Shape sh1 = ws.getShapes().get(0);
Shape sh4 = ws.getShapes().get(3);
//Print the Z-Order position of the shape
System.out.println("Z-Order Shape 1: " + sh1.getZOrderPosition());
//Send this shape to front
sh1.toFrontOrBack(2);
//Print the Z-Order position of the shape
System.out.println("Z-Order Shape 4: " + sh4.getZOrderPosition());
//Send this shape to back
sh4.toFrontOrBack(-2);
//Save the output Excel file
wb.save(outDir + "outputToFrontOrBack.xlsx");