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

可能的使用场景

当同一位置存在多个形状时,它们的可见方式取决于它们的 z 顺序位置。 Aspose.Cells提供形状.ToFrontOrBack() 方法改变形状的 z 顺序位置。如果你想将形状发送到后面,你将使用负数,如 -1、-2、-3 等,如果你想将形状发送到前面,你将使用正数,如 1、2、3,等等

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

下面的示例代码解释了[形状.ToFrontOrBack()](https://reference.aspose.com/cells/java/com.aspose.cells/shape#toFrontOrBack(int)) 方法。请参阅示例 Excel 文件在代码中使用输出Excel文件由它产生。屏幕截图显示了代码对示例 Excel 文件的执行效果。

待办事项:图片_替代_文本

示例代码

// 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");