Home > Java > javaTutorial > How to get the row and column coordinates of the picture in Excel in Java

How to get the row and column coordinates of the picture in Excel in Java

王林
Release: 2023-04-18 15:22:03
forward
2119 people have browsed it

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:

How to get the row and column coordinates of the picture in Excel in Java

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>
Copy after login

Get the row and column position of the image

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 + ")");
}
}
Copy after login

Read The result is as shown in the figure. The picture is located in the eighth row and fourth column:

How to get the row and column coordinates of the picture in Excel in Java

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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template