Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

I'm using ImportXML in a Google Spreadsheet to access the user_timeline method in the Twitter API. I'd like to extract the created_at and text fields from the response and create a two-column display of the results.

Currently I'm doing this by calling the API twice, with

=ImportXML("http://twitter.com/status/user_timeline/matthewsim.xml?count=200","/statuses/status/created_at")

in the cell at the top of one column, and

=ImportXML("http://twitter.com/status/user_timeline/matthewsim.xml?count=200","/statuses/status/text")

in another.

Is there a way for me to create this display with a single call?

share|improve this question
up vote 3 down vote accepted

Just concatenate your queries with "|"

=ImportXML("http://twitter.com/status/user_timeline/matthewsim.xml?count=200","/statuses/status/created_at | /statuses/status/text")
share|improve this answer
1  
This works pretty well. I need to follow up with some code to separate the list into two columns with =INDIRECT((ADDRESS((ROW()-1)*2+1;1))) or similar. – Matthew Simoneau Oct 2 '12 at 0:23
    
@MatthewSimoneau - Rather than try to wedge the columnization into a comment I've added an additional answer (though perhaps I should have edited David's existing one -- not sure). – Lake Aug 27 '13 at 19:45

ImportXML supports using the xpath | separator to include as many queries as you like.

=ImportXML("http://url"; "//@author | //@catalogid| //@publisherid")

However it does not expand the results into multiple columns. You get a single column of repeating triplets (or however many attributes you've selected) as shown below in column A.

The following is deprecated

2015.06.16: continue is not available in "the new Google Sheets" (see: The Google Documentation for continue).

However you don't need to use the automatically inserted CONTINUE() function to place your results.

=CONTINUE($A$2, (ROW()-ROW($A$2)+1)*$A$1-B$1, 1)

Placed in B2 that should cleanly fill down and right to give you sane column data.

example screenshot

  • ImportXML is in A2.
  • A3 and below are how the CONTINUE() functions are automatically filled in.
  • A1 is the number of attributes.
  • B1:D1 are the attribute index for their columns.
share|improve this answer
1  
Nice one but unfortunately CONTINUE is no more available in new google sheets – Laurent' Jun 7 '15 at 15:30
    
That's terrible news for me. The Google Documentation for continue notes that it's "not available in the new Google Sheets". However as of this post continue continues to work in existing sheets (just verified). – Lake Jun 16 '15 at 18:20

Another way to convert the rows of =CONTINUE() into columns is to use transpose():

=transpose(importxml("http://url","//a | //b | //c"))
share|improve this answer
    
transpose will only convert column-wise to row-wise but it won't help if you want 3-by-N results as was discussed here. – Laurent' Jun 7 '15 at 15:32

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.