javafaj / google-gdata

Automatically exported from code.google.com/p/google-gdata
0 stars 0 forks source link

service.Insert(listFeed, row) gives error while inserting a row in worksheet of a spreadsheet #638

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
See the code below. 
1. I have connected service
2. searched in worksheets
3. finally while creating the worksheet the worksheet gets created with no of 
rows and columns
4. Now I am trying to connect to the newly inserted worksheet for inserting new 
rows with some data. At my first entry it got failed with follwing error:
"Execution of request failed: 
https://spreadsheets.google.com/feeds/list/tVk0Ia6n8RF9pONzDpUGnPQ/oci/private/f
ull"

What is the expected output? What do you see instead?
Row must get inserted

Please use labels and text to provide additional information.
See the code below and let me know if there is any issue from my side.
This is not full code but the code required for your analysis.

// Create a local representation of the new worksheet.
WorksheetEntry worksheet = new WorksheetEntry();
worksheet.Title.Text = "Company " + DateTime.Now;
worksheet.Cols = 2;
//Names is a List<string>
worksheet.Rows = (uint)(Names.Count + 1);

// 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.
WorksheetFeed wsFeed = spreadSheet.Worksheets;
service.Insert(wsFeed, worksheet);
WorksheetFeed wsFeed = spreadSheet.Worksheets;
service.Insert(wsFeed, worksheet);

wsFeed = spreadSheet.Worksheets;
foreach (WorksheetEntry entry in wsFeed.Entries)
{
    if (entry.Title.Text == worksheetText)
    {
        worksheet = entry;
        break;
    }
}

// Define the URL to request the list feed of the worksheet.
AtomLink listFeedLink = 
worksheet.Links.FindService(GDataSpreadsheetsNameTable.ListRel, null);

// Fetch the list feed of the worksheet.
ListQuery listQuery = new ListQuery(listFeedLink.HRef.ToString());
ListFeed listFeed = service.Query(listQuery);

// Create a local representation of the new row.
ListEntry row = new ListEntry();
row.Elements.Add(new ListEntry.Custom() { LocalName = "Name", Value = "Name" });
row.Elements.Add(new ListEntry.Custom() { LocalName = "URL", Value = "URL" });

// Send the new row to the API for insertion.
service.Insert(listFeed, row);

I have checked the response in the fiddler but I didn't get any. I get 
innerexception while debugging in the visual studio. Inner exception says, "The 
remote server returned an error: (400) Bad Request.".

Comment on your comment 5:
I don't have anything in newly inserted worksheet. I am trying to insert a 
firstrow with the following code and I am getting the above exception.
// Define the URL to request the list feed of the worksheet.
AtomLink listFeedLink = 
worksheet.Links.FindService(GDataSpreadsheetsNameTable.ListRel, null);

// Fetch the list feed of the worksheet.
ListQuery listQuery = new ListQuery(listFeedLink.HRef.ToString());
ListFeed listFeed = service.Query(listQuery);

// Create a local representation of the new row.
ListEntry row = new ListEntry();
row.Elements.Add(new ListEntry.Custom() { LocalName = "Name", Value = "Name" });
row.Elements.Add(new ListEntry.Custom() { LocalName = "URL", Value = "URL" });

// Send the new row to the API for insertion.
service.Insert(listFeed, row);

Now tell me how shall I insert my first row in the worksheet? I am following 
the code from the link 
"https://developers.google.com/google-apps/spreadsheets/#adding_a_list_row"

Please help me.

See the following links. There also people didn't get solution to insert a row 
in worksheet of google:

http://stackoverflow.com/questions/10518694/adding-a-row-to-a-google-spreadsheet

http://stackoverflow.com/questions/13008293/exception-during-adding-a-row-to-goo
gle-spreadsheet

Original issue reported on code.google.com by dhananja...@clariontechnologies.co.in on 26 Nov 2012 at 6:22

GoogleCodeExporter commented 8 years ago
I was not able to reopen the issue 637 so I opened 638 again

Original comment by dhananja...@clariontechnologies.co.in on 26 Nov 2012 at 6:22

GoogleCodeExporter commented 8 years ago
Following is the fiddler response. Please let me know if you need more than 
this.

HTTP/1.1 400 Bad Request
Content-Type: text/html; charset=UTF-8
x-chromium-appcache-fallback-override: disallow-fallback
Date: Mon, 26 Nov 2012 07:00:30 GMT
Expires: Mon, 26 Nov 2012 07:00:30 GMT
Cache-Control: private, max-age=0
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
Server: GSE
Transfer-Encoding: chunked

5f
We're sorry, a server error occurred. Please wait a bit and try reloading your 
spreadsheet.
0

Original comment by dhananja...@clariontechnologies.co.in on 26 Nov 2012 at 7:02

GoogleCodeExporter commented 8 years ago
Any ways I have achieved the target by using following code. Of course it is 
very basic code I have modify it but it is working I have to just convey you. 
The one which I have pasted in my previous comments is not working.

CellFeed cellFeed = worksheet.QueryCellFeed(ReturnEmptyCells.yes);

// Iterate through each cell, updating its value if necessary.
int counter = 0;
foreach (CellEntry cell in cellFeed.Entries)
{
    if (cell.Title.Text == "A1")
    {
        cell.InputValue = Names[counter];
        cell.Update();
    }
    else if (cell.Title.Text == "B1")
    {
        cell.InputValue = NameList[Names[counter]];
        cell.Update();
    }
}

Original comment by dhananja...@clariontechnologies.co.in on 26 Nov 2012 at 9:54

GoogleCodeExporter commented 8 years ago
I think "ReturnEmptyCells.yes" is a key thing which I had added and success!!!

Original comment by dhananja...@clariontechnologies.co.in on 26 Nov 2012 at 9:55

GoogleCodeExporter commented 8 years ago
Glad you got it working

Original comment by ccherub...@google.com on 26 Nov 2012 at 5:07