Output Google Spreadsheet to XML/RSS/Atom using Google AppScript Content Service

1.6k Views Asked by At

So I've searched this site and found nothing really useful so far to accomplish this.

I am wanting to turn a spreadsheet into an RSS feed using google script content service. How do I declare column values (i.e. pubDate, Author, Content) so it will output correct RSS/Atom feed. Following their online examples so far just outputs cluttered garbage. And there isn't much documentation to it, their example is about how to take an already existing RSS and make changes then re-output it. From what I've read on here and other sites, content service is what I should use to accomplish this. The sheet will update every couple days and I'm trying to create an RSS for it.

function doGet() {
  var feed =  UrlFetchApp.fetch('https://docs.google.com/spreadsheets/d/1lPOwiYGBK0kSJXXU9kaQjG7WNHjnNuxy25WCUudE5sk/edit#gid=0').getContentText();
  return ContentService.createTextOutput(feed)
    .setMimeType(ContentService.MimeType.RSS);
}

I also have tried using:

function doGet() {
 var ss = SpreadsheetApp.openByUrl(
     'https://docs.google.com/spreadsheets/d/1lPOwiYGBK0kSJXXU9kaQjG7WNHjnNuxy25WCUudE5sk/edit');
 SpreadsheetApp.setActiveSpreadsheet(ss);
 SpreadsheetApp.setActiveSheet(ss.getSheets()[0]);
 var title = ss.getSheets()[0].getRange("A1:A");
 var link = ss.getSheets()[0].getRange("B1:B");
 var pubDate = ss.getSheets()[0].getRange("C1:C");
 var content = ss.getSheets()[0].getRange("D1:D");
 var author = ss.getSheets()[0].getRange("E1:E");
  return ContentService.createTextOutput(title)
//    .setMimeType(ContentService.MimeType.RSS);
}

but it doesn't print the titles, it only prints the word Range.

Thank you for you help.

1

There are 1 best solutions below

0
On BEST ANSWER

getRange() function only assigns a range. You need to use getValues().

try changing title to this.

var title = ss.getSheets()[0].getRange("A1:A").getValues();