读我有一个成绩册web应用程序脚本,它着眼于学生的电子邮件地址的记录,找到的电子邮件中的成绩簿,然后显示基于列的电子邮件是在学生的成绩。唯一的问题是,这只有当传播者被公开时才有效。我怎样才能保持传播私密性,并仍然使这个剧本工作?我知道,如果我选择“有链接的任何人”,不太可能有人会找到电子表格,但我宁愿将其保留为私人。另外,从“部署为Web应用程序”界面,该应用程序必须以用户身份执行,而不是自己执行。有任何想法吗?谷歌Apps脚本:从私人电子表格
var ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheet/ccc?key=ID');
var sh1 = ss.getSheetByName('StudentGrades');
var logsheet = ss.getSheetByName('logsheet');
var data = sh1.getDataRange().getValues();
var user = Session.getEffectiveUser()
Logger.log(user)
function doGet() {
var app = UiApp.createApplication();
if(!getcol(user)){
var warn = app.createTextBox().setWidth('500').setValue("Your results are not available or you don't have permission to view these data");// if user is not in the list, warning + return
app.add(warn)
return app
}
var grid = app.createGrid(data.length, 2).setWidth('300px').setBorderWidth(1).setCellPadding(0).setCellSpacing(0).setStyleAttribute('borderCollapse','collapse').setId('grid');
var text = app.createLabel(user).setWidth('300px');
var col = getcol(user)
grid.setWidget(0,1,text).setText(0, 0, 'Results for');
grid.setStyleAttribute('textAlign','center')
for(n=1;n<data.length;++n){
grid.setText(n, 0, string(data[n][0]));
grid.setText(n, 1, string(data[n][col]));
grid.setStyleAttributes(n-1, 0, {'fontWeight':'bold','background':'#fff','border':'1px solid #000'});//left column css attributes
grid.setStyleAttributes(n-1, 1, {'fontWeight':'bold','background':'#fff','border':'1px solid #000'});//right column css attributes
}
app.add(grid);
return app
}
function string(value){
Logger.log(typeof(value))
if (typeof(value)=='string'){return value};// if string then don't do anything
if (typeof(value)=='number'){return Utilities.formatString('%.1f/20',value)};// if number ther format with 1 decimal
if (typeof(value)=='object'){return Utilities.formatDate(value, Session.getTimeZone(), "MM-dd")};//object >> date in this case, format month/day
return 'error'
}
function getcol(mail){
if(data[0].toString().indexOf(mail.toString())!=-1){
for(zz=1;zz<data[0].length;++zz){
if(data[0][zz] == mail){var colindex=zz;break}
}
return colindex
}
return false
}
我感谢你的帮助(你可以在上面看到我如何修改你的脚本)。每学期我将使用至少有5个不同班级的成绩簿。使用用户名和密码进行额外的登录过程将非常不方便。必须有另一种方式来做到这一点。什么与oAuth? – Acornrevolution 2013-04-21 12:59:03
我明白...看到编辑另一个可能的解决方案。 – 2013-04-21 15:10:43