簡體   English   中英

將任務窗格文本字段值添加到 Excel 單元格 JavaScript API

[英]Add Task Pane TextField value to Excel Cell JavaScript API

如何添加到我的異步 function 以將 TextField 值輸入到 Excel 中的單元格? 我正在嘗試創建一個用戶界面數據條目任務窗格,並讓用戶填寫任務窗格,然后將他們的 TextField 數據插入到單元格中。 在下面的 following.js 代碼中,我只有一個按鈕,用於輸入我在 .js 文件中編寫的字符串。 如何將以下內容添加到 this.js async function 中?

(.js)

/*
 * Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
 */


Office.initialize = () => {
  document.getElementById("sideload-msg").style.display = "none";
  document.getElementById("app-body").style.display = "flex";
  document.getElementById("PMARK").onclick = run1;
  document.getElementById("LSR").onclick = clear1;
  document.getElementById("run12").onclick = run;
};

async function run() {
  try {
    await Excel.run(async context => {

      const range = context.workbook.getActiveCell();

      range.load("address");


      range.values = "PRESS BRAKE";
      range.getOffsetRange (0, 2).values = "P_BRK1";

      await context.sync();
      console.log(`The range address was ${range.address}.`);
    });
  } catch (error) {
    console.error(error);
  }
}

(.html)

<!-- Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT License. -->

                <div class="ms-TextField">
                    <label class="ms-Label">Part Number</label>
                    <input class="ms-TextField-field" type="text" value="" placeholder="">
                </div></p>
/*
 * Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
 */

// The initialize function must be run each time a new page is loaded
Office.initialize = () => {
  document.getElementById('sideload-msg').style.display='none';
  document.getElementById('app-body').style.display='flex';
  document.getElementById('run1').onclick = run1;
  document.getElementById('PMARK').onclick = run2;
  document.getElementById('LSR').onclick = run3;
  document.getElementById('WLDR').onclick = run4;
  document.getElementById('FLAT').onclick = run5;
  document.getElementById('DIM').onclick = run6;
  document.getElementById('BUY').onclick = run7;
};
async function run1() {
  try {
    await Excel.run(async context => {

      const range = context.workbook.getActiveCell();
      **var stx = document.getElementsByName("nameField")[0].value**;
      // Read the range address
      range.load("address");

      // Update the fill color
      range.values = "PRESS BRAKE";
      range.getOffsetRange(0, 2).values = "P_BRK1";
      **range.getOffsetRange(0, -2).values = stx;**
      await context.sync();
      console.log(`The range address was ${range.address}.`);
    });
  } catch (error) {
    console.error(error);
  }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM