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

可能的使用场景

当同一位置有多个形状时,它们的可见性由它们的z-order位置决定。 Aspose.Cells提供 Shape.ToFrontOrBack() 方法来更改形状的z-order位置。 如果你想把形状发送到后面,你将使用一个负数,如-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-.NET
//Load source Excel file
Workbook wb = new Workbook(sourceDir + "sampleToFrontOrBack.xlsx");
//Access first worksheet
Worksheet ws = wb.Worksheets[0];
//Access first and fourth shape
Shape sh1 = ws.Shapes[0];
Shape sh4 = ws.Shapes[3];
//Print the Z-Order position of the shape
Console.WriteLine("Z-Order Shape 1: " + sh1.ZOrderPosition);
//Send this shape to front
sh1.ToFrontOrBack(2);
//Print the Z-Order position of the shape
Console.WriteLine("Z-Order Shape 4: " + sh4.ZOrderPosition);
//Send this shape to back
sh4.ToFrontOrBack(-2);
//Save the output Excel file
wb.Save(outputDir + "outputToFrontOrBack.xlsx");