【问题标题】:Pre-populating Cells with Multiple Values using Office JS使用 Office JS 预填充具有多个值的单元格
【发布时间】:2019-04-03 14:22:23
【问题描述】:

我正在使用 Office JS 为 Office 365 构建 Excel 加载项。我热衷于在 Excel 工作表中提供一些单元格,以便在用户在 Excel 工作表中输入数据时预先填充下拉值供用户选择。 Excel 工作表的模板是在用户第一次加载加载项时生成的。是否有允许相同的 Office -JS API?

【问题讨论】:

    标签: excel office-js excel-addins


    【解决方案1】:

    目前,我们没有用于添加数据验证(将下拉菜单添加到 Excel 单元格)的 API。 请随时在https://officespdev.uservoice.com/ 记录功能请求,我们将考虑在未来为此添加 API。

    -Philip,Office 可扩展性团队的软件开发人员

    【讨论】:

      【解决方案2】:

      这里我在 excel 单元格中添加了下拉菜单。

       Excel.run(function (context) {
          var currentWorksheet = context.workbook.worksheets.getActiveWorksheet();
          var expensesTable = currentWorksheet.tables.add("A1:D1", true /*hasHeaders*/);
          expensesTable.name = "ExpensesTable";
          expensesTable.getHeaderRowRange().values = [["Date", "Merchant", "Category", "Amount"]];
          expensesTable.rows.add(null /*add at the end*/, [
              ["1/1/2017", "The Phone Company", "Communications", "120"],
              ["1/2/2017", "Northwind Electric Cars", "Transportation", "142.33"],
              ["1/5/2017", "Best For You Organics Company", "Groceries", "27.9"],
              ["1/10/2017", "Coho Vineyard", "Restaurant", "33"],
              ["1/11/2017", "Bellows College", "Education", "350.1"],
              ["1/15/2017", "Trey Research", "Other", "135"],
              ["1/15/2017", "Best For You Organics Company", "Groceries", "97.88"]
          ]);
          var range = currentWorksheet.getRange("C2:C200");
          range.dataValidation.clear();
          range.dataValidation.rule = {
              list: {
                  inCellDropDown: true,
                  source: "Groceries, Education, Other,Transportation",
                  autofitColumns: true
              }
          };
          //range.dataValidation.errorAlert = {
          //    message: "Sorry, only Selected value are allowed",
          //    showAlert: true,
          //    style: "Stop",
          //    title: "Other value Entered"
          //};
          list.find();
      
          return context.sync();
      }).catch(function (error) {
          console.log("Error: " + error);
          if (error instanceof OfficeExtension.Error) {
              console.log("Debug info: " + JSON.stringify(error.debugInfo));
          }
      });
      

      【讨论】:

        猜你喜欢
        • 2012-05-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-06-01
        • 1970-01-01
        相关资源
        最近更新 更多