尝试添加一个 html 侧边栏来添加从列表中选取的图像

问题描述 投票:0回答:1

所以我想要一个 sode bar 弹出窗口,它只是一个具有不同名称的按钮列表,您单击一个按钮,它会插入指定的图像。我有一个成功添加图像的脚本,并且有一个用于添加联系人的工作侧边栏,我尝试将它们混合在一起,但没有成功。我对脚本编写还很陌生,而且我对 HTML 一无所知,所以就我的主文档而言,我所取得的进展令人印象深刻(如果我自己这么说的话)。

任何帮助完成这项工作都会很棒。我只想进行一项设置,然后我将根据需要复制以进行其他设置。就像下面的清除表一样。

提前致谢!

表格链接

侧边栏按预期弹出,但当我单击按钮时没有任何反应。

脚本:

function imagemenu()
{ 
  var form = 
HtmlService.createHtmlOutputFromFile('Images').setTitle('Add Images');
  SpreadsheetApp.getUi().showSidebar(form);
}

function onOpen() {
  var ui = SpreadsheetApp.getUi();
  ui.createMenu('Tools')
      .addItem('Add Image', 'imagemenu')

      .addToUi();     
  
}

function imageAdder(){
  const img_url = (img_url1);
  const ss = SpreadsheetApp.getActive();
  const sh = SpreadsheetApp.getActiveSheet();
  const response = UrlFetchApp.fetch(img_url);
  const rd = response.getContent();
  const blob = Utilities.newBlob(rd, 'image/png','MyImageName');
  sh.insertImage(blob, 15, 58);
};

html:

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
    <link rel="stylesheet" 
          href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/4.6.1/css/bootstrap.min.css" />
    <style>
      .narrow {
        margin-bottom: 0.5rem;
      }
    </style>
    <script>
      // JavaScript code for SubmitRecord and other functions


      function image01() {
        document.getElementById("displayReturn").innerHTML = "";

        var img_url1 = ('https://thevasilcompany.com/wp-content/uploads/2024/10/VJ-CC.png');
        
        // Call the Google Apps Script function with the form data
        google.script.run.withSuccessHandler(returnBack)
          .imageAdder(img_url1);
      }


      function returnBack(stringBack) {
        document.getElementById("displayReturn").innerHTML = stringBack;
        document.getElementById("img_url1").value = '';

      }



    </script>
  </head>
  <body>
    <form>
      <div style="padding: 10px">

        </div>
        <div class="form-row">
          <div class="form-group col-md-6 narrow">
            <input type="button" value="Cross Country" onclick="image01()" class="btn btn-primary" />
          </div>
        </div>
      </div>
    </form>
    <div id="displayReturn"></div>
    <script>getints();</script>
    <script>getpaytype();</script>
  </body>
</html>
html image insert
1个回答
0
投票
class contact {
    constructor(name, number, email) {
        this.Name = name;
        this.Number = number;
        this.Email = email;
    }    
}

const contacts = [new contact("Ben", "9883092", "[email protected]"), new contact("Muder", "20993902", "[email protected]") ] ; // Number of buttons to create
const buttonList = document.getElementById('buttonList');

for (let i = 1; i <= contacts.length; i++) {
    const listItem = document.createElement(contacts[i].Name);
    const button = document.createElement('button');
    button.textContent = `Button ${i}`;
    button.onclick = () => alert(`Button ${i} clicked!`);

    listItem.appendChild(button);
    buttonList.appendChild(listItem);
}

你需要设置上下文

© www.soinside.com 2019 - 2024. All rights reserved.