C#, VB.NET에서 PowerPoint 문서의 텍스트 정렬하기
PPT 텍스트 정렬은 하나의 텍스트 서식 도구로 볼 수 있습니다. 이 기능을 통해 사용자는 텍스트를 왼쪽, 오른쪽, 가운데, 양쪽 맞춤으로 정렬할 수 있습니다. 기본적으로 텍스트는 오른쪽으로 정렬되며, 사용자가 직접 정렬 방식을 지정할 수도 있습니다. 아래의 스크린샷은 각 정렬 방식에 따라 텍스트가 어떻게 표시되는지를 보여줍니다. 예를 들어, “Left” 텍스트는 왼쪽 정렬되고, “Center” 텍스트는 가운데 정렬됩니다.
Spire.Presentation for .NET은 자동화 없이 PPT 문서를 조작할 수 있는 전문적인 .NET용 PowerPoint 구성요소입니다. 이 가이드에서는 C#과 VB.NET을 사용하여 Spire.Presentation for .NET을 통해 텍스트를 정렬하는 방법을 소개합니다.
방법은 다음과 같습니다:
먼저 새 PPT 문서를 생성하고 슬라이드를 설정합니다.
그런 다음, 모든 정렬 방식을 순회(traverse)하며 새 문단을 추가하여 각 정렬을 표시합니다.
마지막으로 추가된 문단의 글꼴과 채우기 스타일을 설정합니다.
Spire.Presentation for .NET을 다운로드 및 설치한 후, 아래의 코드를 사용하여 PPT 문서에서 텍스트를 정렬하는 방법을 직접 체험해보세요.
전체 코드 예제:
using System;
using System.Drawing;
using Spire.Presentation;
using Spire.Presentation.Drawing;
namespace Alignment
{
class Program
{
static void Main(string[] args)
{
Presentation presentation = new Presentation();
// 배경 이미지 설정
string ImageFile = @"bg.png";
// 사각형 크기와 위치 지정
RectangleF rect = new RectangleF(0, 0, presentation.SlideSize.Size.Width, presentation.SlideSize.Size.Height);
// 슬라이드에 이미지 추가
presentation.Slides[0].Shapes.AppendEmbedImage(ShapeType.Rectangle, ImageFile, rect);
// 테두리 색상 설정
presentation.Slides[0].Shapes[0].Line.FillFormat.SolidFillColor.Color = Color.FloralWhite;
// 새 도형 추가
IAutoShape shape = presentation.Slides[0].Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(50, 70, 600, 400));
shape.TextFrame.Paragraphs[0].Alignment = TextAlignmentType.Left;
shape.Fill.FillType = FillFormatType.None;
shape.TextFrame.Text = "Demo about Alignment";
foreach (TextAlignmentType textAlign in Enum.GetValues(typeof(TextAlignmentType)))
{
// 텍스트 범위 생성
TextRange textRange = new TextRange(textAlign.ToString());
// 새 문단 생성
TextParagraph paragraph = new TextParagraph();
// 텍스트 범위 추가
paragraph.TextRanges.Append(textRange);
// 정렬 설정
paragraph.Alignment = textAlign;
// 도형에 문단 추가
shape.TextFrame.Paragraphs.Append(paragraph);
}
// 글꼴 및 채우기 스타일 설정
foreach (TextParagraph paragraph in shape.TextFrame.Paragraphs)
{
paragraph.TextRanges[0].LatinFont = new TextFont("Arial Black");
paragraph.TextRanges[0].Fill.FillType = FillFormatType.Solid;
paragraph.TextRanges[0].Fill.SolidColor.Color = Color.Black;
}
// 문서 저장
presentation.SaveToFile("alignment.pptx", FileFormat.Pptx2010);
System.Diagnostics.Process.Start("alignment.pptx");
}
}
}
임시 라이선스 신청
생성된 문서의 평가용 워터마크를 제거하거나 기능 제한을 해제하려면, 30일 체험용 임시 라이선스를 신청하세요.