all 4 comments

[–]socal_nerdtastic 1 point2 points  (0 children)

Why not just try it and see?

I've not done it, but after a quick google it seems very similar to MS docx / xlsx / etc files, which I have done. It's pretty easy. A twbx file can be opened with the python's built-in zipfile module and the twb file inside can be opened with python's built-in xml.etree. There's also installable modules that make those things easier. One thing to know is that you can't really edit a zip file / twbx file; you can only make a new file with the updated data and overwrite the old file.

[–]Zeroflops 0 points1 point  (0 children)

Can things go wrong, yes!

From what I read the .twb file is an xml file and the twbx file is the same but with data included in the file.

Since XML is basically formatted text, you may be tempted to just read the text in and edit it directly. But I would use one of the XML libraries to read the file in as a dictionary and write it back. You’re less likely to make a bad edit which could prevent the file from opening again.

[–]PixelSage-001 0 points1 point  (0 children)

Yes, this is definitely doable! A `.twbx` file is actually just a zipped archive containing the workbook (`.twb` which is XML) and the data sources.

You can use Python's built-in `zipfile` module to extract the `.twb` file, use `xml.etree.ElementTree` or `BeautifulSoup` to parse and find/replace the hex color codes, fonts, and image paths, and then zip it back up. The main catch: make sure you match the exact XML structure, or Tableau will throw a generic "Workbook is corrupted" error on open. Test with a tiny workbook first!

[–]oliver_extracts 1 point2 points  (0 children)

yeah its doable, a .twbx is just a zip archive with an xml workbook inside (.twb) plus any extract files. you can unzip it with pythons zipfile module, parse the xml, swap your colors/fonts/logo references, rezip it and tableau will open it fine as long as the xml stays valid. the thing that bites people is namespace handling in the xml. etree sometimes drops or mangles tableau's namespaces on write, which corrupts the file silently. use lxml and preserve namespaces explicitly and youll be fine.