我正在使用google sheet api创建工作表,并希望获得工作表的iframe嵌入式链接。
ServiceAccountCredential credential = new ServiceAccountCredential(
new ServiceAccountCredential.Initializer(serviceAccountEmail)
{
Scopes = new[] { SheetsService.Scope.Spreadsheets,DriveService.Scope.DriveFile}
}.FromCertificate(certificate));
BaseClientService.Initializer clientService = new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = ApplicationName,
};
var service = new SheetsService(clientService);
var spareSheet = new Spreadsheet();
spareSheet.Properties = new SpreadsheetProperties();
spareSheet.Properties.Title = "TestSheet";
spareSheet = service.Spreadsheets.Create(spareSheet).Execute();
答案 0 :(得分:1)
var driveService = new DriveService(clientService);
var fileMetadata = new Google.Apis.Drive.v3.Data.File();
fileMetadata.Name = fileName;
fileMetadata.MimeType = "application/vnd.google-apps.spreadsheet";
var fileRequest = driveService.Files.Create(fileMetadata);
fileRequest.Fields = "id";
var file = fileRequest.Execute();
Console.WriteLine("File ID: " + file.Id);
// Console.WriteLine("URL"+file.)
Permission userPermission = new Permission();
userPermission.Type = "anyone";
userPermission.Role = "writer";
// userPermission.we
var revision = new Revision();
revision.PublishAuto = true;
revision.Published = true;
revision.PublishedOutsideDomain = true;
driveService.Permissions.Create(userPermission, file.Id).Execute();
var request = driveService.Revisions.Update(revision, file.Id, "head");
request.Execute();
string iframeURl="<iframe src='https://docs.google.com/spreadsheets/d/"+file.Id+"/edit?rm=minimal#gid=1333667591' height='900' width='800'></iframe>";