Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
pgriffiths
Creator
Creator

Macro to export straight table to csv after reload on server.

I have been trying to do this for some time, but I can't seem to find an answer.
I need to export a straight table to a CSV file.
Below is a test setup I am using to simpify the process while investigating the problem.

I first create some test data in a load script as follows;

//Example Data
QUALIFY *;
Example_Data:
LOAD * Inline
[Asset,User,OS
UK01,sparnaby,WinVista
UK02,tbrown,Win7
UK03,mrichards,Win8
];

To test the output folder has access, I output this table using the Store command as follows;

STORE Example_Data into c:\TestCSV\Table_Example_Data.csv (txt);

I then create a straight table to output the example data and add a count field with a total. I call this stright table "Table_Data".

I create a Macro to output the straight table as follows;

Sub ExportTest
Set obj = ActiveDocument.GetSheetObject("Table_Data")
obj.ExportBiff "c:\TestCSV\Data.csv"
End Sub

In the Edit Module section this macro is in, I set the following fileds;
Requested Module Security: System Access
Current Local Security: Allow System Access

In the main Qlikview document I also go into Settings->Document Properties->[Triggers] tab.
I select "OnPostReload" and click [Add Action(s)] button.
I add "Run Macro" and set the Macro Name to "ExportTest".

I then setup security Settings on the Qlikview Management Server.
[System] tab->[Setup] subtab->Select Server from the list.
[Security] tab on the server.
[Tick] Allow macro execution on server
[Tick] Allow unsafe macro execution on server
Clicked [Apply]

I then setup the output folder c:\TestCSV and added full permissions for the AD accounts the qlikview services run on.

I open and run the report fine from the qlikview client and c:\TestCSV folder contains both the output files
Data.csv
Table_Example_Data.csv

The problems is if I create a task on the Qlikview Management Server, it only outputs the one file.
Table_Example_Data.csv

Anyone got any idea how to do this?.


Many thanks in advance.

EDIT - I have added the example QVW file.

12 Replies
gandalfgray
Specialist II
Specialist II

Store is a load script command and works with the tables you have in your QlikView application/load script, not with the charts/tables etc you have in the QlikView gui, so no it does not work with Straight Table objects.

But you can create a table in your load script which has the same data as your Straight Table object, and then Store it as a txt.

pgriffiths
Creator
Creator
Author

Thanks for confirmation. Thought for a moment I had missed something and gone down the wrong route.

cmccafferty
Contributor III
Contributor III

This is amazing... but I was wondering if there is a workaround if the export csv file is more than 65000 rows?

At the minute my output is putting the remaining rows onto a new tab Sheet2, ie it's like old school Excel with the limited number of rows available.

 

My very simple script is this:

 

sub Export_Trust

set trust1 = ActiveDocument.GetSheetObject("CH205")
set trust2 = ActiveDocument.GetSheetObject("CH210")
set trust3 = ActiveDocument.GetSheetObject("CH207")

trust1.ExportBiff "X:\Business Performance\Finance\Cash\Download\QVATC.csv"
trust2.ExportBiff "X:\Business Performance\Finance\Cash\Download\QVTrust1.csv"
trust3.ExportBiff "X:\Business Performance\Finance\Cash\Download\QVTrust2.csv"

end sub