Pergunta

I'm learning how to use the Google spreadsheet API to get info from a spreadsheet and insert info to him.

I got the basic stuff with some examples from google, but I want to do something a little more advanced.

I got 2 lists in the spreadsheet, something like this:

      A                     B    
1| WebsiteList1    |   WebsiteList2
2| www.google.com  |  www.blabla.com
3| www.yahoo.com   |  www.someWebsite.com
4| www.cnn.com     |  www.cantThinkOfAbother.com

I want to choose 1 of the list, based on columns titles (WebsiteList1 or WebsiteList2)

I'm trying to change this code to do this, but with no luck (not sure what to do):

public void GetAllWebSitesListFromWorkSheet(string spreadsheetName,string colmnTitle)
{
        WorksheetEntry entry = getWorkSheetByTitle(spreadsheetName);

        CellQuery myCellQuery = new CellQuery(entry.CellFeedLink);

        CellFeed cellFeed = service.Query(myCellQuery);

        foreach (CellEntry cell in cellFeed.Entries)
        {
            Console.WriteLine(cell.Value);
        }
    }

What do I need to change in the CellQuery object, to get all the sites under WebsiteList2 ?

Foi útil?

Solução

Ok, afther some time of messing around, I found a way to get only 1 colmn! Here is the way.

first of all we need to use ListFeed, so we can get complete rows. ListFeed is a collection that represnt the rows on the spreadsheet.

ListFeed row;

row.elements is a collection that represent the cells of the row.

so this is the way to get 1 colmn (based on the spreadsheet in the question):

public void GetWebsitesWithListFeed()
    {


        WorksheetEntry entry = //get your spreadsheet (expmples for this can be found
                              //in google docs api (link in the end of the answer)


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

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

        ListFeed listFeed = service.Query(listQuery);

        // Iterate through each row.
        foreach (ListEntry row in listFeed.Entries)
        {
            //go over each CELL in the row
            foreach (ListEntry.Custom element in row.Elements)
            {   
                //print only the CELLS that there father (xmlName) is "WebsiteList2"
                if (element.XmlName == "WebsiteList2")
                    Console.WriteLine(element.Value);
            }

        }

    }

for info about getting the SpreadSheet and connection stuff go HERE.

this is only 1 way i found, i would like to know if somone know about a diffrent way to get a colmn base on his header.

(sorry for my english)

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top