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.

Comments

26 responses to “Extract Custom Shapes from a Tableau Workbook”

  1. Daniel Avatar
    Daniel

    Nice to see you back in action on this website!

  2. online excel training Avatar

    Well written. Cool technical description behind the implementation. Thanks for sharing.

  3. Steve Avatar
    Steve

    This is a fabulous tool thanks. Rather enjoyed reading your code too, seeing how you did – elegantly done.

  4. Pooja Avatar
    Pooja

    I didn’t see an excel workbook when I downloaded the file.

  5. Robert Avatar

    Pooja,
    Excel files are zipped folders containing XML and other files. Unfortunately Internet Explorer renames .xlsm files to .zip files during download. Change the file extension from .zip back to .xlsm and you can open the workbook with Excel.

  6. Julian Avatar
    Julian

    A pity that the Shape Extractor only seems to work with Tableau Public workbooks, not those published to other websites. After being unable to launch it from either IE or Chrome by clicking (in one case nothing happened, in the other it persisted in downloading the shapes from the worked example), I copied the URL and changed the web location. I got this friendly message:
    [location] is not a Tableau Public url, fool!
    Well thank you Matt and Tableau, it’s nice to be insulted by a tool that doesn’t work. The cynic in me says that it fits perfectly with Tableau itself, which is far from a finished product.

  7. Robert Avatar

    Julian,
    I appreciate your comment, but unfortunately I can’t really reply to your feedback, because I did not develop the online Tableau Custom Shape Extractor. I only created the little Excel tool described above which extracts shapes from a Tableau workbook.
    I first thought of recommending to post your comment on the Tableau Public Blog:

    All Your Shape are Belong to Us

    but it seems as if the comments are deactivated there. Thus, I’d suggest you directly contact Tableau to provide your feedback.

  8. EB Avatar
    EB

    Hi – Any idea why the custom excel tool would only extract a snippet of custom shapes? I initially thought it was a size issue, but I tried a similar workbook and was able to extract all 200+ images fine.
    Link to workbook I am looking at extracting shapes from: https://public.tableau.com/profile/nelson.davis#!/vizhome/EndangeredSafariApril24/ENDANGEREDSAFARI

  9. Robert Avatar

    EB,
    I can reproduce the problem. It is not a size error, it is a character set issue.
    The extraction stops at the image of Rüppel’s Fox, the first shape with a “Umlaut” in the name. The GetNodeData function returns the string “Ru¨ppel’s-Fox-_-Vulpes-rueppellii” as the name of this shape and this causes the issue. The CreateTextFile method of the object can handle this, but apparently the VBA command Kill can’t. The code fails when trying to delete the text file and exits the sub. That’s why the other shapes are not extracted.
    The work-around is simple:
    In the Excel tool, go to the VBE and in the sub CreateandImportCustomShapes replace
    On Error GoTo ExitSub
    by
    On Error Resume Next
    If you run the algorithm again, all shapes will be extracted. Only downside: the text file for Rüppel’s Fox will not be deleted and you have to delete it manually before you copy the images to your Tableau repository.

  10. EB Avatar
    EB

    That does it – Bravo on that bug find & fix!

  11. Sarath Kunala Avatar
    Sarath Kunala

    This is excellent tool. Thanks

  12. Romain Avatar

    Thank you so much !

  13. Manoj Avatar
    Manoj

    This is simply amazing. Great work.

  14. Robert Avatar

    Alexander,
    you are right, you can simply copy an entire sheet and paste it into your own workbook.
    However, the copy-paste-action will not only transfer the custom shapes but everything else, like the data connections, the calculated fields, the sets, the parameters, etc. Whatever is relevant for the copied worksheet will be included in the copy-paste-action. If you only need the custom shapes from the other workbook, you have to get rid of all these components afterwards.
    I am sorry, but I disagree with you. I think my method described above (including the provided Excel tool) is much easier to get access to custom shapes in other workbooks than simply copying and pasting a worksheet.

  15. Craig Dewar Avatar

    I have been trying to refresh some dashboards for a client with a new colour scheme. I found out too late that some of the dashboards have hard wired icons that are already coloured (using the old crappy colours) and i was going to have to try to recreate the icons or roll back all my changes!
    Now with this tool – i can just edit the existing icons with new colour fill. Saved me a bunch of time
    Fantastic effort – thanks so much.
    Craig Dewar

  16. Alex Avatar
    Alex

    Brilliant tool. Thanks for sharing

  17. Juan Avatar
    Juan

    man, y’re a genious!

  18. Lucas Friesen Avatar
    Lucas Friesen

    Hi, I tried using this tool with a workbook that has many custom shapes. But it only seems to extract the first 20 and then stops. Any idea why this may be the case?

  19. Robert Avatar

    Lucas,
    it could be that one of your shapes has a German Umlaut (ä, ö, ü) or another special character in the name. If this is the case, please refer to my reply to EB on Tuesday, Januar 12, 2016 above. One simple change in one line of the code overcomes this issue.

  20. olya Avatar
    olya

    Hi Robert, thank you! I downloaded your Excel .xlsm tool, but when I open it, the link to browse for a file won’t open at all 🙁 It acts like a shape in Excel and it won’t open it for me in order to browse for a file. Appreciate your help

  21. Robert Avatar

    Olya,
    the tool is a VBA-based solution, and you need to enable macros. As long as macros aren’t activated, the code can’t run, and the tool will not work.

  22. Olya Avatar
    Olya

    Hi Robert, thank you. I did enable macros, but the tool still won’t open – it just stays as a shape that won’t let me browse for a file. Appreciate your help. I am on a mac, not PC, is this why possibly it is not working?

  23. Robert Avatar

    Olya,
    yes, being on a mac could be the problem. I don’t have a mac available, and I never tested it on a mac. The code isn’t using specific Windows functions, but it requires a reference to the Microsoft XML library. I am not sure if this is available on macs at all, but you could check in the VBE (Tools|References) if Microsoft XML is in the list and the control box is checked. Maybe this could solve the problem.

  24. Olya Avatar
    Olya

    Thank you very much, Robert! Yes, mac was the problem, as your solution works on a PC. Thanks again!!

Leave a Reply

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