Reputation: 51
I have a Standalone application in which I am trying to copy contents of JTable
into Excel with line breaks included in my cells of JTable
. I have used wrapping using "\""
to my cell contents. It's working fine but I am getting a square box type of symbol in place of line breaks in Excel. How to remove the symbol while copying? Is there any way to do this?
Upvotes: 2
Views: 1382
Reputation: 328614
Excel expects DOS/Windows line breaks ("\r\n"
) instead of Unix/Java ones (just "\n"
). To fix this, use this code:
s = s.replace("\r\n", "\n").replace("\n", "\r\n");
The first part makes sure that you don't have any DOS/Win line breaks and then converts everything to DOS.
If you're stuck with Java 1.4, use replaceAll()
.
[EDIT] The square box means that there is an unprintable character in the string. I suggest to create a file with Excel which contains a line break in a cell and check which characters Excel uses.
Upvotes: 1