Verwalten von Shape Textoptionen mit C++

Verwalten von Shape-Textoptionen

Aspose.Cells ermöglicht es Ihnen, den Text innerhalb von Formen in Excel-Dateien anzupassen. Die Klasse Shape stellt Methoden und Eigenschaften zur Verwaltung von Texteinstellungen wie Ausrichtung, Orientierung und Formatierung bereit.

Textausrichtung festlegen

Sie können die horizontale und vertikale Ausrichtung des Textes innerhalb einer Form mit den Eigenschaften GetTextHorizontalAlignment() und GetTextVerticalAlignment() einstellen.

#include <Aspose.Cells.h>

using namespace Aspose::Cells;
using namespace Aspose::Cells::Drawing;

void SetTextAlignment() {
    // Load the Excel file
    Workbook workbook("example.xlsx");
    Worksheet worksheet = workbook.GetWorksheets().Get(0);

    // Access the shape
    Shape shape = worksheet.GetShapes().Get(0);

    // Set text alignment
    shape.SetTextHorizontalAlignment(TextAlignmentType::Center);
    shape.SetTextVerticalAlignment(TextAlignmentType::Center);

    // Save the workbook
    workbook.Save("output.xlsx");
}

Textrichtung festlegen

Sie können auch die Orientierung des Textes innerhalb einer Form mit der Eigenschaft TextOrientationType einstellen.

#include <Aspose.Cells.h>

using namespace Aspose::Cells;
using namespace Aspose::Cells::Drawing;

void SetTextOrientation() {
    Workbook workbook("example.xlsx");
    Worksheet worksheet = workbook.GetWorksheets().Get(0);

    TextBox textbox = worksheet.GetTextBoxes().Get(0);
    textbox.SetTextOrientationType(TextOrientationType::ClockWise);

    workbook.Save("output.xlsx");
}

Formatierung des Textes

Sie können den Text innerhalb einer Form mit der Klasse Font formatieren. Damit lassen sich Eigenschaften wie Schriftgröße, Farbe und Stil festlegen.

#include <Aspose.Cells.h>

using namespace Aspose::Cells;
using namespace Aspose::Cells::Drawing;

void FormatText() {
    // Load the Excel file
    Workbook workbook("example.xlsx");
    Worksheet worksheet = workbook.GetWorksheets().Get(0);

    // Access the shape
    Shape shape = worksheet.GetShapes().Get(0);

    // Access the font of the shape's text
    Font font = shape.GetTextBody().GetParagraphEnumerator().GetCurrent().GetFont();

    // Set font properties
    font.SetSize(14);
    font.SetColor(Color::Red());
    font.SetIsBold(true);

    // Save the workbook
    workbook.Save("output.xlsx");
}

Fazit

Aspose.Cells for C++ bietet eine umfassende Palette an Werkzeugen zur Verwaltung von Shape-Textoptionen in Excel-Dateien. Durch die Verwendung der Klasse Shape können Sie Textausrichtung, Orientierung und Formatierung einfach an Ihre Anforderungen anpassen.