When I paste data from MS Excel into a grid, some of the cells do not paste as expected; adding an additional blank line within a cell, or not pasting at all for ‘coro’ type.
This appears to be due to the CR/LF (\r\n) that is used to denote the end of a row in the Excel clipboard data. dhtmlxGrid serialization appear to use only LF (\n) to denote the end of a row, and nothing at the end of the last row.
To solve this I have added some code to the pasteBlockFromClipboard method immediately before csvParser.unblock is called.
var pattern = new RegExp("(\r\n)$","g");
var pattern2 = new RegExp("(\r\n)","g");
serialized = serialized.replace(pattern,"");
serialized = serialized.replace(pattern2,this.csv.row);
The code removes the final ‘\r\n’ and replaces any ‘\r\n’ at the end of rows with ‘this.csv.row’ which is ‘\n’ by default. (I am also using setCSVDelimiter("\t") to deal with the tabs used in Excel data.)
This seems to work, although not especially elegant, and may not work in all situations.
Does anyone have a better solution?