Aspose::Words::Tables::Cell::get_CellFormat method
Содержание
[
Скрывать
]Cell::get_CellFormat method
Предоставляет доступ к свойствам форматирования ячейки.
System::SharedPtr<Aspose::Words::Tables::CellFormat> Aspose::Words::Tables::Cell::get_CellFormat()
Примеры
Показывает, как изменить формат строк и ячеек в таблице.
auto doc = System::MakeObject<Aspose::Words::Document>();
auto builder = System::MakeObject<Aspose::Words::DocumentBuilder>(doc);
System::SharedPtr<Aspose::Words::Tables::Table> table = builder->StartTable();
builder->InsertCell();
builder->Write(u"City");
builder->InsertCell();
builder->Write(u"Country");
builder->EndRow();
builder->InsertCell();
builder->Write(u"London");
builder->InsertCell();
builder->Write(u"U.K.");
builder->EndTable();
// Используйте свойство "RowFormat" первой строки, чтобы изменить форматирование
// содержимого всех ячеек в этой строке.
System::SharedPtr<Aspose::Words::Tables::RowFormat> rowFormat = table->get_FirstRow()->get_RowFormat();
rowFormat->set_Height(25);
rowFormat->get_Borders()->idx_get(Aspose::Words::BorderType::Bottom)->set_Color(System::Drawing::Color::get_Red());
// Используйте свойство "CellFormat" первой ячейки в последней строке, чтобы изменить форматирование содержимого этой ячейки.
System::SharedPtr<Aspose::Words::Tables::CellFormat> cellFormat = table->get_LastRow()->get_FirstCell()->get_CellFormat();
cellFormat->set_Width(100);
cellFormat->get_Shading()->set_BackgroundPatternColor(System::Drawing::Color::get_Orange());
doc->Save(get_ArtifactsDir() + u"Table.RowCellFormat.docx");
Показывает, как изменить форматирование ячейки таблицы.
auto doc = System::MakeObject<Aspose::Words::Document>(get_MyDir() + u"Tables.docx");
System::SharedPtr<Aspose::Words::Tables::Table> table = doc->get_FirstSection()->get_Body()->get_Tables()->idx_get(0);
System::SharedPtr<Aspose::Words::Tables::Cell> firstCell = table->get_FirstRow()->get_FirstCell();
// Используйте свойство "CellFormat" ячейки, чтобы задать форматирование, изменяющее внешний вид этой ячейки.
firstCell->get_CellFormat()->set_Width(30);
firstCell->get_CellFormat()->set_Orientation(Aspose::Words::TextOrientation::Downward);
firstCell->get_CellFormat()->get_Shading()->set_ForegroundPatternColor(System::Drawing::Color::get_LightGreen());
doc->Save(get_ArtifactsDir() + u"Table.CellFormat.docx");
Показывает, как объединить строки из двух таблиц в одну.
auto doc = System::MakeObject<Aspose::Words::Document>(get_MyDir() + u"Tables.docx");
// Ниже представлены два способа получения таблицы из документа.
// 1 - Из коллекции "Tables" узла Body:
System::SharedPtr<Aspose::Words::Tables::Table> firstTable = doc->get_FirstSection()->get_Body()->get_Tables()->idx_get(0);
// 2 - С использованием метода "GetChild":
auto secondTable = System::ExplicitCast<Aspose::Words::Tables::Table>(doc->GetChild(Aspose::Words::NodeType::Table, 1, true));
// Добавьте все строки из текущей таблицы к следующей.
while (secondTable->get_HasChildNodes())
{
firstTable->get_Rows()->Add(secondTable->get_FirstRow());
}
// Удалите пустой контейнер таблицы.
secondTable->Remove();
doc->Save(get_ArtifactsDir() + u"Table.CombineTables.docx");
См. также
- Class CellFormat
- Class Cell
- Namespace Aspose::Words::Tables
- Library Aspose.Words for C++