Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to export the following string

"sep = ,"

to a CSV-file, as to be able to define the separation symbol.

However, when using the following command:

Export["test.csv", Join[{"sep = ,"}, RandomInteger[{-5, 5}, {5, 3}]], "CSV"]

I get the quotes around the string in the first line:

"sep = ,"

This obviously isn't recognized by Excel and it doesn't open correctly. I've tried changing the string to something like

Style["sep=,", ShowStringCharacters -> False]

and then export again, but then I just get this whole command into the CSV-file.

Is there a method to export this string without the quotes attached to them into a CSV-file?

share|improve this question
AFAIK, strings can only be exported without the quotation marks if done via streams, as in stream=OpenWrite[file];WriteString[stream, "string..."];Close@stream or if OpenWrite is called with the option FormatType -> OutputForm, but that might cause unwanted formatting on other characters. – István Zachar Jan 24 '14 at 18:19
Of curiosity is there some software that actually needs that header? Undoubtedly it will break many things (eg Mathematica will just include it as a data line if you import..) – george2079 Jan 24 '14 at 18:52
Actually, this is standard behavior for Excel exports to CSV too. If a string contains a field separator (a comma in this case) it needs to be quoted otherwise it will be seen (incorrectly) as a field separator upon import. Excel will automatically quote the string – Sjoerd C. de Vries Apr 27 '14 at 19:54
up vote 7 down vote accepted
 Export["test.csv", Join[{"sep = ,"}, 
        RandomInteger[{-5, 5}, {5, 3}]], "TextDelimiters"->None]

(With the obvious issue if you also have strings that should be quoted in the data )

share|improve this answer

If I try to create a CSV file without the first line indicating the seperator, the resulting file is readable by Excel.


But if you still want the first line, I would do something like this

 "sep = ,\n" <> ExportString[RandomInteger[{-5, 5}, {5, 3}], "CSV"]
 , "Text"]
share|improve this answer
Sadly, with my language settings, Excel wants ";" as delimiters. I've tried to change that, but that wasn't successful. Thanks for the good help! – Gabriel Jan 24 '14 at 18:41
Ahh, okay. Another solution would be to export it as a "Table" but usint the FieldSparators option. Like Export["test.csv",RandomInteger[{-5,5},{5,3}],"Table","FieldSeparators"->" ; "] – JasonB Jan 24 '14 at 18:58
Another approach might be to export comma separated, but with a "txt" extension. I think then Excel will pop up a box and let you tell it what the delimiter is. – george2079 Jan 24 '14 at 20:13

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.