我很擅长撰写Google App Scripts。我正在处理的脚本只是从谷歌表中提取数据。它非常难看,我被告知我可以通过使用CSS来使它变得更好。我已经读过您的CSS文件可以托管在Google云端硬盘上,并通过脚本从那里访问。我不是网络开发人员,过去我只使用过一次CSS。所有这一切的过程是什么?这甚至可能吗?我的整体问题是“我该如何开始这个过程?”我的脚本在下面,以防你想看到它:
var pointsSheet = SpreadsheetApp.openById('1o8_f063j1jYZjFEnI_P7uAztpnEAvQ6mc3Z1_Owa69Y');
//creates and shows an app with a label and password text box
function doGet() {
var app = UiApp.createApplication();
var mygrid = app.createGrid(1, 2);
mygrid.setWidget(0, 0, app.createLabel('Password:'));
mygrid.setWidget(0, 1, app.createPasswordTextBox().setName("text"));
var mybutton = app.createButton('Submit');
var submitHandler = app.createServerClickHandler('getResults');
submitHandler.addCallbackElement(mygrid);
mybutton.addClickHandler(submitHandler);
var mypanel = app.createVerticalPanel();
mypanel.add(mygrid);
mypanel.add(mybutton);
app.add(mypanel);
return app; //UNCOMMENT WHEN DEPLOYING APP
}
//obtains data based on password entered by user and outputs their info
function getResults(eventInfo) {
var app = UiApp.getActiveApplication();
var password = eventInfo.parameter.text;
var passwordCheckRange = pointsSheet.getRange("B34:C34").getValues();
if (passwordCheckRange == null) {
return app;
}
var name;
var studentFound = false;
for(var i = 0; i < passwordCheckRange.length; i++) {//obtains the name of the student
if(passwordCheckRange[i][1] == password) {
name = passwordCheckRange[i][0];
studentFound = true;
break;
}
}
var studentRecordRange = pointsSheet.getRange("B3:CZ29").getValues();
var headingRange = pointsSheet.getRange("B1:CZ2").getValues();
if (studentRecordRange == null) {
return app;
}
var studentRecord;
for(var i = 0; i < studentRecordRange.length; i++) {
if(studentRecordRange[i][0] == name)
studentRecord = studentRecordRange[i]; //gets the row of the student (B? to AY?)
}
var stringRecord = "";
for(var i = headingRange[1].length-1; i >= 7; i--) {
if ((studentRecord[i] == "" || studentRecord[i] == "STOP" || studentRecord[i] == "ALLOW") && headingRange[0][i] != "")
stringRecord += headingRange[1][i] + ": " + headingRange[0][i] + "XP" + "<br>";
}
var mygrid = app.createGrid(2, 1);
mygrid.setWidget(0, 0, app.createLabel('INCOMPLETE CHALLENGES'));
mygrid.setWidget(1, 0, app.createHTML(stringRecord));
var mypanel = app.createVerticalPanel();
mypanel.add(mygrid);
app.add(mypanel);
return app;
}
答案 0 :(得分:3)
我做的是,
1.在同一个项目中,我创建了另一个脚本文件,并将其命名为CSS.gs
2.我的CSS.gs将有以下行,
var css={};
css.Labels = { fontFamily:'Verdana', fontSize:'12px', width: '100', marginTop: '5'};
css.Inputs = { fontFamily:'Verdana', fontSize:'12px', width: '150'};
css.TextArea = { fontFamily:'Verdana', fontSize:'12px', width: '900', height: '50'};
css.PutBorder = {borderStyle: 'solid'};
3。我将使用.setStyleAttributes()
将这些样式应用于应用程序eg::app.createLabel('Password:').setStyleAttributes(css.Inputs)
有setStyleAttribute和setStyleAttribute' s '。请不要混淆。 GS中并不支持所有css属性。您可以找到支持的样式列表here。
答案 1 :(得分:0)
您可以将CSS放入Apps Script HTML文件中,然后在主HTML文件中包含带有CSS的HTML文件。在Apps脚本HTML文件中,将您的CSS放在<style>
标记内。
<style>
.bigHeader {
color:#808000;
text-align:center;
font-family:"Times New Roman";
font-size:50px;
background-color:#66CDAA;
margin-left:1%;
}
</style>
然后在主HTML文件中输入一个scriptlet标记:
<?!= include('Name_Of_HTML_File_With_CSS'); ?>
在主.gs
代码文件中,您需要一个名为include
function include(filename) {
return HtmlService.createHtmlOutputFromFile(filename).getContent();
};
另请参阅此stackoverflow问题:Google app script : Separating HTML and CSS