查找工作表内形状的绝对位置
Contents
[
Hide
]
有时,您需要知道工作表上形状的绝对位置。Aspose.Cells提供Shape.getLeftToCorner()和Shape.getTopToCorner()属性来实现此目的。这些属性以像素返回工作表上形状的绝对位置。
解释Shape.getLeftToCorner()和Shape.getTopToCorner()属性
此屏幕截图解释了Shape.getLeftToCorner()和Shape.getTopToCorner()属性测量的距离。
如何测量绝对位置
以下示例代码显示工作表中第一个形状的绝对位置(以像素为单位)。该代码在控制台中显示以下输出:
Absolute Position of this Shape is (320, 180)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(FindAbsolutePositionOfShape.class); | |
// Load the sample Excel file inside the workbook object | |
Workbook workbook = new Workbook("sample.xlsx"); | |
// Access the first worksheet | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Access the first shape inside the worksheet | |
Shape shape = worksheet.getShapes().get(0); | |
// Displays the absolute position of the shape | |
System.out.println("Absolute Position of this Shape is (" + shape.getLeftToCorner() + " , " | |
+ shape.getTopToCorner() + ")"); |