Saturday, March 1, 2014

Displaying quotation marks in CSV opened by Excel

I love CSV. Easy to serialize, easy to read, great choice for some basic reports. Good news is, it can be opened by MS Excel, so office folks can use it. Bad news is that Excel (at least 2007 one, which’s still widely used) parses CSV in a weird way.
So, how wrapping quotation marks are handled:

1. Single quotation marks around value have no effect –
"test"
is displayed as
test
.
2. Double quotation marks add some ‘cool’ quotation marks in the end of the string – so
""test""
becomes
test""
.
3. Tripple quotation marks actually give those bloody single quotation marks around value –
"""test"""
becomes
"test"

Note, that this applies only to quot. marks that ‘wrap’ the value, i.e. are at the start and the end of value. Quot. marks in the middle of value are displayed ‘as-is’, e.g.
test "that" string
is displayed as
test "that" string
(identical).
I’m not that sure I want to know of reasons why it’s made so.

No comments:

Post a Comment