Program environment:
Follow the following method to reference Spire.Xls.jar Version: 5.1.0
Method 1: Free Download the Spire.XLS for Java package locally, unzip it, and find the Spire.Xls.jar file in the lib folder. Then open the "Project Structure" interface in IDEA, and then perform the steps as shown to manually import the jar file in the local path:
Method 2: Through the Maven repository Download and import, configure pom.xml as follows:
<repositories> <repository> <id>com.e-iceblue</id> <name>e-iceblue</name> <url>https://repo.e-iceblue.cn/repository/maven-public/</url> </repository> </repositories> <dependencies> <dependency> <groupId>e-iceblue</groupId> <artifactId>spire.xls.free</artifactId> <version>5.1.0</version> </dependency> </dependencies>
The following are the detailed steps:
Create an object of class Workbook.
Call the Workbook.loadFromFile(String fileName) method to load the Excel file.
Get the specified worksheet through the Workbook.getWorksheets().get(int Index) method.
Get the specified picture through the Worksheet.getPictures().get(int Index) method.
Get the row and column position of the picture through the ExcelPicture.getTopRow() method and the ExcelPicture.getLeftColumn() method.
Finally, print the obtained results.
The following is the completed code for reference:
Java
import com.spire.xls.*; public class GetImageLocation { public static void main(String[] args) { //加载测试文档 Workbook wb = new Workbook(); wb.loadFromFile("sample.xlsx"); //获取第2个工作表 Worksheet sheet = wb.getWorksheets().get(1); //获取工作表中的第一张图片 ExcelPicture picture = sheet.getPictures().get(0); //获取图片所在行、列 int row = picture.getTopRow(); int column = picture.getLeftColumn(); //输出获取结果 System.out.println("location is :(" + row + "," + column + ")"); } }
Read The result is as shown in the figure. The picture is located in the eighth row and fourth column:
The above is the detailed content of How to get the row and column coordinates of the picture in Excel in Java. For more information, please follow other related articles on the PHP Chinese website!