在工作表中将形状移到前面或后面,用Node.js通过C++

可能的使用场景

当同一位置存在多种形状时,它们的可见性由z序位置决定。Aspose.Cells提供Shape.toFrontOrBack()方法,可以改变形状的z序位置。将形状送到最底层,用负数如-1、-2、-3等,想将形状置于最前面,用正数如1、2、3等。

在工作表内发送形状到最前或最后

以下示例代码解释了Shape.toFrontOrBack()方法的用法。请查看代码中使用的示例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 sourceFilePath = path.join(dataDir, "sampleToFrontOrBack.xlsx");

// Load source Excel file
const workbook = new AsposeCells.Workbook(sourceFilePath);

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

// Access first and fourth shape
const shape1 = worksheet.getShapes().get(0);
const shape4 = worksheet.getShapes().get(3);

// Print the Z-Order position of the shape
console.log("Z-Order Shape 1: " + shape1.getZOrderPosition());

// Send this shape to front
shape1.toFrontOrBack(2);

// Print the Z-Order position of the shape
console.log("Z-Order Shape 4: " + shape4.getZOrderPosition());

// Send this shape to back
shape4.toFrontOrBack(-2);

// Save the output Excel file
const outputFilePath = path.join(dataDir, "outputToFrontOrBack.xlsx");
workbook.save(outputFilePath);