Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
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
jagan
Luminary Alumni
Luminary Alumni

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
Anonymous
Not applicable
Author

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.

rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

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

jagan
Luminary Alumni
Luminary Alumni

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
Author

Thanks for the info.

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

jagan
Luminary Alumni
Luminary Alumni

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
Author

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.

jagan
Luminary Alumni
Luminary Alumni

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.

Not applicable
Author

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

Colin-Albert

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) ;