warpech / sheetclip

Copy/paste from your HTML5 web app to a spreadsheet
MIT License
304 stars 27 forks source link

force strings with tabs to be wrapped in quotes #2

Closed redchair123 closed 11 years ago

redchair123 commented 11 years ago

SheetClip.stringify does not wrap strings that contain tabs but no newlines.

To generate such a monstrosity, set

A1=1&CHAR(9)&2

On Excel 2011 it's displayed as if the tab is a single character, but copying and pasting (pbcopy/pbpaste) reveals that an actual tab character is there!

warpech commented 11 years ago

I don't see tab character in your post above but maybe GitHub stripped it... Would you be able to writes steps to reproduce this error on Handsontable.com?

redchair123 commented 11 years ago

Here's one way to show the issue -- admittedly, there is also an issue in parse but this patch focuses just on the stringify part (this is on OSX with excel 2011, but I suspect the same issue exists on linux with libreoffice and windows with excel 2010/2013).

ISSUE IN PARSE

1) copy the text "multi\ttab\ttest" to your clipboard:

$ echo -e "\"multi\ttab\ttest\"" | tee >(pbcopy)
"multi  tab test" <-- those are tabs

2) paste in excel cell A1. On excel 2011 it displays as if the tabstop is 1: http://imgur.com/cpgj8

3) On the grid at handsontable.com, just select (don't edit) and paste in B2: http://imgur.com/AKQ7C

It should dump in one cell but it now dumps in 3

ISSUE IN STRINGIFY

1) copy the text "multi\ttab\ttest" to your clipboard:

$ echo -e "\"multi\ttab\ttest\"" | tee >(pbcopy)
"multi  tab test" <-- those are tabs

2) On the grid at handsontable.com, edit cell A1 and paste: http://imgur.com/Lqyyb

3) Copy from the grid and paste in excel: http://imgur.com/zGNj5

It should dump in 1 cell but in fact dumps in 3

Fixes

The attached commit fixes the stringify half. If you find the approach reasonable I'll also submit a stringify patch.

warpech commented 11 years ago

Hi @Niggler, sorry that I didn't merge the PR so far. Now I see that you have deleted your fork but I am still able to see the changes that you've submitted. I agree this is a valid issue

warpech commented 11 years ago

Did you also have a fix for the "parse" half of the issue?

redchair123 commented 11 years ago

I've been investigating further and actually am not happy with the proposed solution. When I fully understand what's going on I'll submit another PR

warpech commented 11 years ago

Thanks! Me too. I've spent whole last day unvestivating Excel and various CSV/TSV libraries to see if they perform better than my code. In places they are better, but still far from good. I've written more about it in issue #3. I would appreciate your help!