使用C++设置形状或文本框中的段落行间距
Contents
[
Hide
]
您可以使用TextParagraph.GetLineSpace()、TextParagraph.GetSpaceBefore()和TextParagraph.GetSpaceAfter()属性分别设置段落的行间距、前置距离和后置距离,其中TextParagraph类。
以下示例代码解释了所述属性的用法。
#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;
using namespace Aspose::Cells::Drawing;
using namespace Aspose::Cells::Drawing::Texts;
int main()
{
Aspose::Cells::Startup();
// Source directory path
U16String srcDir(u"..\\Data\\01_SourceDirectory\\");
// Output directory path
U16String outDir(u"..\\Data\\02_OutputDirectory\\");
// Create a workbook
Workbook wb;
// Access first worksheet
Worksheet ws = wb.GetWorksheets().Get(0);
// Add text box inside the sheet
ws.GetShapes().AddTextBox(2, 0, 2, 0, 100, 200);
// Access first shape which is a text box and set its text
Shape shape = ws.GetShapes().Get(0);
shape.SetText(u"Sign up for your free phone number.\nCall and text online for free.");
// Access the first paragraph
TextParagraph p = shape.GetTextBody().GetTextParagraphs().Get(1);
// Set the line space
p.SetLineSpaceSizeType(LineSpaceSizeType::Points);
p.SetLineSpace(20);
// Set the space after
p.SetSpaceAfterSizeType(LineSpaceSizeType::Points);
p.SetSpaceAfter(10);
// Set the space before
p.SetSpaceBeforeSizeType(LineSpaceSizeType::Points);
p.SetSpaceBefore(10);
// Save the workbook in xlsx format
wb.Save(outDir + u"output_out.xlsx", SaveFormat::Xlsx);
std::cout << "Workbook saved successfully!" << std::endl;
Aspose::Cells::Cleanup();
}