首页 > 解决方案 > JavaScript excel API 中的范围函数 getCellProperties 是如何工作的?

问题描述

我特别想在一个数组上调用这个函数:

https://docs.microsoft.com/en-us/javascript/api/excel/excel.range?view=office-js#getcellproperties-cellpropertiesloadoptions-

从文档中确实不清楚要完成这项工作需要什么。我肯定在这里遗漏了一些东西。以下是我的代码的当前状态。

我还检查了我正在构建的加载项是否在使用 API v1.9 的 Excel 版本中运行。

我尝试设置与 cellPropertiesLoadOptions 描述的接口匹配的各种对象 - 但再次不确定文档中的实际要求是什么。

async function getFormatsForCellRange () {
  return await Excel.run(async context => {
    const table = await context.workbook.tables.getItem(observationConst.TABLE_NAME)
    const range = table.getRange()
    const cellProperties = range.getCellProperties()
    console.log(cellProperties)
  })
}

文档指出调用 getCellProperties 的结果应该是一个二维数组。

标签: office-js

解决方案


var actualData = rangeSrc.getCellProperties({
 format: {
    font: {
           bold: true,
           color: true,
           fill: true
           italic: true,
           name: true,
           underline: true,
           size: true,
           strikethrough: true,
           subscript: true,
           superscript: true,
           tintAndShade: true
    }
 }

推荐阅读