How do I create the first line in a new Google Spreadsheet using the API?

This is how I create the spreadsheet:

DocsService client= new DocsService ("idea"); client.useSsl (); client.setOAuthCredentials (oauthParameters, new OAuthHmacSha1Signer ()); DocumentListEntry newEntry= new (); newEntry.setTitle (new PlainTextConstruct ("GIdeaDB")); DocumentListEntry insertedEntry= client.insert (new URL ( ""+ userEmail), newEntry);

Now I want to write the first line in it.

But unfortunately all API calls seam to base on the fact, that there already is a first line, for you insert name-value-pairs (where the name is the headline I want to create).

Any ideas how I can create the first line? The one which defines the field names.


Finaly found it. You have to do it cell by cell:

oauthParameters= new GoogleOAuthParameters ();
oauthParameters.setOAuthConsumerKey (CONSUMER_KEY);
oauthParameters.setOAuthConsumerSecret (CONSUMER_SECRET);
oauthParameters.setOAuthType (OAuthType.TWO_LEGGED_OAUTH);
oauthParameters.setScope ("");

SpreadsheetService spreadsheetService= new SpreadsheetService ("appname");
spreadsheetService.useSsl ();
spreadsheetService.setOAuthCredentials (oauthParameters,
new OAuthHmacSha1Signer ());

URL feedUrl= new URL (
+ "/feeds/spreadsheets/private/full?title=Spreadsheetname&xoauth_requestor_id="
+ userEmail);

SpreadsheetFeed resultFeed= spreadsheetService.getFeed (feedUrl,

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,

CellEntry cellEntry= new CellEntry (1, 1, "headline1");
cellFeed.insert (cellEntry);
cellEntry= new CellEntry (1, 2, "headline2");
cellFeed.insert (cellEntry);

I haven't tried it, but it looks to me like that is described in the section on "Creating a table":

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();
// Start row index cannot overlap with header row.
// This table has only one column.
tableData.addColumn(new Column("A", "Column A"));

service.insert(tableFeedUrl, tableEntry);

Specifically, the part tableEntry.setHeader(new Header(1)) seems like it creates a header on the first row. Then, tableData.setStartIndex(2) seems to specify that data shouldn't go in the first row (since it's the header). Finally, tableData.addColumn(new Column("A", "Column A")) seems to add a column that would be labeled in the header.

Category:java Time:2010-12-03 Views:0

Related post

  • How do I create a command line frontend for a GUI Cocoa app? 2009-05-11

    I'm creating a mainly GUI Cocoa app, but I want to create a command line front end as well that prints the same data so I can display it using geektool. I'm guessing I need to create an additional command line custom executable in my Xcode project an

  • How do I create a new line using javascript that shows correctly in notepad? 2009-08-14

    I have a script that copies table cells from the browser into the user's clipboard. I loop through each cell and when a new line is needed I use text += "\n"; If I paste the text into excel, it formats correctly and fills in the proper rows, however

  • How to create a status line with ttk? 2010-08-25

    How do you create your status line at the bottom of your window? An inactive entry does not look very nice. What other options are there? Is possible to integrate a progress bar which is visible only on demand? (I am using tk and ttk from within R.)

  • Best way to create a long line (or cross line) cursor in Qt GraphicsView 2011-01-15

    The easy way to create the long cross line cursor(as long as viewport) is create a cross line graphicsItem, when mouse moved, set the item's pos property. But this way will be very slow when the scene is complex, because it should update the whole vi

  • Advices to create a command line text editor in .NET 2011-02-27

    I want to create a command line text editor with .Net. I always do GUI applications so I'm a little lost about whole deal with this task. One of the first things I need to know is how create an scrollable editor area. A place where I can write whatev

  • How do I create a new line in Javascript? 2011-04-22

    var i; for(i=10; i>=0; i= i-1){ var s; for(s=0; s<i; s = s+1){ document.write("*"); } //i want this to print a new line /document.write(?); } I am printing a pyramid of stars, I can't get the new line to print. --------------Solutions----------

  • Lwuit Create an empty Line between two Containers 2011-07-07

    I'd like to create an empty line between to containers embedded in my form with BoxLayout Y_Axis. The following piece only shows "test1 test", but I'd like to have "test1 test2" or even more lines.. import com.sun.lwuit.Container; import com.sun.lwui

  • How to create a dashed line that alternates between two colours? 2011-08-05

    I'm using JFreeChart and want to plot a series of data using a line that alternates between gray and black dashes, with no space between. i.e. grayblackgrayblackgrayblack JFreeChart will only accept an AWT Stroke or Shape object as the method of rend

  • How to create a diagonal line within a table cell? 2011-11-14

    How can I create a diagonal line from the lower left corner to the upper right corner of any given cell? To get this <table> <tr> <td class="crossOut">A1</td> <td>B1</td> </tr> <tr> <td>A2 Wide

  • Create an Excel Line - Column combination chart in C# 2012-01-13

    I am trying to create an Excel line-column combination chart using C#. I know how to create a line chart or a column chart but I don't know how to create a combined chart. Could anyone please point me a direction or provide a short sample code on how

  • How to create an number line control? 2012-01-17

    I'm planning to create a number-line control similar to the image below (only one of them): I'm creating a program where the children can detect where's the position's number. I mean, instruct them to write the number 4 (and the boy writes a vertical

  • How to create a multi-line UITextField? 2012-01-26

    How can I implement a multiple line textfield like what I see in the iPhone messaging application. in other words, How to expand the box dynamically when user press return key or when text run to next line. I notice this question already been asked a

  • How can I create a multi-line wx.ComboCtrl in wxPython? 2012-03-17

    Setting the wx.TE_MULTILINE style flag on the ComboCtrl itself or the associated TextCtrl results in no change after a Refresh(). After quite some time Googling, I saw several sources that stated that apparently creating multiline Combo Box is compli

  • Creating a trend line from data set SQL 2012-04-06

    The code below returns the number of resolved tickets and the number of opened tickets for a period (period is YYYY,WW) going back a certain number of days. For example if @NoOfDays is 7: resolved | opened | week | year | period 56 | 30 | 13 | 2012 |

  • When I try to create a signature line and sign it, the entire signature line looks squashed 2012-02-06

    When I try to create a signature line and sign it, the entire signature line looks squashed. --------------Solutions------------- Try creating the signature in Word 2010 and then copy and paste it in Outlook 2010. My mistake, I forgot to put in I cre

  • every time I hit enter in a form it creates a new line in the form, is there a way to stop that or make it move to the next form box 2012-05-11

    I have created a form field, but every time I hit enter it creates a new line. Is there a way to make it just tab to the next field? If I hit enter it pushes everything down on the document. The document is locked but this does not seem to help. What

  • How to create a horizontal line in a message 2012-11-25

    How to create a horizontal line in a message. Used to divide sections. Was a button in entourage. Sorely needed in Outlook. --------------Solutions------------- You can type three asterisks ( *** ) or three underscores ( ___ ) followed by a return an

  • how do I create an off-line account for windows live? 2013-02-13

    Hi anyone know how I can do this pls? --------------Solutions------------- Hi, Which game are you playing? Let’s try these steps: a. Run the game. b. If you automatically sign into a profile then create profile button will not be shown. So we have to

  • How do I create multiple text lines within an excel table cell? 2013-04-14

    Original Title: "Office Mac Excel" How do I create multiple text lines within an excel table cell ? --------------Solutions------------- Hey Jeffrey, You can add a line break by pressing Ctrl+Alt+Enter.

Copyright (C), All Rights Reserved.

processed in 0.615 (s). 13 q(s)