编辑:
正如 tehhowch 的评论,您的答案已经在 SO 上。这个答案来自STTP Smart Triathlon Training on SO question how to publish to the web a spreadsheet using drive API and GAS
您必须首先从控制台 API 激活 Drive API(请参阅启用驱动器平台)并在您的脚本中激活它(资源 > Google 高级服务 > 单击“驱动器 API”行上的“激活”)
//this function publish to the web the document given by ID (google sheets or docs)
function publishToWeb(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var fileId = ss.getId();
var revisions = Drive.Revisions.list(fileId);
var items = revisions.items;
var revisionId =items[items.length-1].id;
var resource = Drive.Revisions.get(fileId, revisionId);
resource.published = true;
resource.publishAuto = true;
resource.publishedOutsideDomain = true;
Drive.Revisions.update(resource, fileId, revisionId);
}
第一个答案:
如文档页面所示,您可以使用File.setSharing(accessType, permissionType)方法,例如:
// Get Spreadsheet and Id
var ss = SpreadsheetApp.getActiveSpreadsheet();
var id = ss.getId();
// Get the file object with the Spreadsheet Id
var file = File.getFileById(id);
// Set sharing parameters so ANYONE can VIEW this spreadsheet
file.setSharing(DriveApp.Access.ANYONE, DriveApp.Permission.VIEW);
// Get the Spreadsheet url, who is now accessible by anyone
var url = ss.getUrl();
您不能通过这种方法只共享一张纸,但您可以制作一些东西。
另请参见File.getFileById(id)、SpreadsheetApp.getUrl()、SpreadsheetApp.getId()