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 for Python via .NET provides Shape.to_front_or_back() 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.to_front_or_back() 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
from aspose.cells import Workbook | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# Load source Excel file | |
wb = Workbook(sourceDir + "sampleToFrontOrBack.xlsx") | |
# Access first worksheet | |
ws = wb.worksheets[0] | |
# Access first and fourth shape | |
sh1 = ws.shapes[0] | |
sh4 = ws.shapes[3] | |
# Print the Z-Order position of the shape | |
print("Z-Order Shape 1: " + str(sh1.z_order_position)) | |
# Send this shape to front | |
sh1.to_front_or_back(2) | |
# Print the Z-Order position of the shape | |
print("Z-Order Shape 4: " + str(sh4.z_order_position)) | |
# Send this shape to back | |
sh4.to_front_or_back(-2) | |
# Save the output Excel file | |
wb.save(outputDir + "outputToFrontOrBack.xlsx") |