ce
ce copied to clipboard
Excel and quotation mark handling
This is kind of a follow up on #176
When pasting data from excel with quotation marks, this isn't handled properly by jExcel. After some testing, I found that excel has surprisingly complicated quote handling icw copy/paste.
Consider this excel table:
Copying it to a text file results in this (see image for whitespace characters):
copy pastable:
"single quote 1
ends with quote" 2
"surrounded by quotes" 3
no quote 4
"has a tab" 5
"a "" and a tab" 6
"""starts with quote, and has a tab" 7
If a cell has a tab, then it gets surrounding quotes. If there is also a quote in the cell, then that is escaped by doubling it. So how can excel know the difference between a cell that has quotes in the content or that is surrounded by quotes? Well, apparently it doesn't. When the text is copied back to excel, the surrounded by quotes cell loses the quotes. Also the first two cells are merged:
Copying it back to text results in
"single quote 1
ends with quote" 2
surrounded by quotes 3
no quote 4
"has a tab" 5
"a "" and a tab" 6
"""starts with quote, and has a tab" 7
All this is to say that there is probably no way to do it completely right, but as jExcel just interprets all quotes as cell delimiters (as far as I can tell) it can surely be improved
For my particular use case, I think I can manage with a unicode inch character
onbeforepaste: (el, data) => data.replace(/"{1,3}/g, '″'),
Thanks for the suggestion. It would be definitely considered in future releases.