8000 initial work on filter-and-replicate sample · onware/document-api-python@9ae5583 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9ae5583

Browse files
committed
initial work on filter-and-replicate sample
1 parent 88361b5 commit 9ae5583

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed
249 KB
Binary file not shown.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Workbook,Format,Project,Branch
2+
Job Time,twbx,Operations - Edmonton,Edmonton
3+
Job Time,twbx,Operations - Abbotsford-Cor,Abbotsford-Cor
4+
Job Time,twbx,Operations - Abbotsford-Ref,Abbotsford-Ref
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import csv # so we can work with our database list (in a CSV file)
2+
3+
############################################################
4+
# Step 1) Use Workbook object from the Document API
5+
############################################################
6+
from tableaudocumentapi import Workbook
7+
8+
############################################################
9+
# Step 3) Use a database list (in CSV), loop thru and
10+
# create new .twb's with their settings
11+
############################################################
12+
with open('databases.csv') as csvfile:
13+
databases = csv.DictReader(csvfile, delimiter=',', quotechar='"')
14+
for row in databases:
15+
16+
# Open the workbook
17+
sourceWB = Workbook(row['Filename'] + row['Format'])
18+
19+
# Update the filters
20+
for datasource in sourceWB.datasources:
21+
for filter in datasource:
22+
if filter.column == '[Branch]'
23+
filter.groupfilter.member = '"' + row['Branch'] + '"'
24+
25+
# Save our newly created workbook with the new file name
26+
sourceWB.save_as(row['Filename'] + ' - ' + row['Branch'] + row['Format'])

0 commit comments

Comments
 (0)
0