问题描述
我正在举一个示例来检查动态数组上JavaScript API的行为。
我首先在工作表的单元格=MUNIT(3)
中输入一个动态数组A1
。然后,我意识到范围formulas[0][0]
上的所有formulaR1C1[0][0]
,formulaLocal[0][0]
和A1
都返回=MUNIT(3)
。但是,在formulas[0][0]
,formulaR1C1[0][0]
之类的其他单元格上的所有formulaLocal[0][0]
,B1
和A2
返回空字符串。
因此,有没有正式的JavaScript API或正式方法来检查像B1
这样的单元格是否在动态数组范围内?
PS:我猜想一种方法是检查单元格的公式是否为空且其值是否为非空,但我希望有更好的方法。
解决方法
是的,您可以尝试即将发布的Beta API range.hasSpill
,也可以在range.getSpillParent()
之前获得父API,这是您可以尝试的示例代码。
await Excel.run(async (context) => {
// Check the current cell for any spill parents or spilling-to ranges.
const currentRange = context.workbook.getSelectedRange();
currentRange.load("hasSpill");
await context.sync();
if (currentRange.hasSpill)
{
const spillParent = currentRange.getSpillParentOrNullObject();
spillParent.load("address");
await context.sync();
console.log(`The selected cell has a spill parent: ${spillParent.address}`);
}
});
请注意:对于preview the beta API,您需要引用CDN上的beta库 https://appsforoffice.microsoft.com/lib/beta/hosted/office.js