How to Create A Table in Powerpoint Programmatically

개요

PowerPoint에서 표를 만드는 것은 특히 수동으로 수행할 때 번거로운 작업이 될 수 있습니다. 하지만 이 과정을 자동화할 수 있다면 어떨까요? Aspose.Slides for Java를 사용하면 가능합니다. 이 강력한 PowerPoint 프레젠테이션 라이브러리를 사용하면 PowerPoint에서 프로그래밍 방식으로 표를 만들어 시간과 노력을 절약할 수 있습니다. 다양한 산업 분야에서 사용되는 Aspose.Slides for Java는 PowerPoint 프레젠테이션을 만들고, 편집하고, 관리하는 과정을 간소화합니다. 이제 이 Java API를 사용하여 PowerPoint에서 표를 만드는 방법을 구현해 보겠습니다.

이 가이드에서는 다음 사항을 다룹니다:

PowerPoint 프레젠테이션 라이브러리 설치

시작하려면 Aspose.Slides for Java를 설치해야 합니다. 여기에서 다운로드할 수 있습니다. 또는 다음 Maven 종속성을 사용하여 프로젝트에 Aspose.Slides를 추가할 수 있습니다:

<repository>
  <id>AsposeJavaAPI</id>
  <name>Aspose Java API</name>
  <url>https://repository.aspose.com/repo/</url>
</repository>
<dependency>
  <groupId>com.aspose</groupId>
  <artifactId>aspose-slides</artifactId>
  <version>24.4</version>
  <classifier>jdk16</classifier>
</dependency>

PowerPoint에서 프로그래밍 방식으로 표 만들기

Aspose.Slides for Java를 사용하여 PowerPoint에서 표를 만들 준비가 되셨나요?

다음 단계를 따르세요:

  1. PPTX/PPT 파일을 나타내는 Presentation 클래스를 인스턴스화합니다.
  2. get_Item 함수를 호출하여 첫 번째 슬라이드에 액세스합니다.
  3. 열의 너비와 행의 높이를 정의합니다.
  4. addTable 함수를 호출하여 슬라이드에 표 모양을 추가합니다.
  5. 각 셀에 대한 테두리 형식을 설정합니다.
  6. mergeCells 메서드를 호출하여 1행의 셀 1과 2를 병합합니다.
  7. setText 메서드를 호출하여 병합된 셀에 텍스트를 추가합니다.
  8. save 메서드는 디스크에 PPTX를 저장합니다.

다음은 PowerPoint에서 프로그래밍 방식으로 표를 만드는 방법을 보여주는 간단한 Java 코드 스니펫입니다:

package com.example;
import com.aspose.slides.*;
import java.awt.*;
public class main
{
public static void main(String[] args)
{
// Define the working directory.
final String outPath = "/Desktop/";
// Instantiate Presentation class that represents PPTX/PPT file.
Presentation pres = new Presentation();
try
{
// Access first slide by calling the get_Item function.
ISlide sld = pres.getSlides().get_Item(0);
// Define columns with widths and rows with heights.
double[] dblCols = {50, 50, 50};
double[] dblRows = {50, 30, 30, 30, 30};
// Call the addTable function to add table shape to slide.
ITable tbl = sld.getShapes().addTable(100, 50, dblCols, dblRows);
// Set border format for each cell.
for (int row = 0; row < tbl.getRows().size(); row++)
{
for (int cell = 0; cell < tbl.getRows().get_Item(row).size(); cell++)
{
tbl.get_Item(cell, row).getCellFormat().getBorderTop().getFillFormat().setFillType(FillType.Solid);
tbl.get_Item(cell, row).getCellFormat().getBorderTop().getFillFormat().getSolidFillColor().setColor(Color.RED);
tbl.get_Item(cell, row).getCellFormat().getBorderTop().setWidth(5);
tbl.get_Item(cell, row).getCellFormat().getBorderBottom().getFillFormat().setFillType((FillType.Solid));
tbl.get_Item(cell, row).getCellFormat().getBorderBottom().getFillFormat().getSolidFillColor().setColor(Color.RED);
tbl.get_Item(cell, row).getCellFormat().getBorderBottom().setWidth(5);
tbl.get_Item(cell, row).getCellFormat().getBorderLeft().getFillFormat().setFillType(FillType.Solid);
tbl.get_Item(cell, row).getCellFormat().getBorderLeft().getFillFormat().getSolidFillColor().setColor(Color.RED);
tbl.get_Item(cell, row).getCellFormat().getBorderLeft().setWidth(5);
tbl.get_Item(cell, row).getCellFormat().getBorderRight().getFillFormat().setFillType(FillType.Solid);
tbl.get_Item(cell, row).getCellFormat().getBorderRight().getFillFormat().getSolidFillColor().setColor(Color.RED);
tbl.get_Item(cell, row).getCellFormat().getBorderRight().setWidth(5);
}
}
// Merge cells 1 & 2 of row 1 by calling the mergeCells method.
tbl.mergeCells(tbl.get_Item(0, 0), tbl.get_Item(1, 1), false);
// Invoke the setText method to add text to the merged cell.
tbl.get_Item(0, 0).getTextFrame().setText("Merged Cells");
// The save method will save PPTX to Disk. s
pres.save(outPath + "table.pptx", SaveFormat.Pptx);
}
finally
{
if (pres != null) pres.dispose();
}
//ExEnd:CreateATableFromScratchInASlide
}
}
출력:
powerpoint-presentation-library

무료 라이선스 받기

Aspose.Slides for Java를 탐색하는 데 관심이 있으신가요? 이 링크를 방문하여 무료 평가판 라이선스를 얻으세요.

최종 생각

Aspose.Slides for Java를 사용하면 PowerPoint에서 프로그래밍 방식으로 표를 만드는 것이 매우 쉬워집니다. 이 강력한 PowerPoint 프레젠테이션 라이브러리는 과정을 단순화하여 시간과 노력을 절약합니다. 그러니 주저하지 말고 Aspose.Slides for Java를 오늘 탐색하여 PowerPoint 프레젠테이션을 혁신하세요.

유용한 리소스

추가 학습을 위해 광범위한 문서 및 커뮤니티 포럼을 확인하세요. 이러한 리소스는 이 블로그 콘텐츠를 넘어 이해와 기술을 향상시키는 데 도움이 될 수 있습니다.

더 알아보기

  1. Java에서 프로그래밍 방식으로 상자 및 수염 차트 만들기
  2. [Java에서 ODP를 PPTX