使用Node.js通过C++刷新关联形状的数值
Contents
[
Hide
]
有时,你的Excel文件中有与某个单元格关联的形状。Microsoft Excel中,改变关联单元格的值也会改变关联形状的值。如果你想用Aspose.Cells for Node.js via C++保存工作簿为XLS或XLSX格式,这也没问题。但如果你想保存为PDF或HTML格式,则必须调用ShapeCollection.updateSelectedValue()方法来刷新关联形状的值。
示例
下图显示了示例代码所使用的源Excel文件。它包含一个链接到单元格A1到E4的图片。我们将用 Aspose.Cells 改变B4单元格的值,然后调用 ShapeCollection.updateSelectedValue() 方法刷新图片的值,并将其保存为PDF格式。
使用Node.js代码刷新关联形状的数值
const path = require("path");
const AsposeCells = require("aspose.cells.node");
// Source directory
const sourceDir = path.join(__dirname, "data");
// Output directory
const outputDir = path.join(__dirname, "output");
// Create workbook from source file
const workbook = new AsposeCells.Workbook(path.join(sourceDir, "sampleRefreshValueOfLinkedShapes.xlsx"));
// Access first worksheet
const worksheet = workbook.getWorksheets().get(0);
// Change the value of cell B4
const cell = worksheet.getCells().get("B4");
cell.putValue(100);
// Update the value of the Linked Picture which is linked to cell B4
worksheet.getShapes().updateSelectedValue();
// Save the workbook in PDF format
workbook.save(path.join(outputDir, "outputRefreshValueOfLinkedShapes.pdf"), AsposeCells.SaveFormat.Pdf);