需要创建Google表格并将其保存到特定的Google驱动器文件夹

时间:2019-06-12 15:44:38

标签: google-api

我们正在使用google.sheet.api创建工作表并将其保存到驱动器中的特定文件夹中。 但是我们能够创建文件夹,但是找不到任何与Google表格关联的方法。

在驱动器中创建文件夹

        var fileMetadata = new File()
        {
            Name = "GoogleExport",
            MimeType = "application/vnd.google-apps.folder"
        };
        var driveservice = new DriveService();
        var request1 = driveservice.Files.Create(fileMetadata);
        request1.Fields = "id";
        var file = request1.Execute();
        var folderid = file.Id;

创建Google工作表

Data.Spreadsheet requestBody = new Data.Spreadsheet();
requestBody.Properties = new Data.SpreadsheetProperties() { Title = "Test Sheet" };
            SpreadsheetsResource.CreateRequest request = sheetsService.Spreadsheets.Create(requestBody);
            request.RequestParameters.Add);
            Data.Spreadsheet response = request.Execute();
            SpreadsheetsResource.ValuesResource.AppendRequest.InsertDataOptionEnum insertDataOption = SpreadsheetsResource.ValuesResource.AppendRequest.InsertDataOptionEnum.INSERTROWS;
            SpreadsheetsResource.ValuesResource.AppendRequest.ValueInputOptionEnum valueInputOption = SpreadsheetsResource.ValuesResource.AppendRequest.ValueInputOptionEnum.USERENTERED;
            Data.ValueRange vRange = new Data.ValueRange();
            vRange.Range = "A:A";
            List<IList<Object>> objNewRecords = new List<IList<Object>>();
            IList<Object> obj = new List<Object>();
            obj.Add("Column - 1");
            obj.Add("Column - 2");
            obj.Add("Column - 3");
            IList<Object> obj1 = new List<Object>();
            obj1.Add("Poki - 1");
            obj1.Add("Poki - 2");
            obj1.Add("Poki - 3");
            objNewRecords.Add(obj1);
            objNewRecords.Add(obj);
            vRange.Values = objNewRecords;

            SpreadsheetsResource.ValuesResource.AppendRequest request2 = sheetsService.Spreadsheets.Values.Append(vRange, response.SpreadsheetId, "A:A");
            request2.ValueInputOption = valueInputOption;
            request2.InsertDataOption = insertDataOption;
            Data.AppendValuesResponse response2 = request2.Execute();

0 个答案:

没有答案