nattablenebula

NatTable - copy & paste cell data with line separator inside cell


My copy & paste works well for Nattables. Problem comes, if some cell contains line separator. When I paste data, line separator is taken as a row separator and structure of my table is destructed.

In CopyDataToClipboardCommand.class:

public CopyDataToClipboardCommand(String cellDelimeter,
        String rowDelimeter, IConfigRegistry configRegistry) {
    this.cellDelimeter = cellDelimeter;
    this.rowDelimeter = rowDelimeter;
    this.configRegistry = configRegistry;
}

cellDelimeter is set to \t and rowDelimeter is set to \r\n.

Inside problematic cells is new line set with \n. Any idea about this?


Solution

  • If you talk about pasting to Excel for example, then the issue is not in NatTable, it is in Excel. Excel treats a new line character as a row delimiter. The configuration in CopyDataToClipboardCommand is used to add that character for ADDING a new row.

    If you want to be able to copy cell content that contains new line characters and paste it in Excel, you probably need to override CopyDataCommandHandler#internalDoCommand() and use a custom serializer that replaces the new line characters in the cell to something Excel can handle. Actually I don't know what character is treated as a line separater inside a cell in Excel. I probably would replace it with a simple space then.