Send Shape Front or Back inside the Worksheet
Possible Usage Scenarios
When there are multiple shapes present in the same location then how will they be visible is decided by their z-order positions. Aspose.Cells provides Shape.ToFrontOrBack() method which changes the z-order position of the shape. If you want to send shape to back you will use a negative number like -1, -2, -3, etc. and if you want to send shape to the front, you will use a positive number like 1, 2, 3, etc.
Send Shape Front or Back inside the Worksheet
The following sample code explains the usage of Shape.ToFrontOrBack() method. Please see the sample Excel file used inside the code and the output Excel file generated by it. The screenshot shows the effect of the code on the sample Excel file on execution.
Sample Code
// 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"); |