You can find detailed information at: Create and Manipulate Tables in PowerPoint using C++
Last active
October 25, 2021 12:16
-
-
Save aspose-com-gists/20ed166c69499bf66b105b8cc809ea45 to your computer and use it in GitHub Desktop.
Create and Manipulate Tables in PowerPoint using C++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment