如何添加到范围内的图像交付结果? [英] How to add to the results of delivery the images from range?

查看:78
本文介绍了如何添加到范围内的图像交付结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是编程初学者。
有一个



1)将html模板添加到您的GAS项目中。您可以通过文件 - >新建 - > Html文件创建html文件。 2)在doGet()函数中,从电子表格中检索值的数组,然后将其作为属性附加到模板对象中。这将允许你直接从html引用变量。在模板上调用evaluate()将执行内联代码并生成发送给浏览器的htmlOutput。


$ b

  function doGet(){ 

var ss = SpreadsheetApp.openById(yourId);
var sheet = ss.getSheets()[0];
var range = sheet.getRange(A1:A+ sheet.getLastRow());
var url = range.getValues();

var template = HtmlService.createTemplateFromFile('images');
template.urls =网址;

return template.evaluate();

$ b}



<3>对于你的html文件,使用scriptlet动态地创建尽可能多的表格单元格,因为您的数组具有值。有关模板的更多信息,请参见


I'm a beginner in programming . There is a script which returns the found range of values by highlighting the desired row. author @Jack Brown. I made small additions. Here is a script with which I'm working now. The question: how to add to the delivery of the text ("N1:V15") images from the range(" W3:W17")? that's the expected result Thank you!

function doGet(e)
    {
      var sheet = SpreadsheetApp.openById("1siy44rpMtdLmcCMUiopQ__Z13KkFnB_HMJhiJ_Qv0QY");
      sheet.getRange("A2").setValue(e.parameter.p1) ;
      var n= sheet.getRange("N1:V15").getValues();
      var h= sheet.getRange("L2").getValue(); //Line number for selection
      var z= sheet.getRange("M2").getValue(); 
      if (z==="#N/A"){return HtmlService.createHtmlOutput("Code not found");
                   }
    var retStr ="<style> .tcol { font: 10pt arial;font-weight: bold; color : DarkBlue; } </style> <table>"
      for(var i = 0 ; i< n.length ; i++){
       if ( i != h) {
        retStr +="<tr><td>"+ n[i].join("</td><td>") +"</td></tr>"
       } else {
        retStr +="<tr><td class = 'tcol'>" + n[i].join("</td><td class = 'tcol'>") +"</td></div></tr>"
       }

      }
      retStr += "</table>"

        return HtmlService.createHtmlOutput(retStr)
      }

Spreadsheet https://docs.google.com/spreadsheets/d/1siy44rpMtdLmcCMUiopQ__Z13KkFnB_HMJhiJ_Qv0QY/edit?usp=sharing

解决方案

Here's the example of a simple web app that I put together to demonstrate advanced templating in GAS. For simplicity, the spreadsheet used as a source of image urls contains a single column

1) Add html template to your GAS project. You create html files via File -> New -> Html file. I called the file 'images'.

2)In your doGet() function, retrieve the array of values from the spreadsheet, then attach it to your template object as property. This will allow you to reference the variable directly from html. Calling evaluate() on the template will execute inline code and build htmlOutput that gets sent to the browser.

function doGet(){

var ss = SpreadsheetApp.openById(yourId);
var sheet = ss.getSheets()[0];
var range = sheet.getRange("A1:A" + sheet.getLastRow());
var urls = range.getValues();

var template = HtmlService.createTemplateFromFile('images');
template.urls = urls;

return template.evaluate();


}

3) For your html file, use scriptlets to dynamically create as many table cells as your array has values. More on templating here https://developers.google.com/apps-script/guides/html/templates

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
    <table>

    <tr><th>Images</th></tr>

    <?

    for(var i=0; i < urls.length; i++ ) { ?>

    <tr>

     <? for(var j=0; j < urls[i].length; j++) { ?>  

    <td> <img src="<?=urls[i][j]?>" /> </td>


    <?}?>

     </tr>
   <? }

    ?>

    </table>
  </body>
</html>

4) Deploy your script as a web app. The result is below

这篇关于如何添加到范围内的图像交付结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆