Excel.FunctionCellValue type

表示可作为函数计算的单元格值。

export type FunctionCellValue = JavaScriptCustomFunctionReferenceCellValue;

注解

API 集:ExcelApi 1.19

通过以下链接详细了解此类型别名中的类型。

Excel.JavaScriptCustomFunctionReferenceCellValue

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/20-data-types/data-types-function-references.yaml

// Read the custom-function identity stored in an entity's method property.
await Excel.run(async (context) => {
    const sheet: Excel.Worksheet = context.workbook.worksheets.getItem("Sample");
    const entityRange: Excel.Range = sheet.getRange("A2");
    entityRange.load("valuesAsJson");
    await context.sync();

    const cellValue: Excel.CellValue = entityRange.valuesAsJson[0][0];
    if (cellValue.type !== Excel.CellValueType.entity) {
        throw new Error("Create the function reference in Sample!A2 first.");
    }

    const methodValue: Excel.CellValue = cellValue.properties["Get27"];
    if (!methodValue || methodValue.type !== Excel.CellValueType.function) {
        throw new Error("The entity in Sample!A2 doesn't contain a Get27 function reference.");
    }

    const functionReference: Excel.FunctionCellValue = methodValue;
    console.log("Function type:", functionReference.functionType);
    console.log("Custom-function namespace:", functionReference.namespace);
    console.log("Custom-function ID:", functionReference.id);
});