ce icon indicating copy to clipboard operation
ce copied to clipboard

Excel and quotation mark handling

Open tdamsma opened this issue 3 years ago • 2 comments

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: image

Copying it to a text file results in this (see image for whitespace characters): image

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: image Copying it back to text results in
image

"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

tdamsma avatar Sep 08 '20 20:09 tdamsma

For my particular use case, I think I can manage with a unicode inch character

onbeforepaste: (el, data) => data.replace(/"{1,3}/g, '″'),

tdamsma avatar Sep 08 '20 20:09 tdamsma

Thanks for the suggestion. It would be definitely considered in future releases.

pphod avatar Sep 09 '20 22:09 pphod