Добавить новый лист - PullRequest
       13

Добавить новый лист

0 голосов
/ 11 июня 2018

Я пытаюсь добавить новый лист, но я не понимаю, как это сделать.Помогите мне, пожалуйста ...

спасибо.

Пример кода листа Google https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/batchUpdate

AddSheetRequest https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#AddSheetRequest

package main

// BEFORE RUNNING:
// ---------------
// 1. If not already done, enable the Google Sheets API
//    and check the quota for your project at
//    https://console.developers.google.com/apis/api/sheets
// 2. Install and update the Go dependencies by running `go get -u` in the
//    project directory.

import (
        "errors"
        "fmt"
        "log"
        "net/http"

        "golang.org/x/net/context"
        "google.golang.org/api/sheets/v4"
)

func main() {
        ctx := context.Background()

        c, err := getClient(ctx)
        if err != nil {
                log.Fatal(err)
        }

        sheetsService, err := sheets.New(c)
        if err != nil {
                log.Fatal(err)
        }

        // The spreadsheet to apply the updates to.
        spreadsheetId := "my-spreadsheet-id" // TODO: Update placeholder value.

        // A list of updates to apply to the spreadsheet.
        // Requests will be applied in the order they are specified.
        // If any request is not valid, no requests will be applied.
        requests := []*sheets.Request{} // TODO: Update placeholder value.

        rb := &sheets.BatchUpdateSpreadsheetRequest{
                Requests: requests,

                // TODO: Add desired fields of the request body.
        }

        resp, err := sheetsService.Spreadsheets.BatchUpdate(spreadsheetId, rb).Context(ctx).Do()
        if err != nil {
                log.Fatal(err)
        }

        // TODO: Change code below to process the `resp` object:
        fmt.Printf("%#v\n", resp)
}

func getClient(ctx context.Context) (*http.Client, error) {
        // TODO: Change placeholder below to get authentication credentials. See
        // https://developers.google.com/sheets/quickstart/go#step_3_set_up_the_sample
        //
        // Authorize using the following scopes:
        //     sheets.DriveScope
        //     sheets.DriveFileScope
        //     sheets.SpreadsheetsScope
        return nil, errors.New("not implemented")
}

1 Ответ

0 голосов
/ 11 июня 2018

Я нахожу метод ...

    req := sheets.Request{
        AddSheet: &sheets.AddSheetRequest{
            Properties: &sheets.SheetProperties{
                Title: "test",
            },
        },
    }

    rbb := &sheets.BatchUpdateSpreadsheetRequest{
        Requests: []*sheets.Request{&req},
    }

    resp, err := srv.Spreadsheets.BatchUpdate(spreadsheetId, rbb).Context(context.Background()).Do()
    if err != nil {
        log.Fatal(err)
    }
...