PNG JPG BMP TIFF PPT
Aspose.Slides  for C++

C++ 中的 PPT 格式图表

使用 C++ API 的服务器端 Aspose.Slides 的原生和高性能 PPT 文档图表,无需使用 Microsoft 或 Adob​​e PDF 等任何软件。

如何使用 C++ 创建 PPT 文件图表

为了搜索 PPT 文件,我们将使用

Aspose.Slides for C++

API 是一个功能丰富、功能强大且易于使用的 C++ 平台文档搜索 API。可以直接下载最新版本,直接打开

NuGet

包管理器,搜索 Aspose.Slides.Cpp 并安装。您也可以从包管理器控制台使用以下命令。

命令


PM> Install-Package Aspose.Slides.Cpp

在 C++ 中创建 PPT 文件图表的步骤

只需几行代码即可使用 Aspose.Slides for C++ API 绘制基本文档图表。

  1. 实例化演示类。

  2. 访问第一张幻灯片。

  3. 添加带有默认数据的图表

  4. 设置图表数据表的索引。

  5. 获取图表数据工作簿。

  6. 设置图表标题。

  7. 删除默认生成的系列和类别。

  8. 添加系列和类别。

  9. 获取第一个图表系列并填充数据。

  10. 为系列设置填充颜色。

  11. 保存PPT文件。

系统要求

Aspose.Slides for C++ 支持所有主要平台和操作系统。请确保您具有以下先决条件。

  • Microsoft Windows 或具有适用于 Windows 32 位、Windows 64 位和 Linux 64 位的 C++ 运行时环境的兼容操作系统。
  • 项目中引用的 C++ DLL 的 Aspose.Slides。
 

创建 PPT 文件图表 - C++

// Output File Path.
const String outputFilePath = u"OutputDirectory\\column_chart.ppt";

// Instantiate Presentation class
SharedPtr<Presentation> pres = MakeObject<Presentation>();

// Access first slide
SharedPtr<ISlide> slide = pres->get_Slides()->idx_get(0);

// Add chart with default data
SharedPtrv<IChart> chart = slide->get_Shapes()->AddChart(Aspose::Slides::Charts::ChartType::ClusteredColumn, 0, 0, 500, 500);

// Setting the index of chart data sheet
int defaultWorksheetIndex = 0;

// Getting the chart data workbook
SharedPtr<IChartDataWorkbook> fact = chart->get_ChartData()->get_ChartDataWorkbook();

// Setting chart Title
chart->get_ChartTitle()->AddTextFrameForOverriding(u"Sample Title");
chart->get_ChartTitle()->get_TextFrameForOverriding()->get_TextFrameFormat()->set_CenterText(NullableBool::True);
chart->get_ChartTitle()->set_Height(20);
chart->set_HasTitle(true);

// Delete default generated series and categories
chart->get_ChartData()->get_Series()->Clear();
chart->get_ChartData()->get_Categories()->Clear();
int s = chart->get_ChartData()->get_Series()->get_Count();
s = chart->get_ChartData()->get_Categories()->get_Count();

// Add series
chart->get_ChartData()->get_Series()->Add(fact->GetCell(defaultWorksheetIndex, 0, 1, ObjectExt::Box<System::String>(u"Series 1")), chart->get_Type());
chart->get_ChartData()->get_Series()->Add(fact->GetCell(defaultWorksheetIndex, 0, 2, ObjectExt::Box<System::String>(u"Series 2")), chart->get_Type());

// Add categories
chart->get_ChartData()->get_Categories()->Add(fact->GetCell(defaultWorksheetIndex, 1, 0, ObjectExt::Box<System::String>(u"Category 1")));
chart->get_ChartData()->get_Categories()->Add(fact->GetCell(defaultWorksheetIndex, 2, 0, ObjectExt::Box<System::String>(u"Category 2")));
chart->get_ChartData()->get_Categories()->Add(fact->GetCell(defaultWorksheetIndex, 3, 0, ObjectExt::Box<System::String>(u"Category 3")));

// Take first chart series
SharedPtr<IChartSeries> series = chart->get_ChartData()->get_Series()->idx_get(0);

// Populate series data
series->get_DataPoints()->AddDataPointForBarSeries(fact->GetCell(defaultWorksheetIndex, 1, 1, ObjectExt::Box(20)));
series->get_DataPoints()->AddDataPointForBarSeries(fact->GetCell(defaultWorksheetIndex, 2, 1, ObjectExt::Box(50)));
series->get_DataPoints()->AddDataPointForBarSeries(fact->GetCell(defaultWorksheetIndex, 3, 1, ObjectExt::Box(30)));

// Setting fill color for series
series->get_Format()->get_Fill()->set_FillType(FillType::Solid);
series->get_Format()->get_Fill()->get_SolidFillColor()->set_Color(System::Drawing::Color::get_Blue());

// Take second chart series
series = chart->get_ChartData()->get_Series()->idx_get(1);

// Populate series data
series->get_DataPoints()->AddDataPointForBarSeries(fact->GetCell(defaultWorksheetIndex, 1, 2, ObjectExt::Box(30)));
series->get_DataPoints()->AddDataPointForBarSeries(fact->GetCell(defaultWorksheetIndex, 2, 2, ObjectExt::Box(10)));
series->get_DataPoints()->AddDataPointForBarSeries(fact->GetCell(defaultWorksheetIndex, 3, 2, ObjectExt::Box(60)));

// Setting fill color for series
series->get_Format()->get_Fill()->set_FillType(FillType::Solid);
series->get_Format()->get_Fill()->get_SolidFillColor()->set_Color(System::Drawing::Color::get_Orange());

// First label will be show Category name
SharedPtr<IDataLabel> lbl = series->get_DataPoints()->idx_get(0)->get_Label();
lbl->get_DataLabelFormat()->set_ShowCategoryName(true);

lbl = series->get_DataPoints()->idx_get(1)->get_Label();
lbl->get_DataLabelFormat()->set_ShowSeriesName(true);

// Show value for third label
lbl = series->get_DataPoints()->idx_get(2)->get_Label();
lbl->get_DataLabelFormat()->set_ShowValue(true);
lbl->get_DataLabelFormat()->set_ShowSeriesName(true);
lbl->get_DataLabelFormat()->set_Separator(u"/");

// Save PPT file
pres->Save(outputFilePath, Aspose::Slides::Export::SaveFormat::Ppt);  

    
 
  • 关于 Aspose.Slides for C++ API

    立即通过访问我们的生成 PPT 文档图表

    现场演示网站

    .现场演示有以下好处

    Online PPT Chart Creation Live Demos

    Generate PPT documents charts right now by visiting our Live Demos website . The live demo has the following benefits

      No need to download Aspose API.
      No need to write any code.
      Just upload your PPT files.
      Chart will be created instantly.

    PPT 什么是PPT文件格式

    A file with PPT extension represents PowerPoint file that consists of a collection of slides for displaying as SlideShow. It specifies the Binary File Format used by Microsoft PowerPoint 97-2003. A PPT file can contain several different types of information such as text, bulleted points, images, multimedia and other embedded OLE objects. Microsoft came up with newer file format for PowerPoint, known as PPTX, from 2007 onwards that is based on Office OpenXML and is different from this binary file format. Several other application programs such as OpenOffice Impress and Apple Keynote can also create PPT files.

    阅读更多

    其他支持的图表格式

    使用 C++,可以轻松处理不同格式的字符,包括。

    PPTX (打开 XML 表示格式)