Java/Excel에 이미지 주석 추가
6576 단어 commentexcelprogrammingjava
JAR 종속성 가져오기(2 방법)
1# free library을 다운로드하고 압축을 푼 다음 Spire.Xls.jar 파일을 종속성으로 프로젝트에 추가합니다.
2# pom.xml에 다음 구성을 추가하여 maven 프로젝트에 jar 종속성을 추가할 수도 있습니다.
<repositories>
<repository>
<id>com.e-iceblue</id>
<name>e-iceblue</name>
<url>http://repo.e iceblue.com/nexus/content/groups/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>e-iceblue</groupId>
<artifactId>spire.xls.free</artifactId>
<version>3.9.1</version>
</dependency>
</dependencies>
이미지 댓글 추가
자세한 단계와 전체 코드는 다음과 같습니다.
● Workbook 인스턴스를 생성한 다음 Workbook.loadFromFile() 메서드를 사용하여 Excel 파일을 로드합니다.
● Workbook.getWorksheets().get() 메서드를 사용하여 Excel 파일의 첫 번째 워크시트를 가져옵니다.
● Worksheet.getCellRange() 메서드를 사용하여 특정 셀을 가져옵니다.
● Cellrange.addComment() 메서드를 사용하여 해당 셀에 설명을 추가합니다.
● 이미지를 로드하고 ExcelComment.getFill().customPicture() 메서드를 사용하여 이미지로 주석을 채웁니다.
● 주석의 높이/너비를 설정하고 ExcelComment 클래스에서 제공하는 메소드를 사용하여 주석을 표시하도록 설정합니다.
● Workbook.saveToFile() 메서드를 사용하여 문서를 다른 파일로 저장합니다.
import com.spire.xls.*;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.*;
public class ImageComment {
public static void main(String[] args)throws IOException {
//Load the sample Excel file
Workbook workbook = new Workbook();
workbook.loadFromFile("member.xlsx");
//Get the first worksheet
Worksheet sheet = workbook.getWorksheets().get(0);
//Get the specific cell
CellRange range = sheet.getCellRange("E7");
//Add the commet
ExcelComment comment = range.addComment();
//Load an image
BufferedImage bufferedImage = ImageIO.read(new File("C:\\Users\\Administrator\\Desktop\\flag.jpg"));
//Use the image to fill the comment
comment.getFill().customPicture(bufferedImage, "C:\\Users\\Administrator\\Desktop\\flag.jpg");
//Set the height and width for the comment
comment.setHeight(bufferedImage.getHeight());
comment.setWidth(bufferedImage.getWidth());
//Show the comment
comment.setVisible(true);
//Save the document to file
workbook.saveToFile("SetImageComment.xlsx", ExcelVersion.Version2013);
}
}
Reference
이 문제에 관하여(Java/Excel에 이미지 주석 추가), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/carlwils/java-add-image-comments-to-excel-153o텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)