Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

72
Visualizações
is it possible to receive Dom in google webscript?

I receive from google sheet some html tags to be displayed but it shows as raw string. here is how

Index.html

  <? var BlogData = getSheetData("Blogs"); ?>
  <? for(var i = 0; i < BlogData.length; i++) { ?>
        <div class="text-muted text-end"><?= BlogData[i][1] ?></div>
        <!-- BlogData[i][1] this should be dom but it displays as string -->
  <?};?>

code.gs

 function doGet(e) {
    return HtmlService.createTemplateFromFile('Index').evaluate();
 }

 function getSheetData(sheetName)  { 
    var ss= SpreadsheetApp.openById("1s5AHWsdfbsgfaegsdthwrthaert5ad4y4gt56355h");
    var dataSheet = ss.getSheetByName(sheetName); 
    var dataRange = dataSheet.getDataRange();
    var dataValues = dataRange.getValues();  

   return dataValues;
  }

and the value comes from sheet Blogs look like this

A B
<h1>Title </h1>
<h2>Subtitle</h2>
<p>Paragraph</p>

and unfortunately it displays in the Index.html as string

I need to show it as DOM not as string

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

finally, I found the solution.

using google interpolation tags is a bit tricky and I don't know types of these tags. but accidently I found that solution.

using <?= blogData[i][j] ?> will return html tags as it is.

however, <?!= blogData[i][j] ?> will return html format.

using exclamation mark completely changes the result.

about 4 years ago · Juan Pablo Isaza Relatório

0

I'll leave this as an example of what devoloper was doing:

He created a deployment so you can retrieve HTML tags from a Spreadsheet, like this:

enter image description here

Now the problem was that the deployment was showing results as raw texts as:

enter image description here

By using the HTML SCriptlets that App Script provides you can return the data from the spreadsheet by passing the values through a script. Something like this:

<!DOCTYPE html>
<html>

<head>
  <base target="_top">
</head>

<body>
  <div class="root">
    <? const blogData = getSheetData("Blogs");?>
    <div>
      <? for(var i = 0; i < blogData.length; i++) { ?>
      <div>
        <? for (var j = 0; j < blogData[i].length; j++) { ?>
        <div>
          <?!= blogData[i][j] ?> // This is the solution that devoloper found
        </div>
        <?};?>
      </div>
      <?};?>

    </div>
  </div>
</body>

</html>

function doGet(e) {
  return HtmlService
    .createTemplateFromFile("index")
    .evaluate()
}


function getSheetData(sheetName) {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var dataSheet = ss.getSheetByName('Blogs');
  var dataRange = dataSheet.getDataRange()
  var dataValues = dataRange.getValues();
  console.log(dataValues)

  return dataValues;
}

Once the above script is run the HTML tags added on the spreadsheet will return as a regular HTML DOM:

enter image description here

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda