Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Not applicable

Export objects to CSV using macros in Load script

Hi all,

As a part of automating some QA processes I want to export some objects (their data of course) from my UI to csv files while the loading script executes. is that possible?

Also, is it possible when doing the reload phase, to use the macros to generate several selections on some filters and then make the export above?

Thanks,

Boris

1 Solution

Accepted Solutions
MVP & Luminary
MVP & Luminary

Re: Export objects to CSV using macros in Load script

Try this macro

SUB ExportChartToCSV

Dim myCharts(2)

myCharts(0) = "Coat"

myCharts(1) = "Suit"

myCharts(2) = "Boxes"

For Each item In myCharts

     SET  objChart = ActiveDocument.GetSheetObject(item)

     objChart.Export "C:\" & item & ".CSV", ", "

Next

END SUB

Regards,

Jagan.

View solution in original post

10 Replies
bestofwest
Contributor II

Re: Export objects to CSV using macros in Load script

Verify STORE command on first point. Edit Script is synchronous process not asynchronous.

One Second point inside I don't understand what is the real question.

MVP & Luminary
MVP & Luminary

Re: Export objects to CSV using macros in Load script

No, it is not possible to access any UI objects during the load script.  The ActiveDocument object, which is required to access any sheet objects, does not exist during the load.

Rob

MVP & Luminary
MVP & Luminary

Re: Export objects to CSV using macros in Load script

Hi,

It is not possible to process the UI objects during script reload, what you can do is trigger the macros on post reload of the document.

You can trigger this by

Settings -> Document Properties -> Triggers -> Document Event Triggers -> On PostReload

Hope this helps you.

Regards,

Jagan.

Not applicable

Re: Export objects to CSV using macros in Load script

Thanks for the info.

Is it possible to export objects to csv and not xls?

MVP & Luminary
MVP & Luminary

Re: Export objects to CSV using macros in Load script

Hi,

Try this macro

SUB ExportChartToCSV

     SET  objChart = ActiveDocument.GetSheetObject("CH01")

     objChart.Export "C:\Data.CSV", ", "

END SUB


This saves the csv file in C drive.  Replace CH01 with your chart ID.


Regards,

Jagan.

Not applicable

Re: Export objects to CSV using macros in Load script

and do you think there is a way to create a loop to export all charts in the UI automatically?

a sub that will set the file name as the chart ID.

MVP & Luminary
MVP & Luminary

Re: Export objects to CSV using macros in Load script

Try this macro

SUB ExportChartToCSV

Dim myCharts(2)

myCharts(0) = "Coat"

myCharts(1) = "Suit"

myCharts(2) = "Boxes"

For Each item In myCharts

     SET  objChart = ActiveDocument.GetSheetObject(item)

     objChart.Export "C:\" & item & ".CSV", ", "

Next

END SUB

Regards,

Jagan.

View solution in original post

Not applicable

Re: Export objects to CSV using macros in Load script

That means I need first to put all of my chart names into this array?

Re: Export objects to CSV using macros in Load script

You can export a table to csv in the load script without a macro simply by using a store command with the (txt) qualifier.

     store tablename into filename.csv (txt) ;