Tworzenie arkusza kalkulacyjnego za pomocą Google Spreadsheet API w Google Drive + Java

Udało mi się utworzyć nowy arkusz w istniejącym arkuszu kalkulacyjnym mojego konta na Dysku Google za pomocą prostego kodu Java wymienionego w oficjalnej dokumentacji Google na Developer Guide of Spreadsheet API ale chcę utworzyć nowy arkusz kalkulacyjny na moim koncie na Dysku Google za pomocą kodu java. We wspomnianym linku nie wymienili żadnego przykładowego kodu do tego. Przejrzałem wiele linków, ale nie rozumiem, jak to zrobić? Widziałem już różne metody dostępne w Klasa Spreadservice.

Nie rozumiem, jak to zrobić z Google Spreadsheet API ?

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import com.google.gdata.client.spreadsheet.*;
import com.google.gdata.data.Link;
import com.google.gdata.data.PlainTextConstruct;
import com.google.gdata.data.TextConstruct;
import com.google.gdata.data.docs.ExportFormat;
import com.google.gdata.data.spreadsheet.*;
import com.google.gdata.util.*;


import java.io.IOException;
import java.net.*;
import java.util.*;
import javax.xml.soap.Text;


    /**
     *
     * @author satyam
     */
    public class SpreadSheet {

        public static void main(String[] args)
                throws AuthenticationException, MalformedURLException, IOException, ServiceException {

            SpreadsheetService service =   new SpreadsheetService("gBuddy");

            // TODO: Authorize the service object for a specific user (see other sections)
            String USERNAME = "USERNAME";
            String PASSWORD = "PASSWORD";

            service.setUserCredentials(USERNAME, PASSWORD);


            // Define the URL to request.  This should never change.
            URL SPREADSHEET_FEED_URL = new URL(
                    "https://spreadsheets.google.com/feeds/spreadsheets/private/full");

            // Make a request to the API and get all spreadsheets.
            SpreadsheetFeed feed = service.getFeed(SPREADSHEET_FEED_URL, SpreadsheetFeed.class);
            List<SpreadsheetEntry> spreadsheets = feed.getEntries();

            // Iterate through all of the spreadsheets returned
            for (SpreadsheetEntry spreadsheet : spreadsheets) {
    //             Print the title of this spreadsheet to the screen;
                System.out.println(spreadsheet.getTitle().getPlainText());
            }

            SpreadsheetEntry spreadsheet = spreadsheets.get(1);
    //        System.out.println(spreadsheet.getTitle().getPlainText());

    //        // Create a local representation of the new worksheet.
            WorksheetEntry worksheet = new WorksheetEntry();
            worksheet.setTitle(new PlainTextConstruct("New Worksheet"));
            worksheet.setColCount(10);
            worksheet.setRowCount(20);

            // Send the local representation of the worksheet to the API for
            // creation.  The URL to use here is the worksheet feed URL of our
            // spreadsheet.
            URL worksheetFeedUrl = spreadsheet.getWorksheetFeedUrl();
            WorksheetEntry insert = service.insert(worksheetFeedUrl, worksheet);
        }
    }
Author: Satyam Koyani, 2013-10-14

2 answers

To po prostu proste po pewnych badaniach znalazłem tę odpowiedź. Nie możemy utworzyć nowego arkusza kalkulacyjnego na Dysku google za pomocą Google Spreadsheet API .

Uwaga: możemy utworzyć nowy arkusz roboczy w już istniejącym arkuszu kalkulacyjnym Dysku google za pomocą interfejsu API arkusza kalkulacyjnego Google, ale nie możemy utworzyć nowego arkusza kalkulacyjnego za pomocą interfejsu API arkusza kalkulacyjnego.

Do tworzenia i przesyłania nowego arkusza kalkulacyjnego lub innego rodzaju dokumentu, który obsługuje Dysk google, musimy użyć Dysku Google api .

Tego właśnie szukam. Dzięki temu możemy utworzyć nowy arkusz kalkulacyjny na Dysku google za pomocą interfejsu API Dysku google.
    DocsService docsService = new DocsService("MySampleApplication-v3");
    docsService.setUserCredentials(USERNAME, PASSWORD);
    URL GOOGLE_DRIVE_FEED_URL = new URL("https://docs.google.com/feeds/default/private/full/");
    DocumentListEntry documentListEntry = new com.google.gdata.data.docs.SpreadsheetEntry();
    documentListEntry.setTitle(new PlainTextConstruct("Spreadsheet_name"));
    documentListEntry = docsService.insert(GOOGLE_DRIVE_FEED_URL, documentListEntry);

Aby utworzyć nowy arkusz kalkulacyjny musimy utworzyć obiekt new SpreadsheetEntry(), a dla każdego innego dokumentu utworzyć obiekt new DocumentEntry().

Teraz, jeśli mamy przesłać dowolny dokument (xls,doc,image itp.) na Dysk google możemy zrobić tak:

//File upload in google drive
        DocumentListEntry uploadFile = new DocumentListEntry();
        uploadFile.setTitle(new PlainTextConstruct("FILE_NAME_DISPLAY_IN_DRIVE"));
        uploadFile.setFile(new File("FILE_PATH"), "MIME_TYPE_OF_FILE");
        uploadFile = docsService.insert(GOOGLE_DRIVE_FEED_URL, uploadFile);
 27
Author: Satyam Koyani,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-10-14 17:43:58

Powinieneś użyć Google Documents List API do tworzenia nowych zestawów głośnomówiących.

Co może zrobić to API?

API listy Dokumentów Google pozwala programistom tworzyć, pobierać, Aktualizuj i usuwaj Dokumenty Google (w tym między innymi tekst dokumentów, arkuszy kalkulacyjnych, prezentacji i rysunków), plików i Kolekcje. Zapewnia również niektóre zaawansowane funkcje, takie jak zasób archiwa, optyczne rozpoznawanie znaków, tłumaczenie i rewizja historia.

 1
Author: Guillaume,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-10-14 13:55:27