Sunday 15 July 2012

javascript - import CSS and JS from the same GAS project into Spreadsheet HtmlOutput -



javascript - import CSS and JS from the same GAS project into Spreadsheet HtmlOutput -

i'm next this tutorial, i'm trying import gas html file css , js file, both within same project. tutorial works fine web app, want show htmloutput on associated spreadsheet, same content.

i tried create htmloutput on spreadsheet follows:

function test(request){ var html = htmlservice.createhtmloutputfromfile('page'); ss.show(html); }

and i'm getting result (as can see getcontent , include not working expected):

these html, css , gs documents:

code.gs

//--- function called onclick on spreadsheet custom menu function test(request){ var html = htmlservice.createhtmloutputfromfile('page'); ss.show(html); } function include(filename){ homecoming htmlservice.createhtmloutputfromfile(filename).getcontent(); }

page.html

<?!= getcontent("stylesheet.html"); ?> <div> <h1>welcome</h1> <p> test </p> </div> <?! include('javascript'); ?>

stylesheet.html

<style> p{ color: green; } </style> <div> </div>

javascript.html

<script> window.addeventlistener("load", function(){ alert("loaded!"); }); </script> <div> </div>

am missing something?

thanks in advance, best regards

in tutorial tried using

htmlservice.createtemplatefromfile('page').evaluate();

you have utilize same approach in context of spreadsheet ui.

so, instead of

var html = htmlservice.createhtmloutputfromfile('page'); ss.show(html);

use

var html = htmlservice.createtemplatefromfile('page').evaluate(); ss.show(html);

and works if alter html file below (use "include" include style sheet):

<?!= include("stylesheet.html"); ?> <div> <h1>welcome</h1> <p> test </p> </div> <?! include('javascript'); ?>

javascript css google-apps-script include google-spreadsheet

No comments:

Post a Comment