原創|使用教程|編輯:張瑩心|2021-11-02 09:46:46.983|閱讀 483 次
概述:Microsoft PowerPoint 提供了在 PowerPoint 演示文稿中插入表格的功能。表格允許以行和列的形式排列數據。此外,它們組織數據并使其易于查看和分析。為此,本文將教您如何使用 C++ 在 PowerPoint 演示文稿中創建和操作表格。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
Microsoft PowerPoint 提供了在 PowerPoint 演示文稿中插入表格的功能。表格允許以行和列的形式排列數據。此外,它們組織數據并使其易于查看和分析。為此,本文將教您如何使用 C++ 在 PowerPoint 演示文稿中創建和操作表格。
>>你可以點擊這里下載Aspose.Slides 最新版測試體驗。
// File path const String outputFilePath = u"OutputDirectory\\CreateTable_out.pptx"; // Create an instance of the Presentation class auto presentation = System::MakeObject<Presentation>(); // Access first slide SharedPtr<ISlide> slide = presentation->get_Slides()->idx_get(0); // Define columns with widths and rows with heights System::ArrayPtr<double> dblCols = System::MakeObject<System::Array<double>>(4, 70); System::ArrayPtr<double> dblRows = System::MakeObject<System::Array<double>>(4, 70); // Add table shape to slide SharedPtr<ITable> table = slide->get_Shapes()->AddTable(100, 50, dblCols, dblRows); // Set border format for each cell for (int x = 0; x < table->get_Rows()->get_Count(); x++) { SharedPtr<IRow> row = table->get_Rows()->idx_get(x); for (int y = 0; y < row->get_Count(); y++) { SharedPtr<ICell> cell = row->idx_get(y); cell->get_CellFormat()->get_BorderTop()->get_FillFormat()->set_FillType(FillType::Solid); cell->get_CellFormat()->get_BorderTop()->get_FillFormat()->get_SolidFillColor()->set_Color(System::Drawing::Color::get_Red()); cell->get_CellFormat()->get_BorderTop()->set_Width(5); cell->get_CellFormat()->get_BorderBottom()->get_FillFormat()->set_FillType(FillType::Solid); cell->get_CellFormat()->get_BorderBottom()->get_FillFormat()->get_SolidFillColor()->set_Color(System::Drawing::Color::get_Red()); cell->get_CellFormat()->get_BorderBottom()->set_Width(5); cell->get_CellFormat()->get_BorderLeft()->get_FillFormat()->set_FillType(FillType::Solid); cell->get_CellFormat()->get_BorderLeft()->get_FillFormat()->get_SolidFillColor()->set_Color(System::Drawing::Color::get_Red()); cell->get_CellFormat()->get_BorderLeft()->set_Width(5); cell->get_CellFormat()->get_BorderRight()->get_FillFormat()->set_FillType(FillType::Solid); cell->get_CellFormat()->get_BorderRight()->get_FillFormat()->get_SolidFillColor()->set_Color(System::Drawing::Color::get_Red()); cell->get_CellFormat()->get_BorderRight()->set_Width(5); } } // Save Presentation presentation->Save(outputFilePath, Aspose::Slides::Export::SaveFormat::Pptx);
示例代碼生成的輸出圖像:
// File paths const String sourceFilePath = u"OutputDirectory\\CreateTable_out.pptx"; const String outputFilePath = u"OutputDirectory\\AccessTable_out.pptx"; // Load the presentation file auto presentation = System::MakeObject<Presentation>(sourceFilePath); // Access first slide SharedPtr<ISlide> slide = presentation->get_Slides()->idx_get(0); // Access the table SharedPtr<ITable> table; for (SharedPtr<IShape> shape : slide->get_Shapes()) { if (System::ObjectExt::Is<ITable>(shape)) { table = System::DynamicCast_noexcept<ITable>(shape); } } // Set text table->idx_get(0, 1)->get_TextFrame()->set_Text(u"Aspose"); // Save Presentation presentation->Save(outputFilePath, Aspose::Slides::Export::SaveFormat::Pptx);
// File paths const String sourceFilePath = u"SourceDirectory\\Slides\\PresentationWithTable.pptx"; const String outputFilePath = u"OutputDirectory\\SetTextDirectionInTable_out.pptx"; // Load the presentation file auto presentation = System::MakeObject<Presentation>(sourceFilePath); // Access first slide SharedPtr<ISlide> slide = presentation->get_Slides()->idx_get(0); // Access the table SharedPtr<ITable> table; for (SharedPtr<IShape> shape : slide->get_Shapes()) { if (System::ObjectExt::Is<ITable>(shape)) { table = System::DynamicCast_noexcept<ITable>(shape); } } // Set text direction SharedPtr<ICell> cell = table->idx_get(0, 1); cell->set_TextAnchorType(TextAnchorType::Center); cell->set_TextVerticalType(TextVerticalType::Vertical270); // Save Presentation presentation->Save(outputFilePath, Aspose::Slides::Export::SaveFormat::Pptx);
示例代碼生成的輸出圖像:
如果你想試用Aspose的全部完整功能,可聯系在線客服獲取30天臨時授權體驗。
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn