c# - 我们可以使用 Google Drive API 创建具有多个工作表的谷歌电子表格吗

标签 c# google-sheets google-drive-api google-sheets-api

目前,我们正在使用 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/

相关文章:

c# - 如何使用 .net 连接到 Facebook 聊天?

javascript - 如何查询谷歌工作表列的某个值

javascript - Google 脚本上的循环忽略 if 语句

C# HttpWebRequest POST 数据 block

google-drive-api - 访问 Google Drive API downloadURL 时出现 403 Forbidden 错误

c# - SpreadsheetGear CopyFromDataTable 单元格格式

c# - 为什么我们可以使用这样的任务?

c# - 如何添加没有边框的矩形?

date - 使用单元格格式值的 IF 语句

python - 无法通过 ID 从 Google 云端硬盘下载文件