1

Androidアプリでスプレッドシートを作成しようとしています。これまでのところ、空のテキスト ドキュメントの作成にしか成功していません。 Google の Spreadsheet APIは、 Google Driveでスプレッドシート ドキュメントを作成するために、Google Documents List APIに従うように指示します。Google Documents List APIでは、次のように書かれています。

新しい空のスプレッドシートを作成するには、 メタデータのみを含む新しいドキュメントまたはファイルの作成の手順に従います。その際、http://schemas.google.com/docs/2007#spreadsheetのカテゴリ用語を使用します。

上記のリンクで、次の.NET コードを見つけました。

using System;
using Google.GData.Client;
using Google.GData.Documents;

namespace MyDocumentsListIntegration
{
  class Program
  {
    static void Main(string[] args)
    {
      DocumentsService service = new DocumentsService("MyDocumentsListIntegration-v1");

      // TODO: Authorize the service object for a specific user (see Authorizing requests)

      // Instantiate a DocumentEntry object to be inserted.
      DocumentEntry entry = new DocumentEntry();

      // Set the document title
      entry.Title.Text = "Legal Contract";

      // Add the document category
      entry.Categories.Add(DocumentEntry.DOCUMENT_CATEGORY);

      // Make a request to the API and create the document.
      DocumentEntry newEntry = service.Insert(
          DocumentsListQuery.documentsBaseUri, entry);
    }
  }
}

このコードを使用してスプレッドシートを作成しようとしましたが、3 番目のバリアントのみが機能しました ( URL オブジェクトDocsServiceを追加Categoryおよび使用せずに を使用)。feedUrl

これが私の作業コードの一部です(upload()ユーザーがボタンをクリックすると呼び出されます):

private void upload() {
        SpreadSheetAsyncTask sprdSheetAsyncTsk = new SpreadSheetAsyncTask();

        sprdSheetAsyncTsk.execute();

    }

    public class SpreadSheetAsyncTask extends AsyncTask<Void, Void, Void> {

        @Override
        protected Void doInBackground(Void... params) {
            spreadSheetService = new SpreadsheetService("Salary_Calculator");
            docService = new DocsService("Salary_Calculator");
            try {

                spreadSheetService.setUserCredentials(USERNAME, PASSWORD);
                docService.setUserCredentials(USERNAME, PASSWORD);

                URL feedUrl = new URL(
                        "https://docs.google.com/feeds/default/private/full/");
                URL tmpFeedUrl = new URL(
                        "https://spreadsheets.google.com/feeds/worksheets/key/private/full");

                DocumentEntry entry = new DocumentEntry();

                Calendar timeRightNow = GregorianCalendar.getInstance();

                entry.setTitle(new PlainTextConstruct(
                        "Salary Calculator Spreadsheet "
                                + timeRightNow.get(Calendar.DAY_OF_MONTH) + "/"
                                + (timeRightNow.get(Calendar.MONTH) + 1) + "/"
                                + timeRightNow.get(Calendar.YEAR)));

//              Category object = new Category("spreadsheet",
//                      "http://schemas.google.com/docs/2007#spreadsheet");
//              
//
//              entry.getCategories().add(object);
                
                /*
                 * TODO TEST AREA
                 */

                entry = docService.insert(feedUrl, entry);
                /*
                 * TODO TEST AREA
                 */
            } catch (AuthenticationException e) {
                cancel(true);
                loginDialog("Wrong username or password");
            } catch (IOException e) {
                e.printStackTrace();
                return null;
            } catch (ServiceException e) {
                cancel(true);
                loginDialog("Wrong username or password");
            } catch (Exception e) {
                loginDialog("Wrong username or password");
            }

            return null;
        }
    }
                

動作しないコードは、上記のカテゴリ オブジェクトobject(コード コメントに示されているように) を使用し、entry = spreadSheetService.insert(feedUrl, entry);

私の質問は - 彼らが書いたとき、彼らは私に何をしてほしかったの use a category term of http://schemas.google.com/docs/2007#spreadsheetですか?

4

0 に答える 0