在工作表内使用Node.js通过C++设置评论或形状的边距

可能的使用场景

Aspose.Cells允许你使用Shape.textBody.textAlignment属性设置任何形状或评论的边距,该属性返回Aspose.Cells.Drawing.Texts.ShapeTextAlignment类的对象,具有不同的属性(如ShapeTextAlignment.getTopMarginPt()ShapeTextAlignment.getLeftMarginPt()ShapeTextAlignment.getBottomMarginPt()ShapeTextAlignment.getRightMarginPt()等)可用于设置上下左右边距。

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

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

todo:image_alt_text

示例代码

const path = require("path");
const AsposeCells = require("aspose.cells.node");

// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
const filePath = path.join(dataDir, "sampleSetMarginsOfCommentOrShapeInsideTheWorksheet.xlsx");
// Load the sample Excel file
const workbook = new AsposeCells.Workbook(filePath);

// Access first worksheet
const ws = workbook.getWorksheets().get(0);

const shapes = ws.getShapes();
for (let i = 0; i < shapes.getCount(); i++) {
const sh = shapes.get(i);
// Access the text alignment
const 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("outputSetMarginsOfCommentOrShapeInsideTheWorksheet.xlsx");