Tacitus
Tacitus

Reputation: 87

Pass Google Sheets Cell Value To HTML

I am trying to pass the value "assetCell" to the HTML dialog box. It seems simple enough . . . thank you for any help.

GAS

 function Test(){
 var ss = SpreadsheetApp.getActiveSpreadsheet(); 
 var MySH = ss.getActiveSheet();
 var Assetcell = MySH.getRange("f8").getValue()
 var Assetcellb = MySH.getRange("f10").getValue()

 var t = HtmlService.createTemplateFromFile('vIndex'); // Modified
 t.AssetCell = Assetcell 
 t.AssetCell = Assetcellb

 html = t.evaluate().setWidth(400).setHeight(300); // Added

  SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
.showModalDialog(html, 'Hi');
 }

HTML

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

Upvotes: 1

Views: 1984

Answers (1)

Tanaike
Tanaike

Reputation: 201378

How about this modification?

GAS

function Test(){
  var ss = SpreadsheetApp.getActiveSpreadsheet(); 
  var MySH = ss.getActiveSheet();
  var Assetcell = MySH.getRange("f8").getValue()

  var t = HtmlService.createTemplateFromFile('vIndex'); // Modified
  t.AssetCell = Assetcell; // Added
  html = t.evaluate().setWidth(400).setHeight(300); // Added

  SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
    .showModalDialog(html, 'Hi');
}

HTML

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
    <?!= AssetCell ?> => <!-- Modified -->
  </body>
</html>

Reference :

If this was not useful for you, I'm sorry.

Edit :

1. When you want to give them to <?!= AssetCell ?>

You can use the same HTML.

var ss = SpreadsheetApp.getActiveSpreadsheet(); 
var MySH = ss.getActiveSheet();
var Assetcell1 = MySH.getRange("f8").getValue();
var Assetcell2 = MySH.getRange("f10").getValue();

var t = HtmlService.createTemplateFromFile('vIndex'); // Modified
t.AssetCell = [Assetcell1, Assetcell2]; // Added
html = t.evaluate().setWidth(400).setHeight(300); // Added

SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
  .showModalDialog(html, 'Hi');

2. When you want to give <?!= AssetCell1 ?> and <?!= AssetCell2 ?>, respectively

GAS
var ss = SpreadsheetApp.getActiveSpreadsheet(); 
var MySH = ss.getActiveSheet();
var Assetcell1 = MySH.getRange("f8").getValue();
var Assetcell2 = MySH.getRange("f10").getValue();

var t = HtmlService.createTemplateFromFile('vIndex'); // Modified
t.AssetCell1 = Assetcell1; // Added
t.AssetCell2 = Assetcell2; // Added
html = t.evaluate().setWidth(400).setHeight(300); // Added

SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
  .showModalDialog(html, 'Hi');
HTML
<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
    <?!= AssetCell1 ?> => <!-- Modified -->
    <?!= AssetCell2 ?> => <!-- Modified -->
  </body>
</html>

Upvotes: 1

Related Questions