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

可能的使用场景

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

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

下面的示例代码解释了形状.ToFrontOrBack()方法。请参阅示例 Excel 文件在代码中使用输出Excel文件由它产生。屏幕截图显示了代码对示例 Excel 文件的执行效果。

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

示例代码

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