Set Line Spacing of the Paragraph in a Shape or Textbox with Node.js via C++
Contents
[
Hide
]
You can set the line space of the paragraph, its space before and space after using the TextParagraph.getLineSpace(), TextParagraph.getSpaceBefore(), and TextParagraph.getSpaceAfter() properties of the TextParagraph class.
The following sample code explains the usage of the mentioned properties.
const AsposeCells = require("aspose.cells.node");
const path = require("path");
// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
const filePath = path.join(dataDir, "sample.xlsx");
// Create a workbook
const wb = new AsposeCells.Workbook();
// Access first worksheet
const 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
const shape = ws.getShapes().get(0);
shape.setText("Sign up for your free phone number.\nCall and text online for free.");
// Access the first paragraph
const p = shape.getTextBody().getTextParagraphs().get(1);
// Set the line space
p.setLineSpaceSizeType(AsposeCells.LineSpaceSizeType.Points);
p.setLineSpace(20);
// Set the space after
p.setSpaceAfterSizeType(AsposeCells.LineSpaceSizeType.Points);
p.setSpaceAfter(10);
// Set the space before
p.setSpaceBeforeSizeType(AsposeCells.LineSpaceSizeType.Points);
p.setSpaceBefore(10);
// Save the workbook in xlsx format
wb.save(path.join(dataDir, "output_out.xlsx"), AsposeCells.SaveFormat.Xlsx);