이 항목에서는 **C#**을 사용하여 PowerPoint 표에 이미지를 삽입하는 방법에 대해 중점적으로 설명합니다. 여기에는 환경 설정을 위한 모든 세부 정보, 테이블 셀을 생성하고 이미지로 채우는 단계별 절차, C#의 PPTX 테이블에 이미지를 추가하는 방법을 보여주는 작업 예제가 포함됩니다. . 개발된 애플리케이션은 Windows, macOS 또는 Linux와 같은 모든 .NET 구성 환경에서 사용할 수 있습니다.
C#을 사용하여 PowerPoint 테이블에 이미지를 삽입하는 단계
- 테이블 이미지를 삽입하기 위해 Aspose.Slides for .NET을(를) 추가하도록 환경 설정
- Presentation 클래스 개체를 인스턴스화하여 새 프레젠테이션을 추가하고 슬라이드 모음에서 첫 번째 슬라이드에 액세스
- 선택한 슬라이드에 AddTable() 메서드를 사용하여 행과 열의 높이가 지정된 표를 삽입합니다.
- 프리젠테이션 이미지 모음에 원하는 이미지 삽입
- 테이블의 첫 번째 행과 열에 속하는 셀에 접근하여 그 안에 추가된 이미지를 설정합니다.
- 프레젠테이션을 PPTX 형식의 표 이미지와 함께 저장
위의 단계에서 *C#*의 PPTX 테이블에 이미지를 표시하는 방법을 설명했습니다. 프레젠테이션 클래스의 인스턴스를 사용하여 기본 프레젠테이션을 만들고 첫 번째 슬라이드에 액세스하는 것으로 프로세스가 시작됩니다. 후속 단계에서는 AddTable() 메서드를 사용하여 테이블의 행과 열 수를 제공하여 새 테이블을 추가한 다음 프레젠테이션 이미지 컬렉션 내에서 소스 이미지를 로드하고 추가합니다. 마지막으로 테이블에서 원하는 셀이 선택되고 로드된 이미지가 디스크에 출력 프레젠테이션을 저장하기 전에 특정 셀에 대해 설정됩니다.
C#을 사용하여 PowerPoint 테이블에 이미지를 삽입하는 코드
using System.Drawing; | |
using Aspose.Slides; | |
namespace TestSlides | |
{ | |
public class InsertImageInTable | |
{ | |
public static void AddImageInsideTable() | |
{ | |
string filesPath = @"/Users/Documents/KnowledgeBase/TestData/"; | |
License license = new License(); | |
license.SetLicense(filesPath + "Conholdate.Total.Product.Family.lic"); | |
//Create a new presentation to insert an image inside the table | |
Presentation TablePresentation = new Presentation(); | |
//Load the first default slide of the presentation | |
ISlide targetSlide = TablePresentation.Slides[0]; | |
// Access the source image from the disk and add to presentation images | |
System.Drawing.Image tblImage = (System.Drawing.Image)new Bitmap(filesPath+ "Test.png"); | |
IPPImage ppTblImage = TablePresentation.Images.AddImage(tblImage); | |
//Now declare the rows heights and columns widths | |
double[] columnsWidths = { 45, 45, 45 ,45}; | |
double[] rowsHeights = { 45, 26, 30, 30 }; | |
// Insert a table inside the slide | |
Aspose.Slides.ITable tableWithImage = targetSlide.Shapes.AddTable(55, 55, columnsWidths, rowsHeights); | |
// Access the first cells inside the first row of the table | |
ICell tableCell = tableWithImage[0,0]; | |
// Set the cell fill format to picture | |
tableCell.CellFormat.FillFormat.FillType = FillType.Picture; | |
// Set the picture fill mode | |
tableCell.CellFormat.FillFormat.PictureFillFormat.PictureFillMode = PictureFillMode.Stretch; | |
// Set the image for the selected cell inside the table | |
tableCell.CellFormat.FillFormat.PictureFillFormat.Picture.Image = ppTblImage; | |
//Save the presentation with the table image on the disk | |
TablePresentation.Save(filesPath + "PresWithTableImage.pptx", Aspose.Slides.Export.SaveFormat.Pptx); | |
} | |
} | |
} |
이 항목에서는 *C#*을 사용하여 프레젠테이션에 테이블 이미지를 삽입하는 방법에 중점을 두었습니다. PowerPoint 내부의 표 관리에 대한 학습을 더 향상시키려면 C#을 사용하여 PowerPoint에서 표를 만드는 방법 문서를 참조하십시오.