クイックスタート

クイックスタート

クイックスタート

このガイドでは、CMake のセットアップから .pptx ファイルを保存するまでの最速パスを、C++ 用の aspose_slides_foss を使用して示します。ライブラリは MIT ライセンスで、Microsoft Office は不要です。また、C++20 コンパイラと CMake 3.20 以降があれば、任意のプラットフォームでビルドできます。


前提条件

要件詳細
C++ 標準C++20 以降
CMake3.20 以降
OSWindows、macOS、Linux
Packageaspose_slides_foss を CMake で FetchContent

Install

CMake FetchContent を使用して構成時にライブラリを取得します。以下を CMakeLists.txt に追加し、aspose_slides_foss にリンクしてください:

include(FetchContent)
FetchContent_Declare(
    aspose_slides_foss
    GIT_REPOSITORY https://github.com/aspose-slides-foss/Aspose.Slides-FOSS-for-Cpp.git
    GIT_TAG main
)
FetchContent_MakeAvailable(aspose_slides_foss)
target_link_libraries(your_target PRIVATE aspose_slides_foss)

プレゼンテーションを作成

Presentation を引数なしで構築して空のデッキを作成し、次にパスと SaveFormat::PPTX を指定して save() を呼び出します。ライブラリは自動的に空のスライドを 1 枚追加します:

#include <Aspose/Slides/Foss/presentation.h>
#include <Aspose/Slides/Foss/export/save_format.h>

using namespace Aspose::Slides::Foss;

int main() {
    Presentation prs;
    prs.save("empty.pptx", SaveFormat::PPTX);
    return 0;
}

テキスト付きシェイプを追加

最初のスライドに prs.slides()[0] でアクセスし、shapes().add_auto_shape() で長方形を挿入し、text_frame()->set_text() でテキストを設定します:

#include <Aspose/Slides/Foss/auto_shape.h>
#include <Aspose/Slides/Foss/presentation.h>
#include <Aspose/Slides/Foss/shape_type.h>
#include <Aspose/Slides/Foss/text_frame.h>
#include <Aspose/Slides/Foss/export/save_format.h>

using namespace Aspose::Slides::Foss;

int main() {
    Presentation prs;
    auto& slide = prs.slides()[0];
    auto& shape = slide.shapes().add_auto_shape(
        ShapeType::RECTANGLE, 50, 50, 400, 150
    );
    shape.text_frame()->set_text("Hello from Aspose.Slides FOSS!");
    prs.save("with_shape.pptx", SaveFormat::PPTX);
    return 0;
}

単色塗りつぶしを適用

シェイプに対して fill_format().set_fill_type(FillType::SOLID) を呼び出し、solid_fill_color().set_color() で ARGB カラーを指定してから、save() を呼び出します:

#include <Aspose/Slides/Foss/auto_shape.h>
#include <Aspose/Slides/Foss/fill_format.h>
#include <Aspose/Slides/Foss/fill_type.h>
#include <Aspose/Slides/Foss/presentation.h>
#include <Aspose/Slides/Foss/shape_type.h>
#include <Aspose/Slides/Foss/export/save_format.h>

using namespace Aspose::Slides::Foss;

int main() {
    Presentation prs;
    auto& shape = prs.slides()[0].shapes().add_auto_shape(
        ShapeType::RECTANGLE, 100, 100, 400, 200
    );
    shape.fill_format().set_fill_type(FillType::SOLID);
    shape.fill_format().solid_fill_color().set_color(0xFF, 0x46, 0x82, 0xB4);
    shape.text_frame()->set_text("Styled shape");
    prs.save("styled.pptx", SaveFormat::PPTX);
    return 0;
}

既存のファイルをロード

ファイルパス文字列を Presentation コンストラクタに渡して、既存の .pptx ファイルをロードします。必要に応じてデッキを変更し、最後に save() を呼び出して出力を書き込みます:

#include <Aspose/Slides/Foss/presentation.h>
#include <Aspose/Slides/Foss/export/save_format.h>

using namespace Aspose::Slides::Foss;

int main() {
    Presentation prs("existing.pptx");
    prs.save("copy.pptx", SaveFormat::PPTX);
    return 0;
}

次のステップ

参照

 日本語