1

I'm new to SO (although not to the SE medium), so though I've searched for an answer (using the site's search function and Google) there's a chance it's been asked and answered before; if so, thanks in advance for flagging as duplicate (provided I can find some assistance in the original, naturally).

I'm trying to compose a script for my personal use that would aggregate and filter RSS feeds. I've got the RSS corner handled (thanks in large part to this Programmer's Library entry), but the point where I'm stuck is that I want to make the filter modular by making it look for phrases contained in a spreadsheet file on my Google Drive. That way, if I ever need to modify/add filtering terms, I could simply edit the file on my Drive instead of going into my script's code.

So, I've been browsing the APIs for classes File, Spreadsheet, SpreadsheetApp, ScriptDb, as well as this Developer's article, but I just can't get my head around it (and I get the feeling I might not be looking in the right place). What I need to do, in the most basic terms, is load (and perhaps save) an array (it could be Object[][] for all I'm concerned) from (to) a spreadsheet file on my Drive. Then I could easily filter by the entries of said array. Another thing I'll be interested in doing is to keep some statistics on how much each term was used as an active filter, which is where saving a modified array back to my Drive would come in handy.

In conclusion, I should mention that I took some Java in collage, but as a math major I was never very accomplished with it; I'm comfortable using examples of similar things and making adjustments to do what I need, but probably not much more than that (although I'm more than willing to learn, if things are explained in a way a non-professional-programmer can understand). I'll appreciate any help you could give me (referring me to the correct place in which to get my answers would be super), but please keep in mind that my head's liable to explode if things get too technical.

Many thanks.

2
  • I like the idea of your script very much but to be honest I'm a bit surprised that you didn't find a way to read and write the content of a spreadsheet as this is really a very basic operation. I guess one could suggest a more accurate advice if you show (for example) the RSS filter part of your code and the way you imagine the presentation of your spreadsheet. As far as I'm concerned, I would have a page with |filters string|nr of occurrence| in successive rows and a second page with the web adress of the rss feed you are monitoring. Would that be sufficient or did you have other ideas ? Oct 8, 2013 at 21:41
  • @Sergeinsas that was how I planned to construct my spreadsheet as well. However, basic as it may be, I can't find how to do it. Let's cut down to the piece that matters: suppose a spreadsheet named RSS Filter is located in my Drive's root, and suppose it has two sheets, filters and sources. How can I declare an array and fill it with the contents of a given range in filters, say? Or better yet, declare the range on the go, to include only those cells which are used in the give sheet? Oct 8, 2013 at 21:57

1 Answer 1

1

here is an example with your criteria :

function getArrayFromSheet(sheetName) {
  var ss = SpreadsheetApp.openById('0AnqSFd3iikE3dF9hb3RUeHBqNUt2NGdkRlUycVZQN0E');// edit this id to suit your spreadsheet
  var sh = ss.getSheetByName(sheetName);
  var lastRow = sh.getLastRow();
  var lastCol = sh.getLastColumn();
  var data = sh.getRange(2,1,lastRow,lastCol).getValues();// starting from row nr 2 to skip headers if present (otherwhise start from 1)
  // data is an array of arrays [[row1],[row2],[row3],[...]] 0 indexed, each row inside the array is an array of the cell values
  return data
}

// usage :

function testFunction(){
  var firstRowOfData = getArrayFromSheet('filters')[0];
  Logger.log(firstRowOfData)
}

here is a testSpreadsheet to start with (make a copy to run the code)

1
  • SpreadsheetApp.openById() is precisely what I needed; thank you so very much. I've been all over that class, so I guess my only excuse is that its phrasing isn't very layman-friendly. Oct 8, 2013 at 22:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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