Qlik Community

QlikView App Development

Discussion Board for collaboration related to QlikView App Development.

Partner
Partner

Export to CSV with quotation marks

Hi Guys,

i need to Export a Tabel to a CSV File. I made a VB Script

set sObject = ActiveDocument.GetSheetObject("TB02")

sObject.Export "C:\users\\TestFile.csv", ","

Well this works fine but i need quotation marks around the values.

I found a lot of threads about the delimiter, but are there any parameter to add quotes to the value?

KR

Johann

1 Solution

Accepted Solutions
MVP & Luminary
MVP & Luminary

Re: Export to CSV with quotation marks

There are several possibilities which you could try - storing these data per store-statement within the script, switching to a different export-call like ExportEX or maybe if it's a rather simple table you could add the quotes to each value like: '"' & sum(value) & '"' - whereby I believe you will rather need another workaround and write your data into a file. Here are an example how to loop through a table and how to write values into a text-file and here you could manipulate the output like you need:

Re: Export to Excel macro (no field grouping)

Re: Scan of scripts in .qvw files

- Marcus

6 Replies
MVP & Luminary
MVP & Luminary

Re: Export to CSV with quotation marks

There are several possibilities which you could try - storing these data per store-statement within the script, switching to a different export-call like ExportEX or maybe if it's a rather simple table you could add the quotes to each value like: '"' & sum(value) & '"' - whereby I believe you will rather need another workaround and write your data into a file. Here are an example how to loop through a table and how to write values into a text-file and here you could manipulate the output like you need:

Re: Export to Excel macro (no field grouping)

Re: Scan of scripts in .qvw files

- Marcus

Partner
Partner

Re: Export to CSV with quotation marks

Hi Marcus,

I tried to use your Method with '"' & sum(value) & '"' and in qlikview it looks good.

qwv.png

But if i export it via a Makro, i get everytime 3 Quotes .

"""roboter""",timeIntervalListAnfang,typebits,aktuellerTag,targetFolder,pathRawData,pathRDSData,intervallTyp

"""KA2M41_03R03""","""03.02.2014""","""PLC_do_Typbit_03""","""10.08.2016""","""\\...ta\TargetFolder""","""\\.....ta\RawData""","""\\...SData""","""beliebig"""

I also tried it with a chr(34) but it didnt worked either.

I use following vba Script to create the csv.

sObject.Export "C:\users...p\TestFile.csv",","

Any other ides how to get only 1 Quote?

MVP & Luminary
MVP & Luminary

Re: Export to CSV with quotation marks

I have feared that this happened than it's the same behaviour like by storing values with enclosing quotes within txt-files. I remember on a solution which used double/triple/quadruple quotes to get rid of the automatically logic of adding quotes to quotes.

Another way is like above mentioned to write these data directly like in this example:

sub CSVEportWithQuotes

set table = ActiveDocument.GetSheetObject( "TB14" )

for RowIter = 0 to table.GetRowCount-1

    for ColIter =0 to table.GetColumnCount-1

        set cell = table.GetCell(RowIter,ColIter)

        if ColIter < table.GetColumnCount-1 then vDelimiter = "," else: vDelimiter = ""

        vContent = vContent & """" & cell.Text & """" & vDelimiter

    next

    vContent = vContent & chr(10)

next

msgbox vContent

set fso = CreateObject("Scripting.FileSystemObject")

set File = fso.OpenTextFile("\\YourServer\d\Test.csv", 2, true)

File.Writeline vContent

File.Close

end sub

- Marcus

Partner
Partner

Re: Export to CSV with quotation marks

Hi Marcus,

thank you for that vba Script.

It works perfectly, just does what i need.

Kind Regards

Johann

Partner
Partner

Re: Export to CSV with quotation marks

Hi Marcus,

We have a similier situation like Johann.

I have 2 questions over here

1. The above macro will run on server side or on client side?

2. Is the above macro independent of OS. Meaning will it run on MAC?

Thanks in advance.

Regards,

Hiren Jadiya

MVP & Luminary
MVP & Luminary

Re: Export to CSV with quotation marks

I never tried it on the server side else only with the desktop client on the server or the local machine or with the IE plugin. Regarding to the MAC I don't know if MAC supports VBS - AFAIK VBA is supported by using MS Office for MAC but if it includes all necessary libraries for VBS ... ?

- Marcus