Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

CSV file export Issue, help needed

I am exporting a straight table as a .csv file.  The requirement is to have each field wrapped in double quotes so I concatenated them to the field itself, i.e.,

'"' & Material & '"' as PARTNUMBER,

and I even tried,

CHR(34) & Material_MATNR & CHR(34) as PARTNUMBER

however, when I view the .csv file after export in Notepad or WordPad, I see 3 sets on each end of the field value, i.e.,

"""Y6015"""

Any thoughts on how I can get each field value wrapped in a set of quotes like this " Field Value " ?

Also, I am using QV v10 but will be moving this to v11 next week.

Thanks,

Sean

1 Reply
Not applicable
Author

Hi Sean,

i think that the triple double quotes are must for the csv file if the field contain double qutes. It's kinda of escape character.

If is possible to use macro in your file you can write the following sub that will open the exported csv file, replace the tripe dobule quotes with single double quotes and save it with new name

sub replaceQuotes

          exportedFile = "C:\Users\Admin\Desktop\exported.csv"

          resultFile = "C:\Users\Admin\Desktop\result.csv"

          set fso = CreateObject("Scripting.FileSystemObject")

          if (fso.FileExists(resultFile) = False) Then

                    fso.CreateTextFile resultFile

          end if

          set file = fso.OpenTextFile(exportedFile)

          set outFile = fso.OpenTextFile(resultFile, 2, true)

          do while not file.atEndOfStream

                    text = file.ReadLine

                    outFile.WriteLine Replace(text,chr(34)&chr(34)&chr(34), chr(34))

          loop

end sub

Just set the exportedFile and resultFile variables.

Be aware that this read the csv file line by line so if you have many records then the whole process might be slow.

Regards!

Stefan