在 TSC 中应用过滤器后将表格视图导出为 pdf [英] export tableau view to pdf after applying filter in TSC
问题描述
我正在尝试使用 python tableau 服务器客户端导出一个 tableau 视图.
以下是用于创建pdf的部分代码.
I am trying to export a tableau view using python tableau server client.
Following is the part of code which is used for creating pdf.
server.views.populate_pdf(view, options)
with file("dashboard.pdf", 'wb') as f:
f.write(view.pdf)
此代码运行良好,正在将视图导出为 pdf 文件.
我的 tableau 仪表板几乎没有过滤器(例如 product_type、vendor).
如何在导出时添加视图过滤器,以便仅获取特定 product_type 和供应商的数据?
This code is working fine and it is exporting a view to pdf file.
My tableau dashboard has few filters(e.g. product_type, vendor).
How can I add a view filter while exporting so that I will only get data for specific product_type and vendor?
推荐答案
我想我使用以下示例找到了答案.
https://github.com/tableau/server-客户端python/blob/master/samples/export.py
我们需要添加视图过滤器(vf)如下:
I think I found the answer using following example.
https://github.com/tableau/server-client-python/blob/master/samples/export.py
We need to add view filters(vf) as follow:
option_factory = getattr(TSC, "PDFRequestOptions")
options = option_factory().vf("product_type","Handphone")
options.vf("vendor","vendor1")
#In case of multi select filter we can use coma separated values as followed
options.vf("vendor","vendor1,vendor2")
#To get the list of all filter options use
print options.view_filters
一旦我们准备好过滤器选项,我们就可以将其传递给 pdf.
Once we have filter options ready we can pass it to populate pdf.
server.views.populate_pdf(view, options)
with file("dashboard.pdf", 'wb') as f:
f.write(view.pdf)
这篇关于在 TSC 中应用过滤器后将表格视图导出为 pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!