Nick BalestraNick Balestra Personal Blog

Comments

Using Google Docs Spreadsheet to enjoy my weekend ;-)

Doing my work at beyounic I always strive for ways to make things work easier, saving time and avoiding stupid repetitive tasks. So when I heard that i had to track daily stuff on the web I just went mad. Before even starting to take this new tasks on my shoulder i was already up with a plan, a challenging one: how can I spend few hours on this and just forget about it?

My initial idea was to build a script using Xpath and after playing around and googleing for few references on the xpath syntax i just found out that google docs spreadsheet can take advantage of xpath query by using =importXml - awesome!

If you then think that google apps also offers google apps script to build quickly scripts for it, i just was set. (you can check this out here: http://code.google.com/googleapps/appsscript/guide.html)

So I did some work to import on the fly some google analytics on a spreadsheet mixed together with some other data through the use of xpath & ImportXml - refreshing and storing them on a separate sheet for reference. For the GA integration i based my work on this nice script: https://docs.google.com/View?id=dg6mf6rd_33fz36k3gj

Now i’ll just have to wait few days (or a notification from google app script that my script isn’t working…) to see if everything work as it should, if it does as i hope, I will never have to start doing that stupid daily tracking job;-). It’s so rewarding when you solve a problem even before having to face it ;-)

not sure if any of you is interested but here is my code for the script:

function dailystupidjob() {

var activess = SpreadsheetApp.getActiveSpreadsheet();

var target = SpreadsheetApp.openById(“ttrV45cR54EPqJPr3pggfyBA”);

//this id is not from mine ss;-)

var source_sheet = ss.getSheetByName(“Once a day”);

var target_sheet = target.getSheetByName(“Every Days”);

var source_range = source_sheet.getRange(“A1:J1”);

var last_row = target_sheet.getLastRow();

target_sheet.insertRowAfter(last_row);

var target_range = target_sheet.getRange(“A”+(last_row+1)+”:J”+(last_row+1));  

source_range.copyTo(target_range, {contentsOnly:true});

//by doing {contentsOnly:true} I avoid to have all the rows that i generate on the “Every Days” sheet the same as they contain formulas and not just values ;-)

}

because i do some daily tracking i just run this script and the others i did with a time trigger…!

A big thanks for the hints on the script goes to Keith Twombley 

  1. nickbalestra posted this
blog comments powered by Disqus