您可以使用setStyleAttribute()
和参考一些CSS documentation
尝试像这样,例如(我真的不是在CSS的专家,所以不要怪我,如果这是不好的; - )
function testImage(){
var app = UiApp.createApplication().setTitle("My Simple App").setHeight('700').setWidth('900');
mainImage = app.createImage("https://dl.dropbox.com/u/211279/Time-change-clock_animated_TR80.gif")
.setStyleAttribute('position','relative').setStyleAttribute('left','50%').setStyleAttribute('top','50%')
app.add(mainImage);
ss=SpreadsheetApp.getActive()
ss.show(app)
}
注:您还可以使用位置PX(像素图像),而不是%,正如你注意到了,我在电子表格UI测试这一点。
编辑:这里是用像素和Bryan的建议CSS样式版本,更紧凑,它的语法有(再次THX)接近原来的CSS方法:
var _imgCSS = {'position':'relative', 'left':'200PX', 'top':'200PX'}
function testImage(){
var app = UiApp.createApplication().setTitle("My Simple App").setHeight('500').setWidth('500');
var mainImage = app.createImage("https://dl.dropbox.com/u/211279/Time-change-clock_animated_TR80.gif")
.setStyleAttributes(_imgCSS)
app.add(mainImage);
ss=SpreadsheetApp.getActive()
ss.show(app)
}
你也可以使用'.setStyleAttributes( _imgCSS)''一次,并把'_imgCSS = {'position':'relative','left':'50%','top':'50%'};'在函数之外。 @Serge - 您知道我们为什么不能使用Google Drive链接指向'createImage()'中的图像文档? –
感谢您的提示;-) - 这是一个已知的问题,使GDrive中的图像无法查看[问题1239](http://code.google.com/p/google-apps-script-issues/issues/detail ?id = 1239)编辑:这个问题不完全相关,但我不记得我在哪里rerad信息...对不起 –
快速之一 - 这在Chrome中正常工作,但是当切换到IE没有中心......有没有办法解决这个问题?谢谢 – Sherlock