Google Visualization – HTML Table Layouts

In order to get a decent layout for charts and dashboards I found it helps to use html tables to create the base layout. Below are two, one with controls across the top, and the second with controls down the side. The tables are reasonably responsive to screen/window sizing….

Top Layout

html

Example Top Filter Table

Side Layout

html

Example Side Filter Table

For these to work with your visualizations, simply insert divs with ids to each of the cells where you need them

Google Visualization – Dependent Controls / Filters

When building a chart with controls (using a dashboard), you very often want to filter, then filter again. Lets say we have a people directory, with names, locations, and countries. You create a CategoryFilter for each of these. But it would make sense to filter by country, then be left with only those in that country, before filtering by location. This is how you do it.

Set up your filters:

Set up the table

Now we need to do the binding of the controls and the table:

You can see that we bind the country to the location, then the location to the people, then the people to the table. In this way, the filters become dependent on each other. In the simple demo below, you should see how – when a country is selected only the locations for that country show in the Location drop down.

Here is a full demo of this in operation:

Demo Open in Browser

Google Visualization – Pick and Choose…

It seems much easier to use the query method to pull in data for visualizations, can be run straight from any old html page (can also be run from a google apps script web app), number formats remain intact (e.g. dates), and using the query language allows to select just the data you need. However, at present, there is one flaw, even for G-Suite users, this method requires that the underlying spreadsheet is shared as “Anyone with the Link”. Now I know it would take 4 x the life of the Earth to crack a google Sheet ID, but in these days of data protection (GDPR) in the workplace one cannot accept this reduced level of security. Fortunately, there is another way, ones spreadsheet can remain private, and data can be visualized and presented in a secure way. This uses a standalone Google Apps Script web app (can be bound), and can be restricted to a G-Suite domain. Downsides are the extra work required to manage dates (these all come through as numbers, which need turning back into dates!), and it has to be done in a web app.
Continue reading

Google Visualization – CategoryFilter with csvFilter

As mentioned in a previous post, I have been working on generating a replica of the csvFilter option as found in a well known online visualizer for google sheets. In this post I demonstrated how to create a unique list of items that could be used in the control, and now can show the working example.
Continue reading

GAS – getLastRow() when sheet has Array Formula

The benefits of using array formulas in your spreadsheets are manifold, but when you come to grabbing the data held on those sheets for scripting you are presented with an issue: using the getDataRange().getValues function provided in GAS will return the entire sheet, in terms of rows, and therefore a whole load of unnecessary rows shown in your google visualization table or arrays. Continue reading

GAS – Create a Unique list from Cell based csv type Values – two ways

In my endeavours to move away from what might be a costly exercise in providing tables and charts for my users at work, I am delving heavily into google visualisations as a replacement. One feature I have yet to replicate is the “csvFilter”, whereby a column of cells in a table contains more than one value, separated by commas:

csvlist Continue reading

GAS Folders, Sub Folders and their Files

Google Drive is a wonderful thing, but when it comes to getting at a file with scripts things can get a little quirky. Every file and folder has a unique ID number (28 digits, letters and other marks) which can make it easy to locate it, if you know how. However you can of course have many files, or folders with the same name spread out across your Google Drive, which can create a bit of a problem when trying to find the file or folder. Very often you may have to iterate over “all the folders” in order to find what you want, using names to do this can be problematic.

I find I am routinely needing to grab a list of filenames, file IDs, or file types, and routinely searching the web each time I need to do this, therefore it was about time I tied down the required scripts in one place for reuse. The scripts I have put together will request either a folder name or ID in order to iterate over the files within that folder and return the results to a spreadsheet. The scripts can be used as a base, and edited to suit specific requirements by adding further properties to return, or through the use of if statements to narrow down selected files.

  • You can find the ID of the folder by looking in the url address bar if you have the folder open in Google Drive
  • You can also right click on the folder and then Shareable Link
  • Finding the name should be obvious! – use search in Google Drive to check for folders with the same name. It may be wise to do this occasionally if you use name a lot in your scripts, and to make your folder names unique

In my scripts I have chosen to return the filename, the mime type, the file ID, and to create a download link. I also include a helper script (courtesy of Sandy Good) that presents the mimetype in a more user friendly way. All four folder scripts rely on this. Thanks should also go to Brian P and AD:AM on the google group support forum for their code.

I will add a link to a google sheet which contains all the scripts, just make a copy of it to your own google drive, authorise the scripts and away you go.

Continue reading

GAS Import CSV from GMail Attachment

I have a weekly email sent to me with a csv attachment. This needs to be opened and the contents pasted into a google sheet, the data therein is then used for a variety of other applications running on Google sheets. Fortunately there is a way to automate this and to parse the csv to sheets. I have robbed and amended the code provided by Digital Inspiration to do this. The linked page also includes other examples of scraping csv data from an email attachment. The key to getting this to work is a consistent approach by my email sender, who needs to use the same email address and subject in order that the GMail filter I set up can assign a label to the email. The script is run from the receiving google sheet on a timed trigger, once a week.

The sheet needed sorting to meet requirements of others. Above code kept nice and short thanks to the parsing API provided by Google. Of course, this will work for a single user google account, calling on the gmail of that user. Because I have G Suite it is simple to create a separate account to handle this type of thing.

 

GAS – Three Crackers: 1. Insert image at specific place in a table, 2. Remove extra paragraphs created by 1, 3. Proportionally size your image

The code, used on a google sheet to add an image to a specific location in a google doc table, should be self explanatory! I use this when an image is needed in a spreadsheet data to google doc to pdf creation exercise (hmmm – had better post that up too 😉 Continue reading