【发布时间】:2014-09-18 04:45:56
【问题描述】:
我正在编写桌面程序以与Google spreadsheets 交互,为此我需要上传excel sheet 并通过编程方式将其转换为Google spreadsheet。我检查了谷歌驱动器和谷歌电子表格 API 找不到这样做的方法。如果有人可以建议这样做的方法,那将是非常有帮助的。
这是我现在拥有的代码,它可以正确上传 excel 文件,但没有转换为 Google 电子表格。
Google.Apis.Drive.v2.Data.File body = new Google.Apis.Drive.v2.Data.File();
body.Title = "My document";
body.Description = "A test document";
body.MimeType = "application/vnd.ms-excel";
byte[] byteArray = System.IO.File.ReadAllBytes("test.xlsx");
System.IO.MemoryStream stream = new System.IO.MemoryStream(byteArray);
FilesResource.InsertMediaUpload request = service.Files.Insert(body, stream, "application/vnd.google-apps.spreadsheet");
request.Convert = true;
request.Upload();
Google.Apis.Drive.v2.Data.File file = request.ResponseBody;
Console.WriteLine("File id: " + file.Id);
Console.WriteLine("Press Enter to end this process.");
Console.ReadLine();
【问题讨论】:
-
如果这没有帮助,您需要发布您当前用于上传到 Google 云端硬盘的代码。
-
感谢cmets,我已经添加了代码。
标签: c# google-apps-script google-drive-api google-spreadsheet-api