Extract Custom Shapes from a Tableau Workbook

How to extract the Custom Shape Images embedded in a Tableau Workbook

Enigma Inside - Photographer: Anthony Catalano (flickr.com)In Tableau Software you can use the Shape Mark property to encode data in a view by different shapes. You can either use Tableau’s default shapes (circles, squares, crosses, etc.) or so called Custom Shapes. Each Tableau installation comes with a set of Custom Shape palettes like arrows, bars, currency and gender symbols and others. Have a look into the Shapes folder of your Tableau Repository to see what is already there.

On top of that, you can also add your own Custom Shape Palette to this collection. Simply create a new folder in the Shapes folder of your Tableau Repository and copy the image files you want to use as shapes (.png, .gif, .jpg, .bmp or.tiff, but no .emf) into this folder. If you then assign shapes in the Edit Shape dialogue in Tableau, this folder automatically appears in the Select Shape Palette drop down and your images can be used to encode the data.

Tableau stores the used Custom Shapes in the .twb file, to make sure the workbook is fully functional on every computer, i.e. also on installations which do not have the Custom Shapes in the Tableau Repository.

So much for the background. And so far, so good.

Now, imagine you have a Tableau workbook using Custom Shapes, but you do not have the image files in your Tableau Repository, because you are working with a new or different computer, you received the workbook from a colleague or downloaded it from Tableau Public.

What if you want to reuse the Custom Shapes in another workbook?

Is there an option to extract the Custom Shape image files from a Tableau workbook?

Not built-in, but there are two existing workarounds provided by Matt York in the Tableau Forum and on the Tableau Public Blog. Although Matt’s solutions are very smart and easy to use, I decided to add my 2 cents with a third workaround.

Today’s post includes the links to Matt York’s Tableau Shape Extractor workarounds and describes a third option of how to do the same with a Microsoft Excel workbook. As always, the article provides the Extract Custom Shape Excel tool for free download.

The Background

A Tableau workbook is in XML format. In order to embed images, Tableau encodes images to generate a text which can be stored in XML. Let’s have a look at an example:

Here is the cover of Bruce Springsteen’s Wrecking Ball (used as a Tableau Custom Shape in Bruce Springsteen Discography – An Infographic):

Wrecking Ball Cover

Encoded and stored in the Tableau workbook, this image looks like this:

Wrecking Ball Cover Base64 Encoded

Believe it or not, you can recreate the image above from this cryptic text.

Technically spoken, Tableau encodes the image using a Base64 encoding scheme. Base64 encodes binary data by converting it into text in a base 64 representation. This is commonly used to store complex data in XML format. Don’t worry, I will not go into the details here, mainly because I barely understand it myself. For those of you who are interested in more details, have a look at this Wikipedia article as a starting point: Base64.

Matt York’s Workarounds

Matt provided two workarounds to solve the challenge of decoding and extracting Custom Shapes from a Tableau workbook:

  1. On a Tableau forum thread in 2011, Matt describes a 9 step tutorial of how to extract shape files from a downloaded Tableau workbook
  2. In his blog article All Your Shapes Are Belong to Us on the Tableau Public Blog in April 2014, he provides a simple and elegant way to extract shape files from published Tableau Workbooks directly in a browser. All you have to do is to add a bookmark Matt provides. You can then download the Custom Shape files of any online published Tableau workbook by simply clicking on this bookmark.

Fantastic work, Matt. Many thanks for sharing.

Why another Workaround?

To be crystal clear: I appreciate and applaud Matt’s work.

So why this blog post?

Because in my humble opinion, both of Matt’s approaches have their limitations. The workaround 1 is a bit cumbersome with the file renaming and the copying / pasting of the Java code into the console, etc. The second workaround is very easy to use, but it works only for workbooks published on a website.

That’s why I thought automating some of the manual steps of Matt’s workaround 1 in a little tool would make things easier.

The Tool – The Custom Shape Extractor in Microsoft Excel

The tool provided with this article extracts Custom Shape Files from any Tableau workbook stored on your computer or a fileserver. The code could have been implemented in any programming language, but I used Microsoft Excel and VBA for it. 

Why?

Well, because Excel is the tool I know best and – more important – it enables most of my readers to directly use it. No need to install anything, no security concerns, no time consuming discussions with your IT-department, etc. Just download the workbook and you are good to go.

How to use the Tool

Download the Microsoft Excel workbook (download link see below). Open the workbook and enable macros. You will see this:

Extract Custom Shape Tool

Click on the command button at top right of the sheet (Select Tableau Workbook). In the following Open File dialogue browse to the Tableau workbook you want to extract the Custom Shapes from.

Please note that it has to be a .twb file. If you have only a packaged workbook (.twbx), you have to extract it first: right click on the file in your Explorer and click on Unpackage.

Here is an example of the worksheet after I extracted the Custom Shapes from the Tableau workbook provided in this article: Bruce Springsteen Discography – An Infographic:

Extract Tool: Bruce Springsteen Covers

The worksheet shows the path and the filename of the Custom Shapes and the images. At the top of the sheet you see the filename and path of the imported workbook and the date and time of the import.

Of course, the tool did not only import the images into the Excel worksheet (which is for informational purposes only), but also created a folder called “Bruce Springsteen Covers” with all the images:

Custom Shapes Image Folder

Please be advised that this folder is created inside the current folder (where the tool is), not in the Shape folder of your Tableau Repository. So, before you can use the images as Custom Shapes in Tableau, you have to copy this folder with the images to the Shapes folder of your Tableau Repository.

Just like Matt’s javascript workarounds, the Excel tool extracts all embedded Custom Shapes, i.e. also the Custom Shapes coming with each Tableau implementation. If we import the Premier League Historical Statistics workbook, for one, the worksheet looks like this:

Extract Tool: Premier League Custom Shapes 1

Where are the team logos? No worries, they are there. The Premier League workbook uses two different shape palettes: the Arrows and the team logos. Just scroll down and from row 38 on, you will find the logos:

Extract Tool: Premier League Custom Shapes 2

In this case, the tool created two folders: one with the arrows and one with the team logos.

Finally: if a folder with the name of the Custom Shape palette already exists, you will receive this warning message:

Warning Message

Please be careful. If you click OK, all files in this folder will be deleted, no undo possible.

The Weaknesses of the Tool

There is some room for improvement in this tool:

It does not handle packaged workbooks and it does not store the Custom Shapes in the Tableau Repository.

Eliminating these disadvantages would be possible in VBA, of course. However, this would require some extra coding, like identifying the correct path of the Tableau Repository, the language of the Tableau installation and some system calls to extract the packaged workbook and to delete the extracted files afterwards. Considerable extra coding just to eliminate the requirement of a few additional clicks. That’s why I decided to waive this and live with the disadvantages.

Having said that, the VBA code is without password protection, so if you want to add this code, you are invited to do so.

The Download

Here is the link to download the tool:

Download Extract Custom Shapes from Tableau (Microsoft Excel 2007 – 2013, 28.5K)

Stay tuned.

Add a Comment

Your email address will not be published. Required fields are marked *