How to create first row in new Google spreadsheet using API?

This is how I create the table:

DocsService client= new DocsService ("idea"); client.useSsl (); client.setOAuthCredentials (oauthParameters, new OAuthHmacSha1Signer ()); DocumentListEntry newEntry= new com.google.gdata.data.docs.SpreadsheetEntry (); newEntry.setTitle (new PlainTextConstruct ("GIdeaDB")); DocumentListEntry insertedEntry= client.insert (new URL ( "https://docs.google.com/feeds/default/private/full/?xoauth_requestor_id="+ userEmail), newEntry); 

Now I want to write the first line in it.

But, unfortunately, the entire API calls the seam, based on the fact that there is already the first line for which you insert name-value pairs (where name is the title that I want to create). http://code.google.com/apis/spreadsheets/data/3.0/developers_guide.html#CreatingTableRecords

Any ideas how I can create the first line? One that defines field names.

+6
java google-spreadsheet gwt google-spreadsheet-api google-docs-api
source share
2 answers

Finally found him. You must do this in a cell:

  oauthParameters= new GoogleOAuthParameters (); oauthParameters.setOAuthConsumerKey (CONSUMER_KEY); oauthParameters.setOAuthConsumerSecret (CONSUMER_SECRET); oauthParameters.setOAuthType (OAuthType.TWO_LEGGED_OAUTH); oauthParameters.setScope ("https://spreadsheets.google.com/feeds/"); SpreadsheetService spreadsheetService= new SpreadsheetService ("appname"); spreadsheetService.useSsl (); spreadsheetService.setOAuthCredentials (oauthParameters, new OAuthHmacSha1Signer ()); URL feedUrl= new URL ( "https://spreadsheets.google.com" + "/feeds/spreadsheets/private/full?title=Spreadsheetname&xoauth_requestor_id=" + userEmail); SpreadsheetFeed resultFeed= spreadsheetService.getFeed (feedUrl, SpreadsheetFeed.class); List <SpreadsheetEntry> spreadsheets= resultFeed.getEntries (); SpreadsheetEntry spreadsheetEntry= spreadsheets.get (0); URL worksheetFeedUrl= spreadsheetEntry.getWorksheetFeedUrl (); log.severe (worksheetFeedUrl.toString ()); WorksheetFeed worksheetFeed= spreadsheetService.getFeed ( worksheetFeedUrl, WorksheetFeed.class); List <WorksheetEntry> worksheetEntrys= worksheetFeed.getEntries (); WorksheetEntry worksheetEntry= worksheetEntrys.get (0); // Write header line into Spreadsheet URL cellFeedUrl= worksheetEntry.getCellFeedUrl (); CellFeed cellFeed= spreadsheetService.getFeed (cellFeedUrl, CellFeed.class); CellEntry cellEntry= new CellEntry (1, 1, "headline1"); cellFeed.insert (cellEntry); cellEntry= new CellEntry (1, 2, "headline2"); cellFeed.insert (cellEntry); 
+14
source share

I have not tried it, but it seems to me that this is described in the "Creating a table" section:

 TableEntry tableEntry = new TableEntry(); FeedURLFactory factory = FeedURLFactory.getDefault(); URL tableFeedUrl = factory.getTableFeedUrl(spreadsheetEntry.getKey()); // Specify a basic table: tableEntry.setTitle(new PlainTextConstruct("New Table")); tableEntry.setWorksheet(new Worksheet("Sheet1")); tableEntry.setHeader(new Header(1)); // Specify columns in the table, start row, number of rows. Data tableData = new Data(); tableData.setNumberOfRows(0); // Start row index cannot overlap with header row. tableData.setStartIndex(2); // This table has only one column. tableData.addColumn(new Column("A", "Column A")); tableEntry.setData(tableData); service.insert(tableFeedUrl, tableEntry); 

In particular, the tableEntry.setHeader(new Header(1)) seems to create a heading in the first row. Then tableData.setStartIndex(2) seems to indicate that the data should not go in the first row (since this is the header). Finally, tableData.addColumn(new Column("A", "Column A")) seems to add a column to be marked in the header.

+1
source share

All Articles