How to programmatically create a table of contents Google Docs?

I found several StackOverflow questions regarding how to create or edit Google Doc spreadsheets using the Google Spreadsheets API or older APIs. However, this table API seems to be part of the gdata library, which, as far as I know, is deprecated.

https://stackoverflow.com/questions/374896/ ... show how to create an empty spreadsheet using the Drive API, which seems more relevant. However, looking at the documentation and examples for this API, it looks like you can create new EMPTY files with a MIME table type. I did not find any functions to create a spreadsheet with the actual content (e.g. rows, columns, tables, etc.).

What is the current process of creating a new Google Doc spreadsheet and populating it with content? Does the drive's API have functionality that I don’t understand? Is the gdata library (or at least part of the table APIs) not completely obsolete? Is there any third approach that I skipped? I work with Java code how important this is, although I'm sure that any Python API will have the equivalent of Java.

+8
google-spreadsheet google-drive-sdk google-docs google-spreadsheet-api google-docs-api
source share
3 answers

The answer is in the form of a bullet ...

  • This is just the old docslist API which is deprecated. The spreadsheet API is still alive and kicking as there is no replacement
  • Gdata libraries may no longer be supported, but you'll probably be better served using the table APIs anyway
  • Drive API is for file-level operations only
  • You can create a completed spreadsheet using the Drive API by uploading a file in a format that you can convert to a Google spreadsheet, for example. MS Excel
  • Keep in mind that the spreadsheet API (and possibly drive APIs) does not yet support the new spreadsheet format (end of 2013).
+2
source share

with reference to the new v4 table API

I have a better and easier way:

Step 1

Create an AsyncTask class, pass it the "GoogleAccountCredential credentials".

Step 2

Use the API to create a new SpreadSheet.

CODE

private class MakeRequestTask extends AsyncTask<Void, Void, Void> { private com.google.api.services.sheets.v4.Sheets mService = null; // The constructor MakeRequestTask(GoogleAccountCredential credential) { HttpTransport transport = AndroidHttp.newCompatibleTransport(); JsonFactory jsonFactory = JacksonFactory.getDefaultInstance(); mService = new com.google.api.services.sheets.v4.Sheets.Builder( transport, jsonFactory, credential) .setApplicationName("Android spreadsheet client") .build(); } protected void doInBackground(Void... params) { // function to create the spreadsheet creadSpreadSheet(); } // creates a new spreadsheet private void creadSpreadSheet() throws IOException{ com.google.api.services.sheets.v4.model.Spreadsheet mSpreadsheet, newSpreadSheet; mSpreadsheet = new Spreadsheet(); SpreadsheetProperties spreadsheetProperties = new SpreadsheetProperties(); spreadsheetProperties.setTitle("Demo SpreadSheet");// name of your spreadsheet mSpreadsheet = mSpreadsheet.setProperties(spreadsheetProperties); newSpreadSheet = mService.spreadsheets() .create(mSpreadsheet) .execute(); // this 'newSpreadsheet' is ready to use for write/read operation. } 

}

Note: Remember to put the "SheetsScopes.SPREADSHEETS" area in the "credentials" in onCreate ().

 String[] SCOPES = { SheetsScopes.SPREADSHEETS}; credential = GoogleAccountCredential.usingOAuth2( getApplicationContext(), Arrays.asList(SCOPES)) .setBackOff(new ExponentialBackOff()); 
+1
source share

Google-apps-script will also create spreadsheets and allow you to add data. See https://developers.google.com/apps-script/reference/spreadsheet/spreadsheet-app It can do more than GData api, i.e. google-apps- script can set cell fonts / colors, etc.

But depending on your needs, GData is low in style, and so I find it faster. There is a simple demo version of Google GData for CellDemo.java. http://gdata-java-client.googlecode.com/svn-history/r51/trunk/java/sample/spreadsheet/cell/CellDemo.java It demonstrates the functions of the Gdata Spreadsheets API.

0
source share

All Articles