GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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 #129

New issue
Copy link
New issue
Copy link
Closed
Closed
Retrieve All fields used in a workbook#129
Copy link

Description

@TCMurph
TCMurph
opened on Feb 7, 2017
Issue body actions

Hey,

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

Reacted by ismail simsek

Activity

  1. graysonarts commented on Feb 7, 2017

    @graysonarts
    graysonarts
    on Feb 7, 2017
    Contributor
    More actions

    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.

  2. TCMurph commented on Feb 7, 2017

    @TCMurph
    TCMurph
    on Feb 7, 2017
    Author
    More actions

    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.

  3. JoeLuker commented on Sep 19, 2019

    @JoeLuker
    JoeLuker
    on Sep 19, 2019
    More actions

    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
  4. jacalata
    closed this as completedon May 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402520 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.