C++에서 프레젠테이션 플레이스홀더 관리
Overview
플레이스홀더는 프레젠테이션 템플릿에서 특정 유형의 콘텐츠 위치를 예약하는 도형입니다. 일반적인 예로는 제목, 본문, 그림, 차트 및 일반 목적 콘텐츠 플레이스홀더가 있습니다. 일반 도형과 달리 플레이스홀더는 레이아웃 슬라이드 또는 마스터 슬라이드로부터 위치, 크기, 서식 및 기타 설정을 상속받을 수 있습니다.
Aspose.Slides는 플레이스홀더 정보를 IShape::get_Placeholder 메서드를 통해 노출합니다. 이 메서드는 일반 도형인 경우 nullptr를 반환하고, IPlaceholder 객체를 반환합니다. 플레이스홀더가 어떤 콘텐츠를 포함하도록 설계되었는지 확인하려면 IPlaceholder::get_Type을 사용하십시오.
플레이스홀더 유형을 알게 된 후에도 도형 인터페이스는 여전히 중요합니다:
- 빈 텍스트, 그림, 차트 또는 콘텐츠 플레이스홀더는 일반적으로 IAutoShape으로 표시됩니다.
- 내용이 채워진 그림 플레이스홀더는 IPictureFrame으로 표시될 수 있습니다.
- 내용이 채워진 차트 플레이스홀더는 IChart으로 표시될 수 있습니다.
- 콘텐츠 플레이스홀더는 여러 종류의 콘텐츠를 포함할 수 있습니다. 모든 플레이스홀더가 IAutoShape라고 가정하지 말고 IPlaceholder::get_Type과 런타임 도형 인터페이스를 모두 확인하십시오.
Warning
IPlaceholder::get_Type은 플레이스홀더의 역할을 설명하지만, 도형의 런타임 유형을 보장하지는 않습니다. 텍스트, 그림, 차트, 표 또는 미디어 관련 멤버에 접근하기 전에 항상 유형 검사를 수행하십시오.Understand Placeholder Inheritance
플레이스홀더는 계층 구조를 형성합니다:
- 마스터 슬라이드는 재사용 가능한 스타일을 정의하고, 경우에 따라 마스터 수준의 플레이스홀더를 정의합니다.
- 레이아웃 슬라이드는 하나 이상의 일반 슬라이드가 사용할 배치를 정의하며 마스터로부터 상속받을 수 있습니다.
- 일반 슬라이드는 해당 슬라이드의 플레이스홀더를 포함하고 레이아웃으로부터 상속받을 수 있습니다.
이 계층 구조에서 한 단계 위로 이동하려면 IShape::GetBasePlaceholder를 호출하십시오. 슬라이드 플레이스홀더는 일반적으로 레이아웃 플레이스홀더를 반환하고, 레이아웃 플레이스홀더는 마스터 플레이스홀더를 반환할 수 있습니다. 도형에 기본 플레이스홀더가 없으면 메서드는 nullptr를 반환합니다.
다음 예제는 첫 번째 슬라이드의 플레이스홀더를 열거하고 해당 기본 플레이스홀더를 보고합니다:
#include <DOM/IPlaceholder.h>
#include <DOM/IShape.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/Presentation.h>
#include <system/console.h>
#include <system/type_info.h>
using namespace Aspose::Slides;
using namespace System;
auto presentation = MakeObject<Presentation>(u"template.pptx");
auto slide = presentation->get_Slide(0);
for (auto&& shape : slide->get_Shapes())
{
auto placeholder = shape->get_Placeholder();
if (placeholder == nullptr)
{
continue;
}
auto placeholderType = placeholder->get_Type();
auto typeName = shape->GetType().get_Name();
Console::WriteLine(u"Slide placeholder: {0}; shape interface: {1}", placeholderType, typeName);
auto layoutPlaceholder = shape->GetBasePlaceholder();
if (layoutPlaceholder != nullptr)
{
auto layoutPlaceholderInfo = layoutPlaceholder->get_Placeholder();
if (layoutPlaceholderInfo != nullptr)
{
auto layoutPlaceholderType = layoutPlaceholderInfo->get_Type();
Console::WriteLine(u" Layout placeholder: {0}", layoutPlaceholderType);
}
auto masterPlaceholder = layoutPlaceholder->GetBasePlaceholder();
if (masterPlaceholder != nullptr)
{
auto masterPlaceholderInfo = masterPlaceholder->get_Placeholder();
if (masterPlaceholderInfo != nullptr)
{
auto masterPlaceholderType = masterPlaceholderInfo->get_Type();
Console::WriteLine(u" Master placeholder: {0}", masterPlaceholderType);
}
}
}
}
일반 슬라이드에서 플레이스홀더를 편집하면 해당 슬라이드에 대한 로컬 오버라이드가 생성되거나 변경됩니다. 관련 레이아웃이나 마스터를 편집하면 여전히 해당 설정을 상속받는 모든 슬라이드에 영향을 줄 수 있습니다. 로컬 일반 도형은 기본 플레이스홀더가 없으며 동일한 좌표에 위치한다고 해서 상속을 시작하지 않습니다.
Remove Placeholder Status
템플릿을 수정할 때는 IShape::RemovePlaceholder를 사용하여 기존 객체를 일반 도형으로 유지할 수 있습니다. 해당 도형의 IShape::get_Placeholder 메서드는 nullptr를 반환하지만, 도형은 슬라이드 컬렉션에 남아 있습니다. 반면에 IShapeCollection::Remove는 컬렉션에서 도형을 삭제합니다.
다음 예제는 최소 하나의 슬라이드와 첫 번째 슬라이드에 비어 있지 않은 텍스트 플레이스홀더가 포함된 template.pptx가 필요합니다. 레이아웃 또는 마스터에서 상속된 서식이 적용된 플레이스홀더를 사용하여 관계를 제거했을 때의 영향을 확인하십시오. 예제는 동일한 도형이 남아 있는지 확인하고, 이제 일반 도형이 된 도형에 다시 메서드를 호출한 뒤 결과를 저장합니다.
Warning
플레이스홀더 상태를 제거한다고 해서 상속된 표시 설정이 자동으로 보존되는 것은 아닙니다. 아래 예제는 이러한 설정을 의도적으로 변경하지 않으므로 출력이 다르게 보일 수 있습니다. 위치와 크기가 완전히 상속된 도형은 호출 후 좌표와 차원이 0이 되어 컬렉션에 남아 있지만 보이지 않을 수 있습니다.#include <DOM/IAutoShape.h>
#include <DOM/IPlaceholder.h>
#include <DOM/IShape.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/ITextFrame.h>
#include <DOM/Presentation.h>
#include <Export/SaveFormat.h>
#include <system/console.h>
#include <system/object_ext.h>
#include <system/string.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace System;
auto presentation = MakeObject<Presentation>(u"template.pptx");
auto slide = presentation->get_Slide(0);
auto found = false;
for (auto index = 0; index < slide->get_Shapes()->get_Count(); index++)
{
auto currentShape = slide->get_Shape(index);
if (!ObjectExt::Is<IAutoShape>(currentShape))
{
continue;
}
auto shape = ExplicitCast<IAutoShape>(currentShape);
auto textFrame = shape->get_TextFrame();
if (shape->get_Placeholder() == nullptr ||
textFrame == nullptr ||
String::IsNullOrEmpty(textFrame->get_Text()))
{
continue;
}
auto shapeCount = slide->get_Shapes()->get_Count();
shape->RemovePlaceholder();
Console::WriteLine(u"Placeholder removed: {0}", shape->get_Placeholder() == nullptr);
Console::WriteLine(u"Same shape retained: {0}", slide->get_Shape(index) == currentShape);
Console::WriteLine(u"Shape count unchanged: {0}", slide->get_Shapes()->get_Count() == shapeCount);
// 일반 도형에 메서드를 호출해도 효과가 없습니다.
shape->RemovePlaceholder();
found = true;
break;
}
if (found)
{
presentation->Save(u"placeholder-status-removed.pptx", SaveFormat::Pptx);
}
else
{
Console::WriteLine(u"No nonempty text placeholder was found on the first slide.");
}
일치하는 플레이스홀더에 대해 세 가지 검사 모두 True를 출력합니다. 텍스트는 유지되지만, 플레이스홀더 관계가 제거될 때 상속된 위치, 크기, 회전, 글꼴, 단락 정렬, 텍스트 프레임 여백, 수직 기준, 채우기 및 선 설정이 변경될 수 있습니다. 예를 들어, 상속된 제목 서식이 일반 텍스트 서식으로 되돌아갈 수 있습니다. 레이아웃에 대한 자세한 내용은 Slide Layout를 참조하십시오.
원래의 표시를 유지하려면 호출 전에 해결된 위치, 크기 및 회전을 캡처하고, 필요한 실효 서식 값을 별도 변수에 복사하십시오. 이러한 값은 IPortionFormat::GetEffective, IParagraphFormat::GetEffective, ITextFrameFormat::GetEffective, IFillFormat::GetEffective, ILineFormat::GetEffective을 통해 가져옵니다. 관계가 제거된 후 텍스트 서식 값이 변할 수 있으므로 실효 서식 객체만 보관하지 마십시오. 캡처한 값을 일반 도형에 명시적으로 적용하십시오(글꼴 패밀리, 크기, 스타일, 색상, 단락 설정, 텍스트 프레임 설정, 채우기 및 선 포함).
상속된 도형 기하학도 IGeometryShape::set_ShapeType을 통해 명시적으로 지정해야 할 수 있습니다. 사각형 텍스트 플레이스홀더의 경우 ShapeType::Rectangle을 지정해야 하며, 채우기와 선만 복원해도 보이는 사각형이 복원되지 않을 수 있습니다. 추가 효과나 복잡한 서식이 있는 템플릿은 이러한 설정도 처리해야 합니다.
Change Text in a Placeholder
제목, 중앙 제목, 부제목, 본문 및 텍스트 플레이스홀더는 일반적으로 텍스트를 지원합니다. IAutoShape인지 확인한 후 해당 도형의 get_TextFrame 메서드를 사용하십시오.
다음 예제는 첫 번째 슬라이드의 첫 번째 제목 플레이스홀더를 업데이트하고 결과를 저장합니다:
#include <DOM/IAutoShape.h>
#include <DOM/IPlaceholder.h>
#include <DOM/IShape.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/ITextFrame.h>
#include <DOM/PlaceholderType.h>
#include <DOM/Presentation.h>
#include <Export/SaveFormat.h>
#include <system/exceptions.h>
#include <system/object_ext.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace System;
auto presentation = MakeObject<Presentation>(u"template.pptx");
auto slide = presentation->get_Slide(0);
SharedPtr<IAutoShape> titleShape;
for (auto&& shape : slide->get_Shapes())
{
if (!ObjectExt::Is<IAutoShape>(shape))
{
continue;
}
auto autoShape = ExplicitCast<IAutoShape>(shape);
auto placeholder = autoShape->get_Placeholder();
if (placeholder == nullptr)
{
continue;
}
auto placeholderType = placeholder->get_Type();
if (placeholderType == PlaceholderType::Title || placeholderType == PlaceholderType::CenteredTitle)
{
titleShape = autoShape;
break;
}
}
if (titleShape == nullptr)
{
throw InvalidOperationException(u"The first slide does not contain a title placeholder.");
}
titleShape->get_TextFrame()->set_Text(u"Quarterly Business Review");
presentation->Save(u"title-placeholder-updated.pptx", SaveFormat::Pptx);
이 패턴은 그림, 차트, 표 또는 미디어 플레이스홀더를 IAutoShape으로 캐스팅하는 것을 방지합니다. 또한 취약한 도형 인덱스에 의존하지 않고 목적에 따라 플레이스홀더를 식별합니다.
Set Prompt Text on a Layout
프롬프트 텍스트는 빈 플레이스홀더에 표시되는 디자인‑타임 안내문으로, 예를 들어 Click to add title와 같습니다. 일반 슬라이드의 도형 컬렉션을 통해 접근하려 하기보다 레이아웃 플레이스홀더에 사용자 지정 프롬프트 텍스트를 설정하십시오. 레이아웃은 ISlide::get_LayoutSlide로 가져오고, IBaseSlide::get_Shapes를 순회합니다.
다음 예제는 첫 번째 슬라이드에 사용된 레이아웃의 제목 및 부제목 프롬프트를 변경합니다:
#include <DOM/IAutoShape.h>
#include <DOM/ILayoutSlide.h>
#include <DOM/IPlaceholder.h>
#include <DOM/IShape.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/ITextFrame.h>
#include <DOM/PlaceholderType.h>
#include <DOM/Presentation.h>
#include <Export/SaveFormat.h>
#include <system/object_ext.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace System;
auto presentation = MakeObject<Presentation>(u"template.pptx");
auto layoutSlide = presentation->get_Slide(0)->get_LayoutSlide();
for (auto&& shape : layoutSlide->get_Shapes())
{
if (!ObjectExt::Is<IAutoShape>(shape))
{
continue;
}
auto autoShape = ExplicitCast<IAutoShape>(shape);
auto placeholder = autoShape->get_Placeholder();
if (placeholder == nullptr)
{
continue;
}
switch (placeholder->get_Type())
{
case PlaceholderType::Title:
case PlaceholderType::CenteredTitle:
autoShape->get_TextFrame()->set_Text(u"Enter a concise slide title");
break;
case PlaceholderType::Subtitle:
autoShape->get_TextFrame()->set_Text(u"Enter a subtitle or reporting period");
break;
default:
break;
}
}
presentation->Save(u"custom-placeholder-prompts.pptx", SaveFormat::Pptx);
프롬프트 텍스트는 일반 슬라이드 콘텐츠가 아닙니다. PowerPoint와 같은 편집 애플리케이션에서 빈 플레이스홀더에 표시되는 안내문이며, 사용자가 실제 콘텐츠를 제공하면 더 이상 표시되지 않습니다. 프롬프트를 변경해도 해당 레이아웃을 사용하는 슬라이드의 기존 텍스트가 대체되지 않습니다.
Update a Picture Placeholder
다음 두 경우를 처리해야 합니다:
- 그림 플레이스홀더가 이미 채워져 있고 IPictureFrame으로 표시되는 경우, IPictureFillFormat::get_Picture와 ISlidesPicture::set_Image를 통해 이미지를 교체합니다.
- 아직 빈 플레이스홀더인 경우, IShapeCollection::AddPictureFrame으로 플레이스홀더 좌표에 그림 프레임을 추가하고 빈 플레이스홀더를 제거합니다.
다음 예제는 두 경우를 모두 지원하고 프레젠테이션을 저장합니다:
#include <DOM/IImageCollection.h>
#include <DOM/IPictureFillFormat.h>
#include <DOM/IPictureFrame.h>
#include <DOM/IPlaceholder.h>
#include <DOM/IShape.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/ISlidesPicture.h>
#include <DOM/PlaceholderType.h>
#include <DOM/Presentation.h>
#include <DOM/ShapeType.h>
#include <Export/SaveFormat.h>
#include <system/exceptions.h>
#include <system/io/file.h>
#include <system/object_ext.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace System;
using namespace System::IO;
auto presentation = MakeObject<Presentation>(u"picture-template.pptx");
auto slide = presentation->get_Slide(0);
SharedPtr<IShape> picturePlaceholder;
for (auto&& shape : slide->get_Shapes())
{
auto placeholder = shape->get_Placeholder();
if (placeholder != nullptr && placeholder->get_Type() == PlaceholderType::Picture)
{
picturePlaceholder = shape;
break;
}
}
if (picturePlaceholder == nullptr)
{
throw InvalidOperationException(u"The first slide does not contain a picture placeholder.");
}
auto imageBytes = File::ReadAllBytes(u"replacement.png");
auto image = presentation->get_Images()->AddImage(imageBytes);
if (ObjectExt::Is<IPictureFrame>(picturePlaceholder))
{
auto pictureFrame = ExplicitCast<IPictureFrame>(picturePlaceholder);
pictureFrame->get_PictureFormat()->get_Picture()->set_Image(image);
}
else
{
auto x = picturePlaceholder->get_X();
auto y = picturePlaceholder->get_Y();
auto width = picturePlaceholder->get_Width();
auto height = picturePlaceholder->get_Height();
auto shapes = slide->get_Shapes();
shapes->AddPictureFrame(ShapeType::Rectangle, x, y, width, height, image);
shapes->Remove(picturePlaceholder);
}
presentation->Save(u"picture-placeholder-updated.pptx", SaveFormat::Pptx);
빈 플레이스홀더에 대해 만든 교체물은 새로운 플레이스홀더가 아니라 로컬 그림 프레임이며, IShape::get_Placeholder이 읽기 전용이기 때문입니다. 예약된 위치는 유지되지만 플레이스홀더 특유의 동작을 더 이상 상속하지 않습니다. 플레이스홀더 관계를 유지해야 한다면 먼저 PowerPoint에서 플레이스홀더를 준비·채우고, 이후 Aspose.Slides로 해당 IPictureFrame을 업데이트하십시오.
그림 투명도, 자르기 및 기타 그림 전용 효과에 대해서는 Manage Picture Frames를 참고하십시오. 이러한 작업은 그림 프레임 또는 그림 채우기와 관련이 있으며 플레이스홀더 메타데이터와는 무관합니다.
Work with Chart and Content Placeholders
채워진 차트 플레이스홀더는 IChart으로 표시될 수 있습니다. 이 예제는 플레이스홀더 유형과 런타임 인터페이스를 모두 확인하여 차트를 찾고, 차트 제목을 변경한 뒤 파일을 저장합니다:
#include <DOM/IChart.h>
#include <DOM/Chart/IChartTitle.h>
#include <DOM/IPlaceholder.h>
#include <DOM/IShape.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/PlaceholderType.h>
#include <DOM/Presentation.h>
#include <Export/SaveFormat.h>
#include <system/exceptions.h>
#include <system/object_ext.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Charts;
using namespace Aspose::Slides::Export;
using namespace System;
auto presentation = MakeObject<Presentation>(u"chart-template.pptx");
auto slide = presentation->get_Slide(0);
SharedPtr<IChart> placeholderChart;
for (auto&& shape : slide->get_Shapes())
{
if (!ObjectExt::Is<IChart>(shape))
{
continue;
}
auto chart = ExplicitCast<IChart>(shape);
auto placeholder = chart->get_Placeholder();
if (placeholder != nullptr && placeholder->get_Type() == PlaceholderType::Chart)
{
placeholderChart = chart;
break;
}
}
if (placeholderChart == nullptr)
{
throw InvalidOperationException(u"The first slide does not contain a populated chart placeholder.");
}
placeholderChart->set_HasTitle(true);
placeholderChart->get_ChartTitle()->AddTextFrameForOverriding(u"Quarterly Revenue");
presentation->Save(u"chart-placeholder-updated.pptx", SaveFormat::Pptx);
일반 콘텐츠 플레이스홀더는 보통 PlaceholderType::Object를 가집니다. PowerPoint에서 이는 차트, 표, 다이어그램, 그림, 미디어 등 다양한 콘텐츠 유형의 시작점 역할을 합니다. 콘텐츠가 채워진 후에는 실제 도형 인터페이스를 검사하여 포함된 내용을 파악해야 합니다. 특수 레이아웃은 PlaceholderType::Chart, PlaceholderType::Table, PlaceholderType::Picture, PlaceholderType::Media, PlaceholderType::Diagram 등을 노출할 수 있습니다.
Aspose.Slides는 IPlaceholder::get_Type을 변경한다고 해서 빈 IAutoShape 플레이스홀더가 자동으로 IChart로 변환되지 않으며, 유형은 읽기 전용입니다. 빈 차트 또는 콘텐츠 영역을 프로그래밍 방식으로 채우려면 해당 좌표에 필요한 객체를 추가한 다음 빈 플레이스홀더를 제거하십시오. 다음 예제는 차트에 대해 이를 수행합니다:
#include <DOM/Chart/ChartType.h>
#include <DOM/IChart.h>
#include <DOM/Chart/IChartTitle.h>
#include <DOM/IPlaceholder.h>
#include <DOM/IShape.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/PlaceholderType.h>
#include <DOM/Presentation.h>
#include <Export/SaveFormat.h>
#include <system/exceptions.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Charts;
using namespace Aspose::Slides::Export;
using namespace System;
auto presentation = MakeObject<Presentation>(u"content-template.pptx");
auto slide = presentation->get_Slide(0);
SharedPtr<IShape> targetPlaceholder;
for (auto&& shape : slide->get_Shapes())
{
auto placeholder = shape->get_Placeholder();
if (placeholder == nullptr)
{
continue;
}
auto placeholderType = placeholder->get_Type();
if (placeholderType == PlaceholderType::Chart || placeholderType == PlaceholderType::Object)
{
targetPlaceholder = shape;
break;
}
}
if (targetPlaceholder == nullptr)
{
throw InvalidOperationException(u"The first slide does not contain a chart or content placeholder.");
}
auto x = targetPlaceholder->get_X();
auto y = targetPlaceholder->get_Y();
auto width = targetPlaceholder->get_Width();
auto height = targetPlaceholder->get_Height();
auto shapes = slide->get_Shapes();
auto chart = shapes->AddChart(ChartType::ClusteredColumn, x, y, width, height);
chart->set_HasTitle(true);
chart->get_ChartTitle()->AddTextFrameForOverriding(u"Quarterly Revenue");
shapes->Remove(targetPlaceholder);
presentation->Save(u"content-placeholder-replaced-with-chart.pptx", SaveFormat::Pptx);
추가된 차트는 일반 로컬 차트이며, 플레이스홀더 영역을 차지하지만 레이아웃 플레이스홀더로부터 상속되지 않습니다. 차트의 범주, 시리즈 또는 워크북 데이터를 교체해야 할 경우 전용 차트 관리 문서를 참고하십시오.
Complete Example: Update Text or Image Content
다음 전체 예제는 템플릿을 열고, 첫 번째 슬라이드에서 제목 또는 그림 플레이스홀더를 검색하고, 플레이스홀더와 도형 유형을 확인한 뒤 적절한 콘텐츠를 업데이트하고 결과를 저장합니다. 이 예제는 도형 인덱스에 의존하거나 모든 플레이스홀더를 동일한 인터페이스로 캐스팅하는 것을 의도적으로 피합니다.
#include <DOM/IAutoShape.h>
#include <DOM/IImageCollection.h>
#include <DOM/IPictureFillFormat.h>
#include <DOM/IPictureFrame.h>
#include <DOM/IPlaceholder.h>
#include <DOM/IShape.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/ISlidesPicture.h>
#include <DOM/ITextFrame.h>
#include <DOM/PlaceholderType.h>
#include <DOM/Presentation.h>
#include <DOM/ShapeType.h>
#include <Export/SaveFormat.h>
#include <system/exceptions.h>
#include <system/io/file.h>
#include <system/object_ext.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace System;
using namespace System::IO;
auto presentation = MakeObject<Presentation>(u"template.pptx");
auto slide = presentation->get_Slide(0);
auto updated = false;
for (auto&& shape : slide->get_Shapes())
{
auto placeholder = shape->get_Placeholder();
if (placeholder == nullptr)
{
continue;
}
auto placeholderType = placeholder->get_Type();
if ((placeholderType == PlaceholderType::Title || placeholderType == PlaceholderType::CenteredTitle) && ObjectExt::Is<IAutoShape>(shape))
{
auto titleShape = ExplicitCast<IAutoShape>(shape);
titleShape->get_TextFrame()->set_Text(u"Quarterly Business Review");
updated = true;
break;
}
if (placeholderType == PlaceholderType::Picture)
{
auto imageBytes = File::ReadAllBytes(u"replacement.png");
auto image = presentation->get_Images()->AddImage(imageBytes);
if (ObjectExt::Is<IPictureFrame>(shape))
{
auto pictureFrame = ExplicitCast<IPictureFrame>(shape);
pictureFrame->get_PictureFormat()->get_Picture()->set_Image(image);
}
else
{
auto x = shape->get_X();
auto y = shape->get_Y();
auto width = shape->get_Width();
auto height = shape->get_Height();
auto shapes = slide->get_Shapes();
shapes->AddPictureFrame(ShapeType::Rectangle, x, y, width, height, image);
shapes->Remove(shape);
}
updated = true;
break;
}
}
if (!updated)
{
throw InvalidOperationException(u"No supported title or picture placeholder was found on the first slide.");
}
presentation->Save(u"placeholder-content-updated.pptx", SaveFormat::Pptx);
FAQ
What is a base placeholder?
기본 플레이스홀더는 레이아웃이나 마스터에 있는 해당 도형으로, 다른 플레이스홀더가 상속받는 대상입니다. 이를 가져오려면 IShape::GetBasePlaceholder를 사용하십시오. 일반 로컬 도형은 플레이스홀더 계층에 포함되지 않으므로 nullptr를 반환합니다.
Can I change all slide titles by editing a layout placeholder?
레이아웃을 통해 상속된 서식이나 프롬프트 텍스트는 변경할 수 있지만, 기존 제목 내용은 일반 슬라이드에 저장됩니다. 프레젠테이션 전체의 실제 제목 텍스트를 교체하려면 슬라이드를 순회하면서 각 제목 플레이스홀더를 업데이트해야 합니다.
How do I manage date, slide-number, header, and footer placeholders?
해당 슬라이드, 레이아웃, 마스터, 노트 또는 유인물 범위에서 헤더 및 푸터 관리자를 사용하십시오. 자세한 예제는 Manage Presentation Header and Footer를 참고하십시오.