0

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?

Dirk Fauth
  • 4,128
  • 2
  • 13
  • 23
Michal Kotus
  • 157
  • 1
  • 10

1 Answers1

0

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.

Dirk Fauth
  • 4,128
  • 2
  • 13
  • 23
  • You are right. Java knows only line separator. Excel does use combination `Alt+Enter` to achieve new row inside cell. there is nothing similar in Java. – Michal Kotus Jan 12 '21 at 13:50
  • how to use custom serializer? I can override for example style in tables or register CopyDataCommandHandler, but not serializer. @Dirk Fauth – Michal Kotus Jan 13 '21 at 09:15