If you use some of my libraries, you may have come across  the Fiddler class, which abstracts sheet data and provides a more functional way to manage data from multiple sheets in a Google Spreadsheet. It’s dependency free (because it can run both server and client side) – so that means you need to pass a sheet class to it.

I got bored of writing the same small functions over and over to handle opening and creating sheets for use with fiddler, so this is just a library that has a dependency on Sheet access – so you can use this instead of fiddler – it uses the fiddler library behind the scenes. It’s just a wrapper so it’s nothing fancy.

Getting started with fiddler

There are plenty of tutorials on Fiddler generally, and also a video introduction, so I’ll assume you’re already using it or will get up to speed with the fundamentals

What’s in the library

Not much at all.

/**
 * some usefule fromts for fiddler
 * this  needs spreadsheet scopes,whereas fiddler is dependency free
 */
function PreFiddler () {
  

    const getss = ({id}) =>  {
      return  id ? SpreadsheetApp.openById(id) : SpreadsheetApp.getActiveSpreadsheet()
    }
        
    // open a sheet
    const getSheet = ({ id, sheetName, createIfMissing=false}) => {
      const ss = getss ({id})
      let sheet = ss.getSheetByName(sheetName)
      if (!sheet && createIfMissing) {
        sheet = ss.insertSheet(sheetName)
      }
      return sheet
    }
  
    // open a fiddler and assign a sheet
    const getFiddler = ({ id, sheetName, createIfMissing }) => {
      return new bmFiddler.Fiddler(getSheet({id, sheetName, createIfMissing}))
    }
    
    return {
      getFiddler,
      getSheet,
      getss
    }

}
bmPreFiddler

Using

Fiddler just needs a sheet object – it’ll take care of reading and objectifying it. So PreFiddler just makes it easier to get one.

 const getFiddler = () => {
   return bmPreFiddler.PreFiddler().getFiddler({ 
	   id: '1h9IGIShgVBVUrUjjawk5MaCEQte_7t32XeEP1Z5jXKQ', 
	   sheetName: 'airport list',
	   createIfMissing: false
   })
 }
Getting a fiddler
Getting another fiddler from the same spreadsheet
Once you’ve got one, you can easily get (or create if missing), another fiddler from another sheet like this.
 const otherFiddler = bmPreFiddler.PreFiddler().getFiddler({
	id:fiddler.getSheet().getParent().getId(),
	sheetName: 'another sheet',
 	createIfMissing: true
 })
anotherSheet
And that’s pretty much it – once you’ve got the fiddler then all the useful stuff you can do with it is available.

Where to get PreFiddler

  • clone the script
  • from github
  • from library bmPreFiddler at 13JUFGY18RHfjjuKmIRRfvmGlCYrEkEtN6uUm-iLUcxOUFRJD-WBX-tkR
  • by including the code earlier, and adding the bmFiddler reference

Where to get fiddler

If you’re using PreFiddler, you don’t need to specifically include fiddler but if you need it, it’s here:
Here’s the key for bmFiddler, and it’s also on Github

13EWG4-lPrEf34itxQhAQ7b9JEbmCBfO8uE4Mhr99CHi3Pw65oxXtq-rU