循环浏览Qlikview中的所有可能字段选择并导出图表

时间:2014-10-22 04:23:40

标签: excel vba qlikview

在Qlikview中,我有多个过滤器。例如,假设3个过滤器,每个过滤器有3个可能的选择。这将给我总共27种可能的选择。

我想编写一个循环遍历所有这27个选项的宏,并将报告中存在的所有这些组合的图表导出到27个不同表格中的Excel工作簿。

1 个答案:

答案 0 :(得分:0)

您可以在QlikView中使用VBScript来实现此目的,但是,QlikView没有自动将图表图像导出到Excel的API。但是,Stefan Walther编写了一套优秀的VBScript方法,以帮助将图表以图像和数据格式导出到Excel。

您可以在此处找到他的文章和代码:http://www.qlikblog.at/971/qliktip-32-exporting-multiple-objects-single-excel-document/

虽然上述内容包括将固定图表导出到Excel,但您也希望进行选择,因此我在下面为您提供了一些可以与Stefan的导出代码结合使用的内容:

Sub ExportCharts()

set field1Values = ActiveDocument.Fields("<your first field here>").GetPossibleValues
set field2Values = ActiveDocument.Fields("<your second field here>").GetPossibleValues
set field3Values = ActiveDocument.Fields("<your third field here>").GetPossibleValues

chartList = ActiveDocument.ActiveSheet.GetGraphs

for i = 0 to field1Values.Count - 1
    for j = 0 to field2Values.Count - 1
        for k = 0 to field3Values.Count - 1
            ActiveDocument.ClearAll()
            ActiveDocument.Fields("<your first field here>").Select field1Values.Item(i).Text
            ActiveDocument.Fields("<your second field here>").Select field1Values.Item(j).Text
            ActiveDocument.Fields("<your third field here>").Select field1Values.Item(k).Text

            ' ... export operations here...

        next
    next
next

end Sub