Pregunta

he visto; acceder a Google Spreadsheets con C # utilizando la API de datos de Google

y

http://code.google.com/apis /spreadsheets/data/2.0/developers_guide_dotnet.html#CreatingRows

Sin embargo todavía estoy teniendo problemas para insertar una nueva fila en una hoja de propagación Google existente. ¿Alguien tiene un ejemplo en lata, que introduce un List<string> por ejemplo en a nueva fila en un libro de hojas de cálculo.

Muchas gracias,

¿Fue útil?

Solución

http://github.com/mausch/GDataDB

GDataDB proporciona una forma sencilla para insertar entidades POCO .net en una hoja de propagación Google.

    public void AddToGoogle()
    {
        var client = new DatabaseClient(Settings.Default.GmailAccount, Settings.Default.GmailPassword);
        string dbName = Settings.Default.WorkBook;

        var db = client.GetDatabase(dbName) ?? client.CreateDatabase(dbName);
        string tableName = Settings.Default.WorkSheet;

        var t = db.GetTable<ActivityLog>(tableName) ?? db.CreateTable<ActivityLog>(tableName);
        var all = t.FindAll();

        t.Add(this);
    }

Otros consejos

Este servicio de Google se suspendió y ahora se les ocurrió otro llamado Google.Apis.Sheets.v4 servicios.

lo que el código anterior no funcionará hoy en día, ya he intentado.

Y encontrar algo que funcionó para mí.

He escrito un blog y compartir todo el código fuente allí. Comprobarlo.

private static SheetsService AuthorizeGoogleApp()
 {
     UserCredential credential;

     using (var stream =
         new FileStream("client_secret.json", FileMode.Open, FileAccess.Read))
     {
         string credPath = System.Environment.GetFolderPath(
             System.Environment.SpecialFolder.Personal);
         credPath = Path.Combine(credPath, ".credentials/sheets.googleapis.com-dotnet-quickstart.json");

         credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
             GoogleClientSecrets.Load(stream).Secrets,
             Scopes,
             "user",
             CancellationToken.None,
             new FileDataStore(credPath, true)).Result;
         Console.WriteLine("Credential file saved to: " + credPath);
     }

     // Create Google Sheets API service.
     var service = new SheetsService(new BaseClientService.Initializer()
     {
         HttpClientInitializer = credential,
         ApplicationName = ApplicationName,
     });

     return service;
 }

Para todo el código fuente comprobarlo. Insertar nueva fila a Google Hoja usando Google.Apis.Sheets.V4 Servicios

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top