用C++设置工作表中的评论或形状的边距

可能的使用场景

Aspose.Cells允许你使用Shape.GetTextAlignment()属性设置任何形状或评论的边距。该属性返回一个Aspose.Cells.Drawing.Texts.ShapeTextAlignment类的对象,该类具有不同的属性例如GetTopMarginPt()GetLeftMarginPt()GetBottomMarginPt()GetRightMarginPt()等,用于设置顶部、左侧、底部和右侧边距。

设置工作表内批注或形状的边距

请查看以下示例代码。它加载包含两个形状的示例Excel文件,代码逐个访问这些形状并设置它们的顶部、左侧、底部和右侧边距。请参阅由代码生成的输出Excel文件以及显示代码对输出Excel文件影响的截图。

todo:image_alt_text

示例代码

#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;

int main()
{
    Aspose::Cells::Startup();

    // For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-C

    // Load the sample Excel file
    Workbook workbook(u"sampleSetMarginsOfCommentOrShapeInsideTheWorksheet.xlsx");

    // Access first worksheet
    Worksheet ws = workbook.GetWorksheets().Get(0);

    // Iterate through each shape in the worksheet
    for (int32_t i = 0; i < ws.GetShapes().GetCount(); i++)
    {
        Shape sh = ws.GetShapes().Get(i);

        // Access the text alignment
        ShapeTextAlignment txtAlign = sh.GetTextBody().GetTextAlignment();

        // Set auto margin false
        txtAlign.SetIsAutoMargin(false);

        // Set the top, left, bottom and right margins
        txtAlign.SetTopMarginPt(10);
        txtAlign.SetLeftMarginPt(10);
        txtAlign.SetBottomMarginPt(10);
        txtAlign.SetRightMarginPt(10);
    }

    // Save the output Excel file
    workbook.Save(u"outputSetMarginsOfCommentOrShapeInsideTheWorksheet.xlsx");

    std::cout << "Margins set successfully!" << std::endl;

    Aspose::Cells::Cleanup();
}