目前,我们正在使用 DriveService 创建电子表格。它使用单张纸创建电子表格。使用的代码如下:
DriveService service = new DriveService(new BaseClientService.Initializer() { HttpClientInitializer = credential, ApplicationName = applicationName });
Google.Apis.Drive.v2.Data.File body = new Google.Apis.Drive.v2.Data.File();
body.Title = uploadSpreadsheetRequest.FileName;
body.Description = uploadSpreadsheetRequest.FileName;
body.MimeType = "text/csv";
byte[] byteArray=System.IO.File.ReadAllBytes(uploadSpreadsheetRequest.FilePath);
System.IO.MemoryStream stream = new System.IO.MemoryStream(byteArray);
FilesResource.InsertMediaUpload request = service.Files.Insert(body, stream, "text/csv");
request.Convert = true;
request.Upload();
有什么方法可以修改我的代码以创建包含多个工作表的电子表格。
我可以使用 Google Sheets API 来做到这一点,但我希望通过使用字节来实现。
有人可以帮我解决这个问题吗
最佳答案
我能够解决这个问题。我用了NPOI用于创建具有多个工作表的 excel 文件,然后通过将内容类型设置为“application/vnd.ms-excel”使用 google drive 上传该文件。
使用 NOPI,因为 Microsoft Excel 未安装在生产服务器上。
关于c# - 我们可以使用 Google Drive API 创建具有多个工作表的谷歌电子表格吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38220759/