GeezerVison is showing github.com — Retrieve All fields used in a workbook · Issue #129 · tableau/document-api-python
Retrieve All fields used in a workbook #129DescriptionHey,
Is it possible to retrieve back from a workbook, what the worksheets are, and within each worksheet what fields are being used and what datasource they come from?
Thanks.
Paul Activitygraysonarts commented on Feb 7, 2017 Hey Paul,
Yes it's possible, but a little convoluted currently. We don't have any sample code that shows how to do it, but the general process would be something like this (assuming a single datasource):
- Open the workbook
- For each datasource, access the fields property.
- Keep a mapping of worksheets that map to a set
- For each field in the datasource, access the worksheets property and loop over the worksheet names to access the set, and add the field to the set for that worksheet. You could add a tuple if you wanted to include which datasource it came from.
The worksheets property contains the names of each worksheet where the field is used.
It's convoluted, but workable. TCMurph commented on Feb 7, 2017 Thanks Russ. We'll try that. Was hoping that I was just missing how to do it with the current release version, but I'll pull the code and see if I can get it to work. JoeLuker commented on Sep 19, 2019 Here's my example of how I got it working. It's messy and not exactly what is described above, but I figured it might help someone:
from tableaudocumentapi import Workbook
sourceWB = Workbook('sample-superstore.twb')
worksheets = sourceWB.worksheets
for worksheet in worksheets:
for datasource in sourceWB.datasources:
for count, field in enumerate(datasource.fields.values()):
for fieldWorksheet in field.worksheets:
if worksheet == fieldWorksheet:
print(worksheet, "==", fieldWorksheet, "|", count, field.name, "-", field.caption)
Reacted by uniquegino and Naveen
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|