C# Slide Element Tutorial – IronPPT
IronPPT는 .NET C# 개발자가 PowerPoint 프레젠테이션을 만들고, 읽고, 편집하는 기능을 애플리케이션에 원활하게 통합할 수 있도록 설계된 강력한 PowerPoint 라이브러리입니다. 파워포인트 프레젠테이션에서 슬라이드는 콘텐츠를 구성하고 정리하는 데 있어 가장 기본적인 요소입니다.
빠른 시작: 새 슬라이드 또는 기존 슬라이드에 텍스트 삽입
이 예시는 IronPPT를 사용하여 슬라이드에 텍스트를 얼마나 쉽게 추가할 수 있는지 보여줍니다. 단 몇 줄의 코드로, 첫 번째 슬라이드가 있으면 삽입하고, 없으면 새로 만들어서 저장하면 됩니다. 빠르고 간편하게 설정할 수 있습니다.
-
NuGet 패키지 관리자를 사용하여 https://www.nuget.org/packages/IronPPT 설치하기
PM > Install-Package IronPPT -
다음 코드 조각을 복사하여 실행하세요.
var doc = new IronPPT.PresentationDocument(); var text = doc.Slides.Count > 0 ? doc.Slides[0].AddText("Quick Option") : doc.Slides.Add(new IronPPT.Models.Slide()).AddText("Quick Option"); doc.Save("quick.pptx"); -
실제 운영 환경에서 테스트할 수 있도록 배포하세요.
무료 체험판으로 오늘 프로젝트에서 IronPPT 사용 시작하기
목차
- 텍스트 추가
- 이미지 추가
- 이미지 불러오기 (파일 및 파일 스트림)
- 치수 및 각도 설정 (너비 및 높이)
- 위치 설정
- 도형 추가
- 도형 유형 설정
- 치수 설정 (가로 및 세로)
- 채우기 및 윤곽선 색상 설정
- 위치 설정
텍스트 추가
텍스트 내용
새로운 프레젠테이션을 만들거나 기존 프레젠테이션을 편집할 때, 텍스트 관리 도구를 사용하면 텍스트 배치와 서식을 완벽하게 제어할 수 있으므로 메시지를 명확하고 전문적으로 전달하는 슬라이드를 디자인할 수 있습니다.
:path=/static-assets/ppt/content-code-examples/tutorials/slide-element-add-text.cs
using IronPPT;
using IronPPT.Models;
// Create a new PowerPoint presentation
var document = new PresentationDocument();
// Ensure there is at least one slide to work with
if (document.Slides.Count == 0)
{
document.Slides.Add(new Slide());
}
// Add text to the first slide
var text = document.Slides[0].AddText("Hello");
// Append text to the existing text on the slide
text.Content += " There!";
// Check if there is any text element to remove from the first slide
if (document.Slides[0].Texts.Count > 0)
{
document.Slides[0].Texts[0].Remove();
}
// Export the PowerPoint presentation with the specified file name
document.Save("addText.pptx");
Imports IronPPT
Imports IronPPT.Models
' Create a new PowerPoint presentation
Private document = New PresentationDocument()
' Ensure there is at least one slide to work with
If document.Slides.Count = 0 Then
document.Slides.Add(New Slide())
End If
' Add text to the first slide
Dim text = document.Slides(0).AddText("Hello")
' Append text to the existing text on the slide
text.Content &= " There!"
' Check if there is any text element to remove from the first slide
If document.Slides(0).Texts.Count > 0 Then
document.Slides(0).Texts(0).Remove()
End If
' Export the PowerPoint presentation with the specified file name
document.Save("addText.pptx")
스타일링 설정
텍스트 스타일링을 사용하면 글꼴 크기, 색상, 스타일, 취소선, 밑줄과 같은 속성을 정의하여 텍스트의 시각적 모양을 사용자 지정할 수 있습니다. 이러한 스타일을 적용하면 텍스트의 표현이 향상되고 문서의 전체적인 모양이 개선됩니다.
:path=/static-assets/ppt/content-code-examples/tutorials/slide-element-text-style.cs
using IronPPT;
using IronPPT.Models; // Ensure the library is available
// Create a new presentation document
var document = new PresentationDocument();
// Define and customize the text style
var textStyle = new TextStyle
{
IsBold = true, // Text is bold
IsItalic = true, // Text is italic
Color = Color.Blue, // Text color is blue
Strike = StrikeValue.SingleStrike, // Text is single struck-off
Outline = true, // Text has an outline
NoProof = true, // Disables proofing for the text
Spacing = 10.0, // Text spacing is set to 10
Underline = new Underline
{
LineValue = UnderlineValues.Single, // Single underline
Color = Color.Red // Underline color is red
},
Languages = "en-US", // Text language is set to U.S. English
SpecVanish = false, // Text does not vanish when special formatting is applied
};
// Create text content and apply the defined style
var text = new Text("Hello World"); // Instantiate text with a string
text.TextStyle = textStyle; // Apply the defined style to the text
// Add a new slide if none exist
if (document.Slides.Count == 0)
{
document.Slides.Add(new Slide()); // Add a new slide to the document
}
// Add the styled text to the first slide
document.Slides[0].AddText(text); // Add the newly created text object to the first slide
// Save the presentation document to a file
document.Save("textStyle.pptx"); // Save the document with the filename "textStyle.pptx"
Imports IronPPT
Imports IronPPT.Models ' Ensure the library is available
' Create a new presentation document
Private document = New PresentationDocument()
' Define and customize the text style
Private textStyle = New TextStyle With {
.IsBold = True,
.IsItalic = True,
.Color = Color.Blue,
.Strike = StrikeValue.SingleStrike,
.Outline = True,
.NoProof = True,
.Spacing = 10.0,
.Underline = New Underline With {
.LineValue = UnderlineValues.Single,
.Color = Color.Red
},
.Languages = "en-US",
.SpecVanish = False
}
' Create text content and apply the defined style
Private text = New Text("Hello World") ' Instantiate text with a string
text.TextStyle = textStyle ' Apply the defined style to the text
' Add a new slide if none exist
If document.Slides.Count = 0 Then
document.Slides.Add(New Slide()) ' Add a new slide to the document
End If
' Add the styled text to the first slide
document.Slides(0).AddText(text) ' Add the newly created text object to the first slide
' Save the presentation document to a file
document.Save("textStyle.pptx") ' Save the document with the filename "textStyle.pptx"
이미지 추가
최적의 화면 표시를 위해 이미지 설정을 조정하십시오. 적절한 설정을 통해 이미지가 시각적으로 매력적이고 맥락에 적합하게 보이도록 할 수 있습니다.
:path=/static-assets/ppt/content-code-examples/tutorials/slide-element-add-image.cs
using IronPPT;
using IronPPT.Models;
using System.Drawing;
// This script demonstrates the creation of a PowerPoint presentation using the IronPPT library.
// An image is added to the presentation, its properties are modified, and then the presentation is saved.
// Create a new PowerPoint presentation
var document = new PresentationDocument();
// Create a new Image object and load an image file.
var image = new Image();
image.LoadFromFile("sample.png");
// Add the image to the first slide (index 0) of the presentation.
var newImage = document.AddImage(image, 0);
// Set the properties of the added image.
// Position property is set using a Point object, which holds X and Y coordinates.
newImage.Position = new Point(200, 200); // Set image position on the slide
newImage.Angle = 45; // Set the rotation angle of the image
newImage.Name = "new image"; // Assign a descriptive name to the image
newImage.Width = 150; // Set the width of the image in pixels
newImage.Height = 150; // Set the height of the image in pixels
// Export the PowerPoint presentation to a file named "addImage.pptx"
document.Save("addImage.pptx");
Imports IronPPT
Imports IronPPT.Models
Imports System.Drawing
' This script demonstrates the creation of a PowerPoint presentation using the IronPPT library.
' An image is added to the presentation, its properties are modified, and then the presentation is saved.
' Create a new PowerPoint presentation
Private document = New PresentationDocument()
' Create a new Image object and load an image file.
Private image = New Image()
image.LoadFromFile("sample.png")
' Add the image to the first slide (index 0) of the presentation.
Dim newImage = document.AddImage(image, 0)
' Set the properties of the added image.
' Position property is set using a Point object, which holds X and Y coordinates.
newImage.Position = New Point(200, 200) ' Set image position on the slide
newImage.Angle = 45 ' Set the rotation angle of the image
newImage.Name = "new image" ' Assign a descriptive name to the image
newImage.Width = 150 ' Set the width of the image in pixels
newImage.Height = 150 ' Set the height of the image in pixels
' Export the PowerPoint presentation to a file named "addImage.pptx"
document.Save("addImage.pptx")
도형 추가
프레젠테이션에 도형을 쉽게 추가하고 사용자 지정하려면 도형의 유형, 크기(너비 및 높이), 채우기 및 윤곽선 색상, 슬라이드에서의 위치를 정의하세요.
:path=/static-assets/ppt/content-code-examples/tutorials/slide-element-add-shape.cs
using IronPPT;
using IronPPT.Models;
using IronPPT.Enums;
// Load a PowerPoint presentation.
// The PresentationDocument is assumed to represent an entire PPTX file loaded from disk.
var document = new PresentationDocument("output.pptx");
// Configure a new shape.
// Shape is assumed to be a model object representing drawable elements on a slide.
Shape shape = new Shape
{
Name = "triangle",
Type = ShapeType.Triangle,
Width = 100,
FillColor = new Color("#444444"),
OutlineColor = Color.Black,
// Position is set via assumed X and Y positioning properties.
// It's important that these properties are set to valid coordinates for display on the slide.
XPosition = 200,
YPosition = 200
};
// Add the shape to the first slide in the presentation.
// Slides[0] refers to the first slide in the collection. Ensure a slide exists at this index.
document.Slides[0].AddShape(shape);
// Export the modified PowerPoint presentation.
// Saves the changes to a new file, ensuring the original presentation is not overwritten.
document.Save("addShape.pptx");
Imports IronPPT
Imports IronPPT.Models
Imports IronPPT.Enums
' Load a PowerPoint presentation.
' The PresentationDocument is assumed to represent an entire PPTX file loaded from disk.
Private document = New PresentationDocument("output.pptx")
' Configure a new shape.
' Shape is assumed to be a model object representing drawable elements on a slide.
Private shape As New Shape With {
.Name = "triangle",
.Type = ShapeType.Triangle,
.Width = 100,
.FillColor = New Color("#444444"),
.OutlineColor = Color.Black,
.XPosition = 200,
.YPosition = 200
}
' Add the shape to the first slide in the presentation.
' Slides[0] refers to the first slide in the collection. Ensure a slide exists at this index.
document.Slides(0).AddShape(shape)
' Export the modified PowerPoint presentation.
' Saves the changes to a new file, ensuring the original presentation is not overwritten.
document.Save("addShape.pptx")

