Java를 사용하여 PowerPoint 테이블에 이미지를 삽입하는 방법

이 간단한 문서는 Java를 사용하여 PowerPoint 테이블에 이미지를 삽입하는 방법에 중점을 둡니다. PPTX 테이블에 이미지를 추가하는 방법을 보여주는 이미지로 슬라이드 테이블 셀을 만들고 채우는 샘플 코드와 함께 환경 및 단계별 절차를 설정하는 데 필요한 모든 정보를 노출합니다. 자바. 이 애플리케이션은 macOS, Windows 또는 Linux와 같은 모든 Java 구성 환경에서 사용할 수 있습니다.

Java를 사용하여 PowerPoint 테이블에 이미지를 삽입하는 단계

  1. 테이블 이미지를 삽입하기 위해 Aspose.Slides for Java을(를) 추가하도록 환경 설정
  2. 새 프레젠테이션을 추가하고 슬라이드 모음에서 첫 번째 슬라이드에 액세스하려면 Presentation 클래스 인스턴스를 초기화하세요.
  3. addTable() 메서드를 사용하여 행과 열의 높이가 지정된 선택한 슬라이드 내에 표를 만듭니다.
  4. 프리젠테이션 이미지 컬렉션 내에 로드된 이미지 추가
  5. 테이블 내부의 첫 번째 행과 열에 속하는 셀을 로드하고 그 안에 이미지를 설정합니다.
  6. 표 이미지가 있는 프레젠테이션을 PPTX 형식으로 저장

앞서 언급한 단계를 사용하여 Java에서 PPTX 테이블에 이미지를 표시하는 방법을 설명했습니다. 우선, 프레젠테이션은 슬라이드 컬렉션 내의 첫 번째 슬라이드에 대한 액세스와 함께 프레젠테이션 클래스 개체를 사용하여 생성됩니다. addTable() 메서드를 사용하여 행과 열의 수를 제공하여 새 테이블을 삽입한 다음 디스크에서 이미지에 액세스하고 프레젠테이션 이미지 컬렉션에 추가합니다. 마지막으로 프레젠테이션을 디스크에 PPTX 형식으로 저장하기 전에 선택한 테이블 셀 안에 이미지를 설정합니다.

Java를 사용하여 PowerPoint 테이블에 이미지를 삽입하는 코드

import com.aspose.slides.FillType;
import com.aspose.slides.ICell;
import com.aspose.slides.IPPImage;
import com.aspose.slides.ISlide;
import com.aspose.slides.ITable;
import com.aspose.slides.License;
import com.aspose.slides.PictureFillMode;
import com.aspose.slides.Presentation;
import com.aspose.slides.SaveFormat;
import java.nio.file.Files;
import java.nio.file.Paths;
public class InsertTableImage {
public static void main(String[] args) throws Exception{
String filesPath = "/Documents/KnowledgeBase/TestData/";
License svgImportlicense = new License();
svgImportlicense.setLicense(filesPath + "Conholdate.Total.Product.Family.lic");
//Generate a default presentation to insert a PNG image
Presentation tblImagePresentation = new Presentation();
//Load the first default slide inside the presentation slides collection
ISlide slide = tblImagePresentation.getSlides().get_Item(0);
// Load and add the image inside the presentation image collection
IPPImage ppTblImage = tblImagePresentation.getImages().
addImage(Files.readAllBytes(Paths.get(filesPath + "Source.png")));
// Define the arrays containing the row heights and column widths
double[] dColumnsWidths = { 55, 55, 55 };
double[] dRowsHeights = { 54, 26, 46, 45 };
// Insert a new table with set rows and columns
ITable tblWithImage = slide.getShapes().addTable(60, 60, dColumnsWidths, dRowsHeights);
// Load the first cells inside the first row of the table
ICell tblCell = tblWithImage.get_Item(0, 0);
// Set the cell cell fill format to add a picture
tblCell.getCellFormat().getFillFormat().setFillType(FillType.Picture);
// Now set the picture fill mode to stretch
tblCell.getCellFormat().getFillFormat().getPictureFillFormat().setPictureFillMode(PictureFillMode.Stretch);
// Set the image for the table cell inside
tblCell.getCellFormat().getFillFormat().getPictureFillFormat().getPicture().setImage(ppTblImage);
//Save the presentation with a table image on the disk
tblImagePresentation.save(filesPath + "PresentationWithTableImage.pptx", SaveFormat.Pptx);
}
}

위의 예에서는 몇 가지 API 호출을 사용하여 Java를 사용하여 슬라이드에 표 이미지를 삽입하는 방법을 보여 주었습니다. 샘플 프레젠테이션을 만들고 ITable 클래스 개체를 사용하여 행과 열 모음이 있는 테이블을 추가했습니다. 테이블 내의 특정 셀에 대해 노출된 CellFormat 인스턴스는 FillType.Picture 열거자를 사용하여 셀의 채우기 형식을 이미지로 설정하는 데 사용됩니다. 마지막으로 프레젠테이션 이미지 모음에 이미지가 추가되고 표시용 셀 이미지로 사용됩니다.

이 예제에서는 Java를 사용하여 프레젠테이션에 테이블 이미지를 삽입하는 방법에 대해 배웠습니다. PowerPoint 내에서 테이블을 관리하는 방법에 대해 자세히 알아보려면 Java를 사용하여 슬라이드에 테이블을 삽입하는 방법 항목을 참조하십시오.

 한국인